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