Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QModbusTCP doesn't change state nor fire error when disconnected

QModbusTCP doesn't change state nor fire error when disconnected

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 290 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I'm facing a lot of issues using QModbus classes. 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 UnconnectedState nor the error signal is emitted.

    So, how to detect such a disconnection?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved