Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-53767

modbus request timeout on windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 5.6.0, 5.7.0 Alpha, 5.7.0 Beta
    • Fix Version/s: 5.13.0 RC 1
    • Component/s: SerialBus: MOD Bus
    • Labels:
      None
    • Environment:
      windows 7
    • Commits:
      a40fcae40fdc4d7cd658c4b8ab38aad7572f2ecf

      Description

      Calculation of send timeout is incorrect.

      Here is the calculation code:

      http://code.qt.io/cgit/qt/qtserialbus.git/tree/src/serialbus/qmodbusrtuserialmaster_p.h#n294

                  // Example: 9600 baud, 11 bit per packet -> 872 char/sec
                  // so: 1000 ms / 872 char = 1.147 ms/char * 3.5 character
                  m_sendTimer.start((1000. / (qreal(m_baudRate) / 11.)) * m_current.adu.size());
      

      Which in my case (115200 and 8 bytes of data) gives 0.7 ms. And after conversion to int, it becomes zero.
      So m_sendTimer is fired up immediately, which brings us to to this code:

      http://code.qt.io/cgit/qt/qtserialbus.git/tree/src/serialbus/qmodbusrtuserialmaster_p.h#n323

                  } else if (m_current.bytesWritten < m_current.adu.size()) {
                      qCDebug(QT_MODBUS) << "(RTU client) Send failed:" << m_current.requestPdu;
      
                      if (m_current.numberOfRetries <= 0) {
                          if (m_current.reply) {
                              m_current.reply->setError(QModbusDevice::TimeoutError,
                                  QModbusClient::tr("Request timeout."));
                          }
        

      So there comes a premature timeout.

      I experimented with a timeout and found that even a value of 15-20ms does not give stable results. only the value of around 50ms gives a stable result in my case.
      I suppose that timeout calculation must include some additional minimum time constant.

      It is only related to windows. In linux everything works perfectly.

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              • Assignee:
                heimrich Karsten Heimrich
                Reporter:
                unkier Dmitry Shapovalov
              • Votes:
                1 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes