stop sending read requests if the interface is not connected
parent
78055fbdf5
commit
0a57de310c
|
|
@ -77,6 +77,11 @@ bool ModbusRTUMaster::connectDevice()
|
|||
return m_modbusRtuSerialMaster->connectDevice();
|
||||
}
|
||||
|
||||
bool ModbusRTUMaster::connected()
|
||||
{
|
||||
return (m_modbusRtuSerialMaster->state() == QModbusDevice::State::ConnectedState);
|
||||
}
|
||||
|
||||
void ModbusRTUMaster::setNumberOfRetries(int number)
|
||||
{
|
||||
m_modbusRtuSerialMaster->setNumberOfRetries(number);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public:
|
|||
~ModbusRTUMaster();
|
||||
|
||||
bool connectDevice();
|
||||
bool connected();
|
||||
void setNumberOfRetries(int number);
|
||||
void setTimeout(int timeout);
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ bool ModbusTCPMaster::connectDevice() {
|
|||
return m_modbusTcpClient->connectDevice();
|
||||
}
|
||||
|
||||
bool ModbusTCPMaster::connected()
|
||||
{
|
||||
return (m_modbusTcpClient->state() == QModbusDevice::State::ConnectedState);
|
||||
}
|
||||
|
||||
void ModbusTCPMaster::setNumberOfRetries(int number)
|
||||
{
|
||||
m_modbusTcpClient->setNumberOfRetries(number);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public:
|
|||
~ModbusTCPMaster();
|
||||
|
||||
bool connectDevice();
|
||||
bool connected();
|
||||
void setNumberOfRetries(int number);
|
||||
void setTimeout(int timeout);
|
||||
|
||||
|
|
|
|||
|
|
@ -568,6 +568,9 @@ void IntegrationPluginModbusCommander::readRegister(Thing *thing)
|
|||
if (!modbus)
|
||||
return;
|
||||
|
||||
if (!modbus->connected())
|
||||
return; // Send requests only if the modbus interface is connected
|
||||
|
||||
if (thing->thingClassId() == coilThingClassId) {
|
||||
requestId = modbus->readCoil(slaveAddress, registerAddress);
|
||||
} else if (thing->thingClassId() == discreteInputThingClassId) {
|
||||
|
|
@ -583,6 +586,9 @@ void IntegrationPluginModbusCommander::readRegister(Thing *thing)
|
|||
if (!modbus)
|
||||
return;
|
||||
|
||||
if (!modbus->connected())
|
||||
return; // Send requests only if the modbus interface is connected
|
||||
|
||||
if (thing->thingClassId() == coilThingClassId) {
|
||||
requestId = modbus->readCoil(slaveAddress, registerAddress);
|
||||
} else if (thing->thingClassId() == discreteInputThingClassId) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue