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. QModbusDevice timeout
QtWS25 Last Chance

QModbusDevice timeout

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 2.1k 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    About the signal timeoutChanged the documentation says:

    This signal is emitted if the response is not received within the required timeout.

    But I experience a different behavior. This is my test code:

    QModbusTcpClient *modbus = new QModbusTcpClient(this);
    connect(modbus, &QModbusClient::timeoutChanged, this, &ModbusMaster::timeoutChanged);
    connect(modbus, &QModbusClient::stateChanged, this, &ModbusMaster::stateChanged);
    connect(modbus, &QModbusClient::errorOccurred, this, &ModbusMaster::errorOccurred);
    
    modbus->setConnectionParameter(QModbusDevice::NetworkPortParameter, 502);
    modbus->setConnectionParameter(QModbusDevice::NetworkAddressParameter, "127.0.0.1");    
    
    modbus->setTimeout(250);
    modbus->setNumberOfRetries(1);
    modbus->connectDevice();
    

    Actually, the timeoutChanged signal is emitted when I set the timeout (modbus->setTimeout(250);) it seems more like a notifier signal than a real "timeout happened".

    Furthermore, if the server is not available, I would expect an error (errorOccurred signal and stateChanged to UnconnectedState) within the set timeout value (250 ms). Instead they fire after more than 40 seconds!!!!

    Where's my fault here?

    J.HilkJ 1 Reply Last reply
    0
    • M Mark81

      About the signal timeoutChanged the documentation says:

      This signal is emitted if the response is not received within the required timeout.

      But I experience a different behavior. This is my test code:

      QModbusTcpClient *modbus = new QModbusTcpClient(this);
      connect(modbus, &QModbusClient::timeoutChanged, this, &ModbusMaster::timeoutChanged);
      connect(modbus, &QModbusClient::stateChanged, this, &ModbusMaster::stateChanged);
      connect(modbus, &QModbusClient::errorOccurred, this, &ModbusMaster::errorOccurred);
      
      modbus->setConnectionParameter(QModbusDevice::NetworkPortParameter, 502);
      modbus->setConnectionParameter(QModbusDevice::NetworkAddressParameter, "127.0.0.1");    
      
      modbus->setTimeout(250);
      modbus->setNumberOfRetries(1);
      modbus->connectDevice();
      

      Actually, the timeoutChanged signal is emitted when I set the timeout (modbus->setTimeout(250);) it seems more like a notifier signal than a real "timeout happened".

      Furthermore, if the server is not available, I would expect an error (errorOccurred signal and stateChanged to UnconnectedState) within the set timeout value (250 ms). Instead they fire after more than 40 seconds!!!!

      Where's my fault here?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi, @Mark81 said in QModbusDevice timeout:

      Actually, the timeoutChanged signal is emitted when I set the timeout (modbus->setTimeout(250);) it seems more like a notifier signal than a real "timeout happened".

      Furthermore, if the server is not available, I would expect an error (errorOccurred signal and stateChanged to UnconnectedState) within the set timeout value (250 ms). Instead they fire after more than 40 seconds!!!!

      Where's my fault here?

      timeoutchanged is indeed a notifyer that is emited when the timeout time is actually changes, that happens by each call to setTimeout, probably has something to do with QProperty and QML.

      the actual timeout of this Qtimer triggers a QModbusDevice error, this one

      QModbusDevice::TimeoutError	5	A timeout occurred during I/O. An I/O operation did not finish within a given time frame.
      

      That is not triggered during connection, but only when exchaning packages with the ModbusMaster


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        Perhaps my English is not so good, but it seems the documentation is misleading here.
        Ok, I made a workaround using a QTimer and manually handle the connection timeout - sadly.

        aha_1980A 1 Reply Last reply
        0
        • M Mark81

          Perhaps my English is not so good, but it seems the documentation is misleading here.
          Ok, I made a workaround using a QTimer and manually handle the connection timeout - sadly.

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

          Hi @Mark81,

          I guess your English is good enough, as I find the documentation incorrectly too.

          What I expect the signal void QModbusClient::timeoutChanged(int newTimeout) to do is to react on void QModbusClient::setTimeout(int newTimeout) and nothing else.

          I'll check that and prepare a documentation fix.

          Regards

          Qt has to stay free or it will die.

          J.HilkJ 1 Reply Last reply
          1
          • aha_1980A aha_1980

            Hi @Mark81,

            I guess your English is good enough, as I find the documentation incorrectly too.

            What I expect the signal void QModbusClient::timeoutChanged(int newTimeout) to do is to react on void QModbusClient::setTimeout(int newTimeout) and nothing else.

            I'll check that and prepare a documentation fix.

            Regards

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @aha_1980 said in QModbusDevice timeout:

            Hi @Mark81,

            I guess your English is good enough, as I find the documentation incorrectly too.

            What I expect the signal void QModbusClient::timeoutChanged(int newTimeout) to do is to react on void QModbusClient::setTimeout(int newTimeout) and nothing else.

            I'll check that and prepare a documentation fix.

            Regards

            now I'm confused, to what else is it reacting?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            M aha_1980A 2 Replies Last reply
            0
            • J.HilkJ J.Hilk

              @aha_1980 said in QModbusDevice timeout:

              Hi @Mark81,

              I guess your English is good enough, as I find the documentation incorrectly too.

              What I expect the signal void QModbusClient::timeoutChanged(int newTimeout) to do is to react on void QModbusClient::setTimeout(int newTimeout) and nothing else.

              I'll check that and prepare a documentation fix.

              Regards

              now I'm confused, to what else is it reacting?

              M Offline
              M Offline
              Mark81
              wrote on last edited by
              #6

              @J.Hilk said in QModbusDevice timeout:

              now I'm confused, to what else is it reacting?

              The problem is on the documentation only, as it implies it would reacting to an actual timeout:

              This signal is emitted if the response is not received within the required timeout.

              and doesn't say it is fired whenever the property is changed.

              aha_1980A 1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @aha_1980 said in QModbusDevice timeout:

                Hi @Mark81,

                I guess your English is good enough, as I find the documentation incorrectly too.

                What I expect the signal void QModbusClient::timeoutChanged(int newTimeout) to do is to react on void QModbusClient::setTimeout(int newTimeout) and nothing else.

                I'll check that and prepare a documentation fix.

                Regards

                now I'm confused, to what else is it reacting?

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

                Hi @J.Hilk,

                if you look at https://code.woboq.org/qt5/qtserialbus/src/serialbus/qmodbusclient.cpp.html#_ZN13QModbusClient10setTimeoutEi you see when the signal is emitted.

                That is it's only purpose.

                Documentation fix is here: https://codereview.qt-project.org/#/c/241620/1

                Qt has to stay free or it will die.

                1 Reply Last reply
                3
                • J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  oh!
                  ok, thats defenitly a contradictory entry! I only read the Note myself. x)

                  void QModbusClient::timeoutChanged(int newTimeout)
                  This signal is emitted if the response is not received within the required timeout. The new response timeout for the device is passed as newTimeout.

                  Note: Notifier signal for property timeout.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • M Mark81

                    @J.Hilk said in QModbusDevice timeout:

                    now I'm confused, to what else is it reacting?

                    The problem is on the documentation only, as it implies it would reacting to an actual timeout:

                    This signal is emitted if the response is not received within the required timeout.

                    and doesn't say it is fired whenever the property is changed.

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

                    Hi @Mark81,

                    what stays is the connection timeout. I think the ~40 seconds come from the default TCP connection timeout and I'm not sure how to easily change that (I'm not that familiar with the Modbus code).

                    You could ask on the interest mailing list if there's a way to set this timeout. At least it looks like some reasonable thing to do if a machine in the local network is not responding, 30-40 seconds is far to long.

                    Qt has to stay free or it will die.

                    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