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

Function applyModbusRegister

app/src/Misc/CLI.cpp:804–837  ·  view source on GitHub ↗

* @brief Parses a Modbus register spec string and registers it with the Modbus driver. */

Source from the content-addressed store, hash-verified

802 * @brief Parses a Modbus register spec string and registers it with the Modbus driver.
803 */
804static void applyModbusRegister(const QString& spec)
805{
806 QStringList parts = spec.split(':');
807 if (parts.size() != 3) {
808 qWarning() << "Invalid register format. Expected: type:start:count";
809 return;
810 }
811
812 const QString typeStr = parts[0].toLower();
813 static const QHash<QString, quint8> kRegisterTypes = {
814 { QStringLiteral("holding"), 0},
815 { QStringLiteral("input"), 1},
816 { QStringLiteral("coils"), 2},
817 {QStringLiteral("discrete"), 3},
818 };
819 const auto it = kRegisterTypes.constFind(typeStr);
820 if (it == kRegisterTypes.cend()) {
821 qWarning() << "Invalid register type (holding/input/coils/discrete):" << typeStr;
822 return;
823 }
824
825 const quint8 registerType = it.value();
826
827 bool startOk = false;
828 bool countOk = false;
829 const quint16 start = parts[1].toUInt(&startOk);
830 const quint16 count = parts[2].toUInt(&countOk);
831 if (!startOk || !countOk || count < 1 || count > 125) {
832 qWarning() << "Invalid register specification (start:0-65535, count:1-125):" << spec;
833 return;
834 }
835
836 IO::ConnectionManager::instance().modbus()->addRegisterGroup(registerType, start, count);
837}
838
839/**
840 * @brief Applies the Modbus parity option to the active Modbus driver.

Callers 1

applyModbusRegistersFunction · 0.85

Calls 5

cendMethod · 0.80
modbusMethod · 0.80
sizeMethod · 0.45
valueMethod · 0.45
addRegisterGroupMethod · 0.45

Tested by

no test coverage detected