Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.15.9, 6.2.4, 6.3.0
-
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
- Set up a serial port loopback on your dev machine
- Edit the serial ports in the attached source code if necessary (defaults: "COM2" for slave, "COM3" for master)
- Build and run the attached slave application
- 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
For Gerrit Dashboard: QTBUG-103879 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
416396,2 | Modbus: extend documentation | dev | qt/qtserialbus | Status: MERGED | +2 | 0 |
416397,4 | QModbusDevice: introduce an InvalidResponseError error code | dev | qt/qtserialbus | Status: MERGED | +2 | 0 |
416934,2 | Modbus: extend documentation | 6.4 | qt/qtserialbus | Status: MERGED | +2 | 0 |
416935,2 | Modbus: extend documentation | 6.3 | qt/qtserialbus | Status: MERGED | +2 | 0 |
417049,2 | Modbus: extend documentation | tqtc/lts-5.15 | qt/tqtc-qtserialbus | Status: MERGED | +2 | 0 |
417050,2 | Modbus: extend documentation | tqtc/lts-6.2 | qt/tqtc-qtserialbus | Status: MERGED | +2 | 0 |
417208,2 | QModbusDevice: introduce an InvalidResponseError error code | 6.4 | qt/qtserialbus | Status: MERGED | +2 | 0 |