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. ModBus Reply Timeout with Qt 5.10
QtWS25 Last Chance

ModBus Reply Timeout with Qt 5.10

Scheduled Pinned Locked Moved Unsolved General and Desktop
modbus5.10
5 Posts 2 Posters 2.9k Views
  • 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.
  • L Offline
    L Offline
    Landolfi
    wrote on last edited by
    #1

    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.

    aha_1980A 1 Reply Last reply
    0
    • L Landolfi

      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.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Landolfi
        wrote on last edited by
        #3

        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.

        aha_1980A 1 Reply Last reply
        0
        • L Landolfi

          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.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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?

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Landolfi
            wrote on last edited by
            #5

            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.

            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