Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.7.1, 5.9.3, 5.11.0 Alpha
-
None
-
QT 5.9.2 or QT 5.7 compiled with mingw 5.3.0 32bit on windows 10 home edition.
-
df179c4c18d8feeef48e38cc76cd2a0395ba5de1 (qt/qtserialbus/5.12)
Description
If the register mapping supplied to QModbusService::setMap does not include register 0, the registers values returned by the server in response to a read request will be incorrect. Depending on circumstances the number of register values in the response may also be smaller than the number of requested registers (at the same time the register count in the response frame is correct, hence a incorrect data frame is returned).
The problem is located in QModbusServer::readData. The second last line reads:
{{ newData>setValues(current.values().mid(newData>startAddress(), newData->valueCount())); }}
Proposed change:
{{ newData>setValues(current.values().mid(newData>startAddress() - current.startAddress(), newData->valueCount())); }}
The QVector returned by current.values() returns interval register values starting with current.startRegister(). The first register to be copied to newData is newData->startAddress(). This means that the offset between newData and is newData->startAddress() - current.startAddress().