From 28cc24029c0ec5474b8f377ffe6400be5c145298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 16 Jan 2023 16:15:00 +0100 Subject: [PATCH] modbuscommander: update action behavior and fix RTU crash on resource removal --- .../integrationpluginmodbuscommander.cpp | 13 ++++++- .../integrationpluginmodbuscommander.json | 38 +++++++------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/modbuscommander/integrationpluginmodbuscommander.cpp b/modbuscommander/integrationpluginmodbuscommander.cpp index 74402b5..4fde6b7 100644 --- a/modbuscommander/integrationpluginmodbuscommander.cpp +++ b/modbuscommander/integrationpluginmodbuscommander.cpp @@ -387,7 +387,15 @@ void IntegrationPluginModbusCommander::thingRemoved(Thing *thing) qCDebug(dcModbusCommander()) << "Removing thing" << thing->name(); if (thing->thingClassId() == modbusTCPClientThingClassId) { ModbusTCPMaster *modbus = m_modbusTCPMasters.take(thing); + if (modbus) { + modbus->deleteLater(); + } + } else if (thing->thingClassId() == modbusRTUClientThingClassId) { + ModbusRtuMaster *modbus = m_modbusRtuMasters.take(thing); modbus->deleteLater(); + if (modbus) { + modbus->deleteLater(); + } } if (myThings().empty()) { @@ -426,12 +434,12 @@ void IntegrationPluginModbusCommander::onRequestExecuted(QUuid requestId, bool s { if (m_asyncActions.contains(requestId)){ ThingActionInfo *info = m_asyncActions.take(requestId); + info->thing()->setStateValue(m_connectedStateTypeId.value(info->thing()->thingClassId()), success); if (success){ info->finish(Thing::ThingErrorNoError); } else { info->finish(Thing::ThingErrorHardwareNotAvailable); } - info->thing()->setStateValue(m_connectedStateTypeId.value(info->thing()->thingClassId()), success); } if (m_readRequests.contains(requestId)){ @@ -689,7 +697,7 @@ void IntegrationPluginModbusCommander::writeRegister(Thing *thing, ThingActionIn info->finish(Thing::ThingErrorHardwareFailure); return; } - + thing->setStateValue("value", action.param(coilValueActionValueParamTypeId).value().toBool()); info->finish(Thing::ThingErrorNoError); }); } else if (thing->thingClassId() == holdingRegisterThingClassId) { @@ -705,6 +713,7 @@ void IntegrationPluginModbusCommander::writeRegister(Thing *thing, ThingActionIn return; } + thing->setStateValue("value", action.param(holdingRegisterValueActionValueParamTypeId).value().toUInt()); info->finish(Thing::ThingErrorNoError); }); } diff --git a/modbuscommander/integrationpluginmodbuscommander.json b/modbuscommander/integrationpluginmodbuscommander.json index 3c3d36e..0b23bfa 100644 --- a/modbuscommander/integrationpluginmodbuscommander.json +++ b/modbuscommander/integrationpluginmodbuscommander.json @@ -62,7 +62,6 @@ "id": "725b541a-9e0c-4634-81eb-e415c0b8f012", "name": "connected", "displayName": "Connected", - "displayNameEvent": "Connection status changed", "type": "bool", "defaultValue": false } @@ -88,7 +87,6 @@ "id": "dffc59fe-b230-4345-81d6-0a55f9e16520", "name": "connected", "displayName": "Connected", - "displayNameEvent": "Connection status changed", "type": "bool", "defaultValue": false } @@ -106,14 +104,14 @@ "name": "slaveAddress", "displayName": "Slave address", "type": "uint", - "defaultValue": 180 + "defaultValue": 1 }, { "id": "9d40c4ce-d251-43bb-a55e-a8780567bbac", "name": "registerAddress", "displayName": "Register address", "type": "uint", - "defaultValue": 100 + "defaultValue": 0 } ], "stateTypes": [ @@ -121,7 +119,6 @@ "id": "9b3852ac-1518-4417-8a0a-452fcfec8963", "name": "connected", "displayName": "Connected", - "displayNameEvent": "Connection status changed", "type": "bool", "defaultValue": false }, @@ -130,7 +127,6 @@ "name": "value", "displayName": "Value", "displayNameAction": "Write value", - "displayNameEvent": "Value changed", "type": "bool", "writable": true, "defaultValue": false @@ -149,14 +145,14 @@ "name": "slaveAddress", "displayName": "Slave address", "type": "uint", - "defaultValue": 180 + "defaultValue": 1 }, { "id": "d37be0cc-6155-4894-b70f-cbc9adfbe48b", "name": "registerAddress", "displayName": "Register address", "type": "uint", - "defaultValue": 100 + "defaultValue": 0 } ], "stateTypes": [ @@ -165,16 +161,14 @@ "name": "connected", "displayName": "Connected", "type": "bool", - "defaultValue": false, - "displayNameEvent": "connection status changed" + "defaultValue": false }, { "id": "c772bd7f-6e51-4b28-b182-3b979c1298ce", "name": "value", "displayName": "Value", "type": "bool", - "defaultValue": false, - "displayNameEvent": "value changed" + "defaultValue": false } ] }, @@ -190,14 +184,14 @@ "name": "slaveAddress", "displayName": "Slave address", "type": "uint", - "defaultValue": 180 + "defaultValue": 1 }, { "id": "264e381c-d259-4e11-b4b3-332b518ebba3", "name": "registerAddress", "displayName": "Register address", "type": "uint", - "defaultValue": 100 + "defaultValue": 0 } ], "stateTypes": [ @@ -206,16 +200,14 @@ "name": "connected", "displayName": "Connected", "type": "bool", - "defaultValue": false, - "displayNameEvent": "Connection status changed" + "defaultValue": false }, { "id": "eabe2d1b-abe5-4063-adab-3cdd8500b286", "name": "Value", "displayName": "Value", "type": "int", - "defaultValue": 0, - "displayNameEvent": "Value received" + "defaultValue": 0 } ] }, @@ -231,14 +223,14 @@ "name": "slaveAddress", "displayName": "Slave address", "type": "uint", - "defaultValue": 180 + "defaultValue": 1 }, { "id": "c771e09e-15fe-4ea9-9662-c44e2df556a8", "name": "registerAddress", "displayName": "Register address", "type": "uint", - "defaultValue": 100 + "defaultValue": 0 } ], "stateTypes": [ @@ -246,7 +238,6 @@ "id": "1f55b72a-5d13-4ae1-b136-bfd84fd9761f", "name": "connected", "displayName": "Connected", - "displayNameEvent": "Connection status changed", "type": "bool", "defaultValue": false }, @@ -255,10 +246,9 @@ "name": "value", "displayName": "Value", "displayNameAction": "Write value", - "displayNameEvent": "Value changed", - "type": "int", + "type": "uint", "writable": true, - "defaultValue": false + "defaultValue": 0 } ] }