From e51701cc6cccb03d3b39f5777faad33c53715401 Mon Sep 17 00:00:00 2001 From: Tarja Sundqvist Date: Wed, 15 Jun 2022 20:08:46 +0300 Subject: Bump version --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index c0e0d61..2e81da4 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,4 @@ load(qt_build_config) CONFIG += warning_clean DEFINES += QT_NO_FOREACH -MODULE_VERSION = 5.15.10 +MODULE_VERSION = 5.15.11 -- cgit v1.2.3 From 77d797d6998768acfd5bfcef686974732670fa5d Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Wed, 15 Jun 2022 10:39:09 +0200 Subject: Modbus: extend documentation Clarify that default Modbus client implementation does not handle all FunctionCodes and that this needs to be implemented in the custom Modbus clients. Also explicitly mention that UnknownError can also mean that the received function code is not implemented. This commit amends 09927894825d97197ffa656576e6be780371dda0 Fixes: QTBUG-103879 Change-Id: Ifb70107cda2595293b9759504fcfc1ca1a3abfa7 Reviewed-by: Karsten Heimrich Reviewed-by: Alex Blasche Reviewed-by: Sze Howe Koh (cherry picked from commit 8360fcd497bcf6e52412629cd4e29f1ef05a93d6) Reviewed-by: Qt Cherry-pick Bot --- src/serialbus/qmodbusclient.cpp | 8 ++++++-- src/serialbus/qmodbusdevice.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/serialbus/qmodbusclient.cpp b/src/serialbus/qmodbusclient.cpp index 72cc5a0..a91ba46 100644 --- a/src/serialbus/qmodbusclient.cpp +++ b/src/serialbus/qmodbusclient.cpp @@ -222,8 +222,12 @@ QModbusClient::QModbusClient(QModbusClientPrivate &dd, QObject *parent) : } /*! - Processes a Modbus server \a response and stores the decoded information in \a data. Returns - true on success; otherwise false. + Processes a Modbus server \a response and stores the decoded information in + \a data. Returns \c true on success; otherwise \c false. + + \note The default implementation does not support all + \l {QModbusPdu::}{FunctionCode}s. Override this method in a custom Modbus + client implementations to handle the needed functions. */ bool QModbusClient::processResponse(const QModbusResponse &response, QModbusDataUnit *data) { diff --git a/src/serialbus/qmodbusdevice.cpp b/src/serialbus/qmodbusdevice.cpp index 8036355..91a7652 100644 --- a/src/serialbus/qmodbusdevice.cpp +++ b/src/serialbus/qmodbusdevice.cpp @@ -204,6 +204,13 @@ void QModbusDevice::setConnectionParameter(int parameter, const QVariant &value) \value ReplyAbortedError The reply was aborted due to a disconnection of the device. \value UnknownError An unknown error occurred. + + \note An UnknownError can also indicate that the received + \l {QModbusPdu::}{FunctionCode} is not supported in the current + implementation. In this case custom Modbus client implementations need to + override the \l {QModbusClient::}{processResponse()} and + \l {QModbusClient::}{processPrivateResponse()} methods to provide support + for needed functions. */ /*! -- cgit v1.2.3 From db246244f5079e87a204d3f2d46d5992ab34e181 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sun, 15 May 2022 23:58:48 +0300 Subject: Make pduFromStream work on big endian (again) reinterpret_cast(&code) works on little endian, but not on big endian, because code is an int (4 bytes value). I fixed this bug earlier in afb7f76efafcb04e430168416d9d74113bde13bc, but it was added back in 2c0bb738e988d84f36169e0103d051745b678479. [ChangeLog][QModbusPdu] Fix reading from stream on big endian systems Change-Id: Ic432d5c86aac40ec2acdc07b4c4881967a023966 Reviewed-by: Marc Mutz (cherry picked from commit e7ce9ac18b5a1ef33e2343d85a01bb7947d1668d) Reviewed-by: Qt Cherry-pick Bot --- src/serialbus/qmodbuspdu.cpp | 21 +++++++++++++++++++-- src/serialbus/qmodbuspdu.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/serialbus/qmodbuspdu.cpp b/src/serialbus/qmodbuspdu.cpp index 112b73d..42548e5 100644 --- a/src/serialbus/qmodbuspdu.cpp +++ b/src/serialbus/qmodbuspdu.cpp @@ -128,11 +128,12 @@ static QDataStream &pduFromStream(QDataStream &stream, Type type, QModbusPdu *pd } raii = { pdu }; QModbusPdu::FunctionCode code = QModbusPdu::FunctionCode::Invalid; - if (stream.readRawData(reinterpret_cast(&code), sizeof(quint8)) != sizeof(quint8)) + stream >> code; + if (stream.status() == QDataStream::ReadPastEnd) return stream; pdu->setFunctionCode(code); - if (code == QModbusPdu::Invalid || code == QModbusPdu::UndefinedFunctionCode) // shortcut + if (code == QModbusPdu::Invalid) // shortcut return stream; constexpr const int MaxPduDataSize = 252; // in bytes @@ -622,6 +623,22 @@ void QModbusRequest::registerDataSizeCalculator(FunctionCode fc, CalcFuncPtr cal requestSizeCalculators()->insert(quint8(fc), calculator); } +/*! + \internal + + Reads a FunctionCode from a \a stream. + In stream we serialize FunctionCode as one byte, so we use a temporary char + variable to make the code work on both little endian and big endian systems. + If reading from stream fails, code will retain original value. +*/ +QDataStream &operator>>(QDataStream &stream, QModbusPdu::FunctionCode &code) +{ + char buffer; + if (stream.readRawData(&buffer, 1) == 1) + code = static_cast(buffer); + return stream; +} + /*! \relates QModbusRequest diff --git a/src/serialbus/qmodbuspdu.h b/src/serialbus/qmodbuspdu.h index f299f24..2c50800 100644 --- a/src/serialbus/qmodbuspdu.h +++ b/src/serialbus/qmodbuspdu.h @@ -187,6 +187,7 @@ private: }; Q_SERIALBUS_EXPORT QDebug operator<<(QDebug debug, const QModbusPdu &pdu); Q_SERIALBUS_EXPORT QDataStream &operator<<(QDataStream &stream, const QModbusPdu &pdu); +Q_SERIALBUS_EXPORT QDataStream &operator>>(QDataStream &stream, QModbusPdu::FunctionCode &code); class QModbusRequest : public QModbusPdu { -- cgit v1.2.3