Amperfied: Fix a crash when the Modbus RTU Master is removed

pull/148/head
Michael Zanetti 2023-08-14 13:03:44 +02:00
parent ba922c7e7e
commit ac47803265
1 changed files with 5 additions and 0 deletions

View File

@ -270,6 +270,11 @@ void IntegrationPluginAmperfied::setupRtuConnection(ThingSetupInfo *info)
{
Thing *thing = info->thing();
ModbusRtuMaster *master = hardwareManager()->modbusRtuResource()->getModbusRtuMaster(thing->paramValue(energyControlThingRtuMasterParamTypeId).toUuid());
if (!master) {
qCWarning(dcAmperfied()) << "The Modbus Master is not available any more.";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The modbus RTU connection is not available."));
return;
}
quint16 slaveId = thing->paramValue(energyControlThingSlaveIdParamTypeId).toUInt();
AmperfiedModbusRtuConnection *connection = new AmperfiedModbusRtuConnection(master, slaveId, thing);