ModBus Reply Timeout with Qt 5.10



  • With upgrade to Qt 5.10 I got a "Reply timeout" from sendWriteRequest that I didn't have with 5.9.
    I'm using ModBus RTU and I can see tx and rx bytes on the serial line, so I'm sure that the device replyes.
    I use QEventLoop().processEvents to get synchronous mode.
    I tried to raise timeout (up to 1 second) but no success.
    If I go stepping with debug, all works fine.
    It seems to me like ModBus object is now in the same thread so processEvents cannot process ModBus fuction.

            auto request = QModbusDataUnit(QModbusDataUnit::Coils, MBCommand, 1);
            request.setValue(0,1);
    
            if (auto *reply = m_modbusDevice->sendWriteRequest(request, mSlaveID)) {
                while (!reply->isFinished())
                    QEventLoop().processEvents
                            (QEventLoop::ExcludeUserInputEvents,m_modbusDevice->timeout()+10);
    
                if (reply->error() == QModbusDevice::NoError) {  //here I get "Response timeout"
                    return true;
                }
            }
            return false;
    

    Thank you for any advice.



  • Hi @Landolfi,

    On which platform are you?

    I'm not aware that QModBus was changed (largely) in between, but maybe code in other parts of Qt?

    Anyway, what I would instantly do is avoid the ugly loop with QEventLoop.processEvents() in it.

    Use a proper Signal-Slot-connection and let Qt's event loop run.



  • Hi aha_1980,

    I'm on Windows 10.

    Thank you for your suggestion. The problem is that I was working on another part of the code and not supposed to modify or refactor anything that was already working!
    So, by now I'm happy having discovered that with 5.9 it still works (it took an entire day!) but may be in the future I'll be forced to upgrade, so I will investigate on this problem.



  • Hi @Landolfi,

    well it may be a bug in Qt, but it may as well be a bug in your code that is exhibited by the update.

    With a quick search, I found the following bug for "timeout + windows": QTBUG-53767 Do you think it could be related?



  • Yes, of course may be a problem in the code that accidentaly worked with previous Qt version. I knew that bug, but is not related to my issue, since I'm using a longer timeout in this case.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.