QModbusTCP doesn't change state nor fire error when disconnected
-
I'm facing a lot of issues using
QModbusclasses. For example, if I successfully connect to a device:QModbusClient *_modbus; bool ModbusClient::open(QString host, int port) { if (_modbus) { _modbus->disconnectDevice(); delete _modbus; } _modbus = new QModbusTcpClient(this); _modbus->setConnectionParameter(QModbusDevice::NetworkPortParameter, port); _modbus->setConnectionParameter(QModbusDevice::NetworkAddressParameter, host); _modbus->setTimeout(250); _modbus->setNumberOfRetries(1); connect(_modbus, &QModbusDevice::stateChanged,this, &ModbusClient::stateChanged); connect(_modbus, &QModbusDevice::errorOccurred,this, &ModbusClient::errorOccurred); return _modbus->connectDevice(); } void ModbusClient::stateChanged(QModbusDevice::State state) { qDebug() << "state" << state; } void ModbusClient::errorOccurred(QModbusDevice::Error error) { qDebug() << "error"<< error; }then I disconnect the cable from the device, but neither the state changes to
UnconnectedStatenor the error signal is emitted.So, how to detect such a disconnection?