diff --git a/modbuscommander/integrationpluginmodbuscommander.cpp b/modbuscommander/integrationpluginmodbuscommander.cpp index cbb1c6b..4de8038 100644 --- a/modbuscommander/integrationpluginmodbuscommander.cpp +++ b/modbuscommander/integrationpluginmodbuscommander.cpp @@ -37,32 +37,72 @@ IntegrationPluginModbusCommander::IntegrationPluginModbusCommander() { } +void IntegrationPluginModbusCommander::init() +{ + connect(this, &IntegrationPluginModbusCommander::configValueChanged, this, &IntegrationPluginModbusCommander::onPluginConfigurationChanged); + + m_slaveAddressParamTypeId.insert(coilThingClassId, coilThingSlaveAddressParamTypeId); + m_slaveAddressParamTypeId.insert(inputRegisterThingClassId, inputRegisterThingSlaveAddressParamTypeId); + m_slaveAddressParamTypeId.insert(discreteInputThingClassId, discreteInputThingSlaveAddressParamTypeId); + m_slaveAddressParamTypeId.insert(holdingRegisterThingClassId, holdingRegisterThingSlaveAddressParamTypeId); + + m_registerAddressParamTypeId.insert(coilThingClassId, coilThingRegisterAddressParamTypeId); + m_registerAddressParamTypeId.insert(inputRegisterThingClassId, inputRegisterThingRegisterAddressParamTypeId); + m_registerAddressParamTypeId.insert(discreteInputThingClassId, discreteInputThingRegisterAddressParamTypeId); + m_registerAddressParamTypeId.insert(holdingRegisterThingClassId, holdingRegisterThingRegisterAddressParamTypeId); + + m_connectedStateTypeId.insert(modbusRTUClientThingClassId, modbusRTUClientConnectedStateTypeId); + m_connectedStateTypeId.insert(modbusTCPClientThingClassId, modbusTCPClientConnectedStateTypeId); + m_connectedStateTypeId.insert(coilThingClassId, coilConnectedStateTypeId); + m_connectedStateTypeId.insert(inputRegisterThingClassId, inputRegisterConnectedStateTypeId); + m_connectedStateTypeId.insert(discreteInputThingClassId, discreteInputConnectedStateTypeId); + m_connectedStateTypeId.insert(holdingRegisterThingClassId, holdingRegisterConnectedStateTypeId); + + m_valueStateTypeId.insert(coilThingClassId, coilValueStateTypeId); + m_valueStateTypeId.insert(inputRegisterThingClassId, inputRegisterValueStateTypeId); + m_valueStateTypeId.insert(discreteInputThingClassId, discreteInputValueStateTypeId); + m_valueStateTypeId.insert(holdingRegisterThingClassId, holdingRegisterValueStateTypeId); +} + void IntegrationPluginModbusCommander::discoverThings(ThingDiscoveryInfo *info) { ThingClassId thingClassId = info->thingClassId(); if (thingClassId == modbusRTUClientThingClassId) { Q_FOREACH(QSerialPortInfo port, QSerialPortInfo::availablePorts()) { - //Serial port is not yet used, create now a new one qCDebug(dcModbusCommander()) << "Found serial port:" << port.systemLocation() << "manufacturer" << port.manufacturer() << "description" << port.description() << "serial number" << port.serialNumber(); - QString description = port.manufacturer() + " " + port.description(); - ThingDescriptor thingDescriptor(thingClassId, "Modbus RTU interface "+port.portName(), description); + if (port.isBusy()) { + qCDebug(dcModbusCommander()) << "Serial port ist busy, skipping."; + continue; + } + QString manufacturer = port.manufacturer(); + if (manufacturer.isEmpty()) { + manufacturer = "unknown"; + } + QString description = port.description()+" Manufacturer: "+port.manufacturer(); + ThingDescriptor thingDescriptor(thingClassId, "Modbus RTU interface", description); ParamList parameters; QString serialPort = port.systemLocation(); - foreach (Thing *existingThing, myThings()) { - if (existingThing->paramValue(modbusRTUClientThingSerialPortParamTypeId).toString() == serialPort) { - thingDescriptor.setThingId(existingThing->id()); - // TODO fix rediscovery of USB to SerialPort converters - // QSerialPort doesn't give any information to rediscover the device - // Un and re-plugging an USB device changes the system location - // detecting if the device is usb and using libsub to get the serialnumber may be a solution - break; - } + QString serialnumber = port.serialNumber(); + if (serialnumber.isEmpty()) { + serialnumber = port.manufacturer()+QString::number(port.productIdentifier(), 16); + + } + qCDebug(dcModbusCommander()) << " - Serial number" << serialnumber; + Q_FOREACH (Thing *exisingThing, myThings().filterByParam(modbusRTUClientThingClassId)) { + thingDescriptor.setThingId(exisingThing->id()); + // Rediscovery is broken because of an missing unique device id + // This is a workaround and doesnt work if multiple uart converters are attached. + // ThingDiscoveryInfo may be extended to distinquish between discovery and rediscovery + break; } parameters.append(Param(modbusRTUClientThingSerialPortParamTypeId, serialPort)); + parameters.append(Param(modbusRTUClientThingSerialnumberParamTypeId, serialnumber)); thingDescriptor.setParams(parameters); info->addThingDescriptor(thingDescriptor); } + + //FIXME missing info if it is a rediscovery info->finish(Thing::ThingErrorNoError); return; } else if (thingClassId == discreteInputThingClassId) { @@ -132,33 +172,6 @@ void IntegrationPluginModbusCommander::discoverThings(ThingDiscoveryInfo *info) } } -void IntegrationPluginModbusCommander::init() -{ - connect(this, &IntegrationPluginModbusCommander::configValueChanged, this, &IntegrationPluginModbusCommander::onPluginConfigurationChanged); - - m_slaveAddressParamTypeId.insert(coilThingClassId, coilThingSlaveAddressParamTypeId); - m_slaveAddressParamTypeId.insert(inputRegisterThingClassId, inputRegisterThingSlaveAddressParamTypeId); - m_slaveAddressParamTypeId.insert(discreteInputThingClassId, discreteInputThingSlaveAddressParamTypeId); - m_slaveAddressParamTypeId.insert(holdingRegisterThingClassId, holdingRegisterThingSlaveAddressParamTypeId); - - m_registerAddressParamTypeId.insert(coilThingClassId, coilThingRegisterAddressParamTypeId); - m_registerAddressParamTypeId.insert(inputRegisterThingClassId, inputRegisterThingRegisterAddressParamTypeId); - m_registerAddressParamTypeId.insert(discreteInputThingClassId, discreteInputThingRegisterAddressParamTypeId); - m_registerAddressParamTypeId.insert(holdingRegisterThingClassId, holdingRegisterThingRegisterAddressParamTypeId); - - m_connectedStateTypeId.insert(modbusRTUClientThingClassId, modbusRTUClientConnectedStateTypeId); - m_connectedStateTypeId.insert(modbusTCPClientThingClassId, modbusTCPClientConnectedStateTypeId); - m_connectedStateTypeId.insert(coilThingClassId, coilConnectedStateTypeId); - m_connectedStateTypeId.insert(inputRegisterThingClassId, inputRegisterConnectedStateTypeId); - m_connectedStateTypeId.insert(discreteInputThingClassId, discreteInputConnectedStateTypeId); - m_connectedStateTypeId.insert(holdingRegisterThingClassId, holdingRegisterConnectedStateTypeId); - - m_valueStateTypeId.insert(coilThingClassId, coilValueStateTypeId); - m_valueStateTypeId.insert(inputRegisterThingClassId, inputRegisterValueStateTypeId); - m_valueStateTypeId.insert(discreteInputThingClassId, discreteInputValueStateTypeId); - m_valueStateTypeId.insert(holdingRegisterThingClassId, holdingRegisterValueStateTypeId); -} - void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); @@ -176,10 +189,10 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) } } - qCDebug(dcModbusCommander()) << "Setting up RTU client"; + qCDebug(dcModbusCommander()) << "Setting up TCP client"; qCDebug(dcModbusCommander()) << " address:" << hostAddress.toString(); qCDebug(dcModbusCommander()) << " port:" << port; - qCDebug(dcModbusCommander()) << " number of retires:" << numberOfRetries; + qCDebug(dcModbusCommander()) << " number of retries:" << numberOfRetries; qCDebug(dcModbusCommander()) << " timeout:" << timeout; ModbusTCPMaster *modbusTCPMaster = new ModbusTCPMaster(hostAddress, port, this); @@ -226,10 +239,10 @@ void IntegrationPluginModbusCommander::setupThing(ThingSetupInfo *info) } qCDebug(dcModbusCommander()) << "Setting up RTU client"; qCDebug(dcModbusCommander()) << " baud:" << baudrate; - qCDebug(dcModbusCommander()) << " stop bits:" << baudrate; - qCDebug(dcModbusCommander()) << " data bits:" << baudrate; + qCDebug(dcModbusCommander()) << " stop bits:" << stopBits; + qCDebug(dcModbusCommander()) << " data bits:" << dataBits; qCDebug(dcModbusCommander()) << " parity:" << parityString; - qCDebug(dcModbusCommander()) << " number of retires:" << numberOfRetries; + qCDebug(dcModbusCommander()) << " number of retries:" << numberOfRetries; qCDebug(dcModbusCommander()) << " timeout:" << timeout; ModbusRTUMaster *modbusRTUMaster = new ModbusRTUMaster(serialPort, baudrate, parity, dataBits, stopBits, this); diff --git a/modbuscommander/integrationpluginmodbuscommander.json b/modbuscommander/integrationpluginmodbuscommander.json index 51a13e9..8259a70 100644 --- a/modbuscommander/integrationpluginmodbuscommander.json +++ b/modbuscommander/integrationpluginmodbuscommander.json @@ -98,6 +98,13 @@ "inputType": "TextLine", "defaultValue": "ttyAMA0" }, + { + "id": "9908b01f-a76b-4b21-8242-b507c9252254", + "name": "serialnumber", + "displayName": "Serial number", + "type": "QString", + "defaultValue": "" + }, { "id": "45dfc828-f238-4263-89a3-9b35cf5dea39", "name": "baudRate", diff --git a/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-de.ts b/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-de.ts index 63a8f62..60ba3d6 100644 --- a/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-de.ts +++ b/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-de.ts @@ -4,30 +4,30 @@ ModbusCommander - + Baud rate The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {45dfc828-f238-4263-89a3-9b35cf5dea39}) Baudrate - + Coil The name of the ThingClass ({f53524ea-1d06-40a9-b7a4-041297b21e84}) Coil - - - - - - - - - - - - + + + + + + + + + + + + Connected The name of the ParamType (ThingClass: holdingRegister, EventType: connected, ID: {1f55b72a-5d13-4ae1-b136-bfd84fd9761f}) ---------- @@ -55,11 +55,11 @@ The name of the StateType ({725b541a-9e0c-4634-81eb-e415c0b8f012}) of ThingClass Verbunden - - - - - + + + + + Connection status changed The name of the EventType ({1f55b72a-5d13-4ae1-b136-bfd84fd9761f}) of ThingClass holdingRegister ---------- @@ -73,70 +73,79 @@ The name of the EventType ({725b541a-9e0c-4634-81eb-e415c0b8f012}) of ThingClass Verbunden geändert - + Data bits The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {a27c664b-9f43-4573-a2cc-f65a8fa1a069}) Datenbits - + Discrete input The name of the ThingClass ({d7a15b39-48d3-4591-bdad-ec5e799aa6e5}) Discrete input - + Holding register The name of the ThingClass ({61a2382c-3d9f-41a1-a2fd-27b2af203c56}) Holding Register - + IP Address The name of the ParamType (ThingClass: modbusTCPClient, Type: thing, ID: {2a3fcb23-931b-4ba1-b134-c49b656c76f7}) IP-Adresse - + Input register The name of the ThingClass ({e4c34050-d115-440f-b332-63d36e3e12b8}) Input Register - + Modbus Commander The name of the plugin ModbusCommander ({7dda1b6d-c37e-4c9f-a696-1666f9de66e6}) Modbus Commander - + Modbus RTU client The name of the ThingClass ({776df314-6186-4eb5-b824-f0d916f6d9c3}) Modbus RTU Client - + Modbus TCP client The name of the ThingClass ({35d3e7dc-1f33-4b8c-baa3-eb10b4f157a7}) Modbus TCP Client - + + + Number of retries + The name of the ParamType (ThingClass: modbusRTUClient, Type: settings, ID: {c4f16d6c-c1f2-4862-b0bd-6fae7193eaa8}) +---------- +The name of the ParamType (ThingClass: modbusTCPClient, Type: settings, ID: {b27c95c9-7584-46e1-9e62-89890c7bde67}) + + + + Parity The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {72de1b08-2a27-49c5-90e0-8788c3ea1da3}) Parity - + Port The name of the ParamType (ThingClass: modbusTCPClient, Type: thing, ID: {bee8b151-815a-4159-9d8a-42b76e99b42c}) Port - - - - + + + + Register address The name of the ParamType (ThingClass: holdingRegister, Type: thing, ID: {c771e09e-15fe-4ea9-9662-c44e2df556a8}) ---------- @@ -148,16 +157,22 @@ The name of the ParamType (ThingClass: coil, Type: thing, ID: {9d40c4ce-d251-43b Registeradresse - + + Serial number + The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {9908b01f-a76b-4b21-8242-b507c9252254}) + + + + Serial port The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {ed49f7d8-ab18-4c37-9b80-1004b75dcb91}) Serielle Schnittstelle - - - - + + + + Slave address The name of the ParamType (ThingClass: holdingRegister, Type: thing, ID: {35879cf9-631c-4fe0-95c0-a4bb2e9039e6}) ---------- @@ -169,28 +184,37 @@ The name of the ParamType (ThingClass: coil, Type: thing, ID: {d85977a2-4f9c-40f Slaveadresse - + Stop bits The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {4ea8bcdf-d4c5-45a4-a54f-f10ac3f08a78}) Stopbits - + + + Timeout + The name of the ParamType (ThingClass: modbusRTUClient, Type: settings, ID: {b0af32f0-b8cc-4642-af5a-576732522b2c}) +---------- +The name of the ParamType (ThingClass: modbusTCPClient, Type: settings, ID: {a6aa4eff-205b-426d-ad05-90971a122138}) + + + + Update interval The name of the ParamType (ThingClass: modbusCommander, Type: plugin, ID: {0606c221-b157-4086-885d-7e7b166540a1}) Updateinterval - - - - - - - - - - + + + + + + + + + + Value The name of the ParamType (ThingClass: holdingRegister, ActionType: value, ID: {585cc4fc-07da-415f-a176-12f3baeef025}) ---------- @@ -214,8 +238,8 @@ The name of the StateType ({1cd4cd53-3043-4ed9-9ba8-62985000c599}) of ThingClass Wert - - + + Value changed The name of the EventType ({585cc4fc-07da-415f-a176-12f3baeef025}) of ThingClass holdingRegister ---------- @@ -223,14 +247,14 @@ The name of the EventType ({1cd4cd53-3043-4ed9-9ba8-62985000c599}) of ThingClass Wert geändert - + Value received The name of the EventType ({eabe2d1b-abe5-4063-adab-3cdd8500b286}) of ThingClass inputRegister Wert empfangen - - + + Write value The name of the ActionType ({585cc4fc-07da-415f-a176-12f3baeef025}) of ThingClass holdingRegister ---------- @@ -238,19 +262,19 @@ The name of the ActionType ({1cd4cd53-3043-4ed9-9ba8-62985000c599}) of ThingClas Schreibe Wert - + connection status changed The name of the EventType ({dbe7c801-0888-4e7f-a88b-ba342efb11b6}) of ThingClass discreteInput Verbindung geändert - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + value changed The name of the EventType ({c772bd7f-6e51-4b28-b182-3b979c1298ce}) of ThingClass discreteInput Wert geändert diff --git a/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-en_US.ts b/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-en_US.ts index 54e8350..f6f98e4 100644 --- a/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-en_US.ts +++ b/modbuscommander/translations/7dda1b6d-c37e-4c9f-a696-1666f9de66e6-en_US.ts @@ -4,30 +4,30 @@ ModbusCommander - + Baud rate The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {45dfc828-f238-4263-89a3-9b35cf5dea39}) - + Coil The name of the ThingClass ({f53524ea-1d06-40a9-b7a4-041297b21e84}) - - - - - - - - - - - - + + + + + + + + + + + + Connected The name of the ParamType (ThingClass: holdingRegister, EventType: connected, ID: {1f55b72a-5d13-4ae1-b136-bfd84fd9761f}) ---------- @@ -55,11 +55,11 @@ The name of the StateType ({725b541a-9e0c-4634-81eb-e415c0b8f012}) of ThingClass - - - - - + + + + + Connection status changed The name of the EventType ({1f55b72a-5d13-4ae1-b136-bfd84fd9761f}) of ThingClass holdingRegister ---------- @@ -73,70 +73,79 @@ The name of the EventType ({725b541a-9e0c-4634-81eb-e415c0b8f012}) of ThingClass - + Data bits The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {a27c664b-9f43-4573-a2cc-f65a8fa1a069}) - + Discrete input The name of the ThingClass ({d7a15b39-48d3-4591-bdad-ec5e799aa6e5}) - + Holding register The name of the ThingClass ({61a2382c-3d9f-41a1-a2fd-27b2af203c56}) - + IP Address The name of the ParamType (ThingClass: modbusTCPClient, Type: thing, ID: {2a3fcb23-931b-4ba1-b134-c49b656c76f7}) - + Input register The name of the ThingClass ({e4c34050-d115-440f-b332-63d36e3e12b8}) - + Modbus Commander The name of the plugin ModbusCommander ({7dda1b6d-c37e-4c9f-a696-1666f9de66e6}) - + Modbus RTU client The name of the ThingClass ({776df314-6186-4eb5-b824-f0d916f6d9c3}) - + Modbus TCP client The name of the ThingClass ({35d3e7dc-1f33-4b8c-baa3-eb10b4f157a7}) - + + + Number of retries + The name of the ParamType (ThingClass: modbusRTUClient, Type: settings, ID: {c4f16d6c-c1f2-4862-b0bd-6fae7193eaa8}) +---------- +The name of the ParamType (ThingClass: modbusTCPClient, Type: settings, ID: {b27c95c9-7584-46e1-9e62-89890c7bde67}) + + + + Parity The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {72de1b08-2a27-49c5-90e0-8788c3ea1da3}) - + Port The name of the ParamType (ThingClass: modbusTCPClient, Type: thing, ID: {bee8b151-815a-4159-9d8a-42b76e99b42c}) - - - - + + + + Register address The name of the ParamType (ThingClass: holdingRegister, Type: thing, ID: {c771e09e-15fe-4ea9-9662-c44e2df556a8}) ---------- @@ -148,16 +157,22 @@ The name of the ParamType (ThingClass: coil, Type: thing, ID: {9d40c4ce-d251-43b - + + Serial number + The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {9908b01f-a76b-4b21-8242-b507c9252254}) + + + + Serial port The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {ed49f7d8-ab18-4c37-9b80-1004b75dcb91}) - - - - + + + + Slave address The name of the ParamType (ThingClass: holdingRegister, Type: thing, ID: {35879cf9-631c-4fe0-95c0-a4bb2e9039e6}) ---------- @@ -169,28 +184,37 @@ The name of the ParamType (ThingClass: coil, Type: thing, ID: {d85977a2-4f9c-40f - + Stop bits The name of the ParamType (ThingClass: modbusRTUClient, Type: thing, ID: {4ea8bcdf-d4c5-45a4-a54f-f10ac3f08a78}) - + + + Timeout + The name of the ParamType (ThingClass: modbusRTUClient, Type: settings, ID: {b0af32f0-b8cc-4642-af5a-576732522b2c}) +---------- +The name of the ParamType (ThingClass: modbusTCPClient, Type: settings, ID: {a6aa4eff-205b-426d-ad05-90971a122138}) + + + + Update interval The name of the ParamType (ThingClass: modbusCommander, Type: plugin, ID: {0606c221-b157-4086-885d-7e7b166540a1}) - - - - - - - - - - + + + + + + + + + + Value The name of the ParamType (ThingClass: holdingRegister, ActionType: value, ID: {585cc4fc-07da-415f-a176-12f3baeef025}) ---------- @@ -214,8 +238,8 @@ The name of the StateType ({1cd4cd53-3043-4ed9-9ba8-62985000c599}) of ThingClass - - + + Value changed The name of the EventType ({585cc4fc-07da-415f-a176-12f3baeef025}) of ThingClass holdingRegister ---------- @@ -223,14 +247,14 @@ The name of the EventType ({1cd4cd53-3043-4ed9-9ba8-62985000c599}) of ThingClass - + Value received The name of the EventType ({eabe2d1b-abe5-4063-adab-3cdd8500b286}) of ThingClass inputRegister - - + + Write value The name of the ActionType ({585cc4fc-07da-415f-a176-12f3baeef025}) of ThingClass holdingRegister ---------- @@ -238,19 +262,19 @@ The name of the ActionType ({1cd4cd53-3043-4ed9-9ba8-62985000c599}) of ThingClas - + connection status changed The name of the EventType ({dbe7c801-0888-4e7f-a88b-ba342efb11b6}) of ThingClass discreteInput - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) - + value changed The name of the EventType ({c772bd7f-6e51-4b28-b182-3b979c1298ce}) of ThingClass discreteInput