From 78055fbdf5f7098b855f02d1083432b7414353da Mon Sep 17 00:00:00 2001 From: Boernsman Date: Mon, 7 Dec 2020 21:52:56 +0100 Subject: [PATCH] fixed typos and extended readme --- modbus/modbusrtumaster.cpp | 2 +- modbus/modbusrtumaster.h | 2 +- modbuscommander/README.md | 45 ++++++++++++++++--- .../integrationpluginmodbuscommander.cpp | 10 +++-- .../integrationpluginmodbuscommander.json | 2 + 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/modbus/modbusrtumaster.cpp b/modbus/modbusrtumaster.cpp index 068af41..d6e6800 100644 --- a/modbus/modbusrtumaster.cpp +++ b/modbus/modbusrtumaster.cpp @@ -92,7 +92,7 @@ int ModbusRTUMaster::timeout() return m_modbusRtuSerialMaster->timeout(); } -int ModbusRTUMaster::numberOfReties() +int ModbusRTUMaster::numberOfRetries() { return m_modbusRtuSerialMaster->numberOfRetries(); } diff --git a/modbus/modbusrtumaster.h b/modbus/modbusrtumaster.h index f37da90..81c91f1 100644 --- a/modbus/modbusrtumaster.h +++ b/modbus/modbusrtumaster.h @@ -49,7 +49,7 @@ public: void setTimeout(int timeout); int timeout(); - int numberOfReties(); + int numberOfRetries(); QUuid readCoil(uint slaveAddress, uint registerAddress, uint size = 1); QUuid readDiscreteInput(uint slaveAddress, uint registerAddress, uint size = 1); diff --git a/modbuscommander/README.md b/modbuscommander/README.md index ed84d53..13f513c 100644 --- a/modbuscommander/README.md +++ b/modbuscommander/README.md @@ -1,27 +1,62 @@ # Modbus Commander -A nymea plugin to send Modbus commands. +A nymea integration plugin to send Modbus RTU or TCP requests. + +## Usage + +Set up one Modbus RTU or TCP client first. Afterwards a register **thing** can be set-up +and during the setup process the modbus client can be selected. ## Supported Things * Modbus TCP client - * Gateway + * Modbus TCP interface + * IP Address and Port of the target device are requried. * Modbus RTU client - * Gateway - * Discovery setup + * Modbus RTU interface + * All available serial ports will be discovered. + * Baudrate, data bits, stop bits and parity are required. * Coil * Writes and reads a single Modbus Coil + * Modbus device- and register address are required. * Discrete input * Reads a single Modbus discrete input + * Modbus device- and register address are required. * Input register * Reads a single Modbus input register + * Modbus device- and register address are required. * Holding register * Writes and reads a single Modbus holding register + * Modbus device- and register address are required. ## Requirements * The package 'nymea-plugin-modbuscommander' must be installed. -* For Modbus RTU a serial port must be available. +* For Modbus RTU, a serial port must be available. +* For Modbus TCP, the target deviecc must be in the same network. + +## Settings + +### Plug-In Configuration + +*Update interval* + +Defines the interval for register polling in seconds. +Minimum and default value is 1 second. + +### Modbus TCP & RTU Client Settings + +*Timeout* + +Default value is 100 ms, the minimum timeout is 10 ms. +The timeout is used by the Modbus client to determine how long it waits +for a response from the server. The request failes if the response +is not received within the given timeout. + +*Number of retries* + +Sets the number of retries a client will perform before a request fails. +The default value is set to 3. ## More diff --git a/modbuscommander/integrationpluginmodbuscommander.cpp b/modbuscommander/integrationpluginmodbuscommander.cpp index 4de8038..2ae7a14 100644 --- a/modbuscommander/integrationpluginmodbuscommander.cpp +++ b/modbuscommander/integrationpluginmodbuscommander.cpp @@ -177,6 +177,7 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) Thing *thing = info->thing(); if (thing->thingClassId() == modbusTCPClientThingClassId) { + QHostAddress hostAddress = QHostAddress(thing->paramValue(modbusTCPClientThingIpAddressParamTypeId).toString()); uint port = thing->paramValue(modbusTCPClientThingPortParamTypeId).toUInt(); uint numberOfRetries = thing->setting(modbusTCPClientSettingsNumberOfRetriesParamTypeId).toUInt(); @@ -189,7 +190,7 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) } } - qCDebug(dcModbusCommander()) << "Setting up TCP client"; + qCDebug(dcModbusCommander()) << "Setting up TCP client" << thing->name(); qCDebug(dcModbusCommander()) << " address:" << hostAddress.toString(); qCDebug(dcModbusCommander()) << " port:" << port; qCDebug(dcModbusCommander()) << " number of retries:" << numberOfRetries; @@ -211,7 +212,7 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) }); connect(thing, &Thing::settingChanged, thing, [thing, modbusTCPMaster] (const ParamTypeId ¶mTypeId, const QVariant &value) { if (paramTypeId == modbusTCPClientSettingsNumberOfRetriesParamTypeId) { - qCDebug(dcModbusCommander()) << "Set number of reties" << thing->name() << value.toUInt(); + qCDebug(dcModbusCommander()) << "Set number of retries" << thing->name() << value.toUInt(); modbusTCPMaster->setNumberOfRetries(value.toUInt()); } else if (paramTypeId == modbusTCPClientSettingsTimeoutParamTypeId) { qCDebug(dcModbusCommander()) << "Set timeout " << thing->name() << value.toUInt(); @@ -237,7 +238,7 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) } else if (parityString.contains("Odd")) { parity = QSerialPort::Parity::OddParity; } - qCDebug(dcModbusCommander()) << "Setting up RTU client"; + qCDebug(dcModbusCommander()) << "Setting up RTU client" << thing->name(); qCDebug(dcModbusCommander()) << " baud:" << baudrate; qCDebug(dcModbusCommander()) << " stop bits:" << stopBits; qCDebug(dcModbusCommander()) << " data bits:" << dataBits; @@ -263,7 +264,7 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) }); connect(thing, &Thing::settingChanged, thing, [thing, modbusRTUMaster] (const ParamTypeId ¶mTypeId, const QVariant &value) { if (paramTypeId == modbusRTUClientSettingsNumberOfRetriesParamTypeId) { - qCDebug(dcModbusCommander()) << "Set number of reties" << thing->name() << value.toUInt(); + qCDebug(dcModbusCommander()) << "Set number of retries" << thing->name() << value.toUInt(); modbusRTUMaster->setNumberOfRetries(value.toUInt()); } else if (paramTypeId == modbusRTUClientSettingsTimeoutParamTypeId) { qCDebug(dcModbusCommander()) << "Set timeout " << thing->name() << value.toUInt(); @@ -276,6 +277,7 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) || (thing->thingClassId() == discreteInputThingClassId) || (thing->thingClassId() == holdingRegisterThingClassId) || (thing->thingClassId() == inputRegisterThingClassId)) { + qCDebug(dcModbusCommander()) << "Setting up modbus register" << thing->name(); info->finish(Thing::ThingErrorNoError); } else { diff --git a/modbuscommander/integrationpluginmodbuscommander.json b/modbuscommander/integrationpluginmodbuscommander.json index 8259a70..15bfd37 100644 --- a/modbuscommander/integrationpluginmodbuscommander.json +++ b/modbuscommander/integrationpluginmodbuscommander.json @@ -30,6 +30,7 @@ "name": "timeout", "displayName": "Timeout", "type": "uint", + "minValue": 10, "defaultValue": 100 }, { @@ -79,6 +80,7 @@ "name": "timeout", "displayName": "Timeout", "type": "uint", + "minValue": 10, "defaultValue": 100 }, {