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

[Reg 5.15.2 -> 5.15.9] QModbusClient:: sendRawRequest() produces ModbusDevice::UnknownError when there is no error

    XMLWordPrintable

    Details

    • Commits:
      8360fcd497 (qt/qtserialbus/dev) e50e5f808d (qt/qtserialbus/6.4) e50e5f808d (qt/tqtc-qtserialbus/6.4) 8360fcd497 (qt/tqtc-qtserialbus/dev) 77d797d699 (qt/tqtc-qtserialbus/5.15) 446554558b (qt/tqtc-qtserialbus/6.2) ba9c521ff8 (qt/qtserialbus/6.3)

      Description

      See attached project, which follows the "Echo Request Data" example described at Section 6.8.2 at https://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf

      The relevant code is:

      auto client = new QModbusRtuSerialMaster;
      client->connectDevice();
      
      quint16 subfunction = 0;
      quint16 data = 0xA537;
      auto reply = client->sendRawRequest(QModbusRequest(QModbusRequest::Diagnostics, subfunction, data), 1);
      QObject::connect(reply, &QModbusReply::finished, [=]
      {
          qDebug("Response received");
          qDebug() << "\tReply error:" << reply->error();
          qDebug() << "\tClient error:" << client->error();
          {
              quint16 replySubfunction;
              quint16 replyData;
              QModbusResponse response = reply->rawResult();
              response.decodeData(&replySubfunction, &replyData);
      
              qDebug() << "\tRaw response:" << response;
              qDebug() << "\tFunction:" << response.functionCode() << "\tSub-function:" << replySubfunction << "\tData:" << QByteArray::number(replyData, 16).prepend("0x");
          }
      
          reply->deleteLater();
      });
      

       

      Steps to reproduce

      1. Set up a serial port loopback on your dev machine
      2. Edit the serial ports in the attached source code if necessary (defaults: "COM2" for slave, "COM3" for master)
      3. Build and run the attached slave application
      4. Build and run the attached master application

       

      Alternatively, if you have a real Modbus device, you can use it instead of looping back to the attached slave application.

       

      Output

      Qt 5.15.2 (correct):

      Client connected
      Response received
          Reply error: QModbusDevice::NoError
          Client error: QModbusDevice::NoError
          Raw response: 0x080000a537
          Function: 8     Sub-function: 0     Data: "0xa537"
      

       

      Qt 5.15.9, Qt 6.x (wrong):

      Client connected
      Response received
          Reply error: QModbusDevice::UnknownError
          Client error: QModbusDevice::NoError
          Raw response: 0x080000a537
          Function: 8     Sub-function: 0     Data: "0xa537"
      

      QModbusDevice::UnknownError should not be returned, since the response was received successfully.

       

      Workaround

      Once the fix for QTBUG-101351 is available in a release, the user can override QModbusClient::processResponse() to erase the error.

        Attachments

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

          Activity

            People

            Assignee:
            ivan.solovev Ivan Solovev
            Reporter:
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes