Skip to content
  • 0 Votes
    3 Posts
    637 Views
    BeaverShallBurnB

    Hi, @J-Hilk!

    Looks like i found desired method in QModbusDataUnit class docs. Don't know how i missed it being mentioned in List of All Members for QModbusRtuSerialMaster. I guess digging into Qt docs about Modbus was a proper way to solve this :)

    QModbusDataUnit::QModbusDataUnit(QModbusDataUnit::RegisterType type, int address, const QVector<quint16> &data)

    In my case this will be:

    QModbusDataUnit input(QModbusDataUnit::InputRegisters, 3001, data);

    Thanks for joining my journey!

  • 0 Votes
    6 Posts
    796 Views
    K

    Maybe you can override QModbusServer::processRequest() and do all work there.

  • 0 Votes
    3 Posts
    920 Views
    R

    Thank you very much!
    Using the "finished"-signal everything works fine :-)

  • 0 Votes
    3 Posts
    3k Views
    J.HilkJ

    @tangxinzhou I'm afraid I do not have a solid solutions. I'm running a workaround now.

    Let me post it for you:

    void connectDevice(bool connect) { if(connect){ switch (mDevice->state()) { case QModbusDevice::ClosingState: case QModbusDevice::ConnectedState: case QModbusDevice::ConnectingState: mDevice->deleteLater(); mDevice = new QModbusRtuSerialMaster(this); setupSignalSlots(); QTimer::singleShot(100,this, [=]{setConnectParamter(m_port,m_paramter);}); break; case QModbusDevice::UnconnectedState: default: if(!mDevice->connectDevice()){ emit signalModbusError(mDevice->errorString()); mDevice->disconnectDevice(); } break; } }else{ stopPoll(); mDevice->disconnectDevice(); QTimer::singleShot(200,this,[=]{checkDisconnected();}); } } void checkDisconnected() { if(mDevice->state() != QModbusDevice::UnconnectedState){ mDevice->deleteLater(); mDevice = new QModbusRtuSerialMaster(this); setupSignalSlots(); } }