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

RTU serial slave incorrect processing of extra characters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.11.1
    • SerialBus: MOD Bus
    • None
    • All

    Description

      We've found that with certain types of hardware problems extra characters may be added at the end of the modbus frame. If that happens, not only will that frame will not be correctly processed, but all subsequent (valid) frames will not be processed until the software is reset.

      Because the problem is hardware-dependent and happens very rarely I can't attach an example program, but this log of of qCDebug statements should hopefully make the issue clear:

      (RTU server) Received ADU: "010307d00002c486"
      (RTU server) Response ADU: "01030400000000fa33"
      (RTU server) Received ADU: "010307d00002c486"
      (RTU server) Response ADU: "01030400000000fa33"
      (RTU server) Received ADU: "010307d00002c486"
      (RTU server) Response ADU: "01030400000000fa33"
      (RTU server) Received ADU: "010307d0"
      (RTU server) ADU does not match expected size, ignoring

      -Incomplete frame is received which has less characters than expected, it's added to the buffer but not processed further.

      (RTU server) Received ADU: "010307d00002c486"

      -The rest of the frame arrives in the buffer and is correctly processed. Buffer is cleared

      (RTU server) Response ADU: "01030400000000fa33"
      (RTU server) Received ADU: "010307d00002c48600"

      -Extra characters have been appended to the frame due to hardware malfunction. We do not have the expected number of characters so the frame is not processed and the buffer isn't cleared.

      (RTU server) ADU does not match expected size, ignoring
      (RTU server) Received ADU: "010307d00002c4860001"

      -All new frames arriving in the buffer are now appended to it, but the buffer is now always bigger than the expected size and will never be processed.

      (RTU server) ADU does not match expected size, ignoring
      (RTU server) Received ADU: "010307d00002c48600010307d00002c48600"
      (RTU server) ADU does not match expected size, ignoring
      (RTU server) Received ADU: "010307d00002c48600010307d00002c4860000"
      (RTU server) ADU does not match expected size, ignoring

      -The data we're receiving is now valid but it will never be processed.

      ...

      The problem is in qmodbusrtuserialslave_p.h, the lambda in setupSerialPort(). This bit of code:

                  else if ((pduSizeWithoutFcode < 0) || ((2 + pduSizeWithoutFcode + 2) != adu.rawSize())) {
                      qCWarning(QT_MODBUS) << "(RTU server) ADU does not match expected size, ignoring";
                      // The quantity of messages addressed to the remote device that it could not
                      // handle due to a character overrun condition, since its last restart, clear
                      // counters operation, or power-up. A character overrun is caused by data
                      // characters arriving at the port faster than they can be stored, or by the loss
                      // of a character due to a hardware malfunction.
                      incrementCounter(QModbusServerPrivate::Counter::BusCharacterOverrun);
                      storeModbusCommEvent(event | QModbusCommEvent::ReceiveFlag::CharacterOverrun);
                      return;
                  }

       

      works fine when adu.rawSize() has less characters than expected, but leads to above problem if it has more characters. If m_request buffer is cleared if more characters are received than expected than the valid frames received after the frame with incorrect number of characters will be correctly processed.

      Attachments

        Issue Links

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

          Activity

            People

              heimrich Karsten Heimrich
              ip2018 Illya Paranucke
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes