stop sending read requests if the interface is not connected

master
Boernsman 2020-12-07 22:06:05 +01:00
parent 78055fbdf5
commit 0a57de310c
5 changed files with 18 additions and 0 deletions

View File

@ -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);

View File

@ -45,6 +45,7 @@ public:
~ModbusRTUMaster();
bool connectDevice();
bool connected();
void setNumberOfRetries(int number);
void setTimeout(int timeout);

View File

@ -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);

View File

@ -45,6 +45,7 @@ public:
~ModbusTCPMaster();
bool connectDevice();
bool connected();
void setNumberOfRetries(int number);
void setTimeout(int timeout);

View File

@ -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) {