MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / setParityIndex

Method setParityIndex

app/src/API/Handlers/ModbusHandler.cpp:431–457  ·  view source on GitHub ↗

* @brief Set RTU parity */

Source from the content-addressed store, hash-verified

429 * @brief Set RTU parity
430 */
431API::CommandResponse API::Handlers::ModbusHandler::setParityIndex(const QString& id,
432 const QJsonObject& params)
433{
434 if (!params.contains(QStringLiteral("parityIndex"))) {
435 return CommandResponse::makeError(
436 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: parityIndex"));
437 }
438
439 const int parityIndex = params.value(QStringLiteral("parityIndex")).toInt();
440 auto* modbus = IO::ConnectionManager::instance().modbus();
441 const auto& parityList = modbus->parityList();
442
443 if (parityIndex < 0 || parityIndex >= parityList.count()) {
444 return CommandResponse::makeError(id,
445 ErrorCode::InvalidParam,
446 QStringLiteral("Invalid parityIndex: %1. Valid range: 0-%2")
447 .arg(parityIndex)
448 .arg(parityList.count() - 1));
449 }
450
451 modbus->setParityIndex(static_cast<quint8>(parityIndex));
452
453 QJsonObject result;
454 result[QStringLiteral("parityIndex")] = parityIndex;
455 result[QStringLiteral("parityName")] = parityList.at(parityIndex);
456 return CommandResponse::makeSuccess(id, result);
457}
458
459/**
460 * @brief Set RTU data bits

Callers

nothing calls this directly

Calls 5

modbusMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
parityListMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected