QModbusResponse Class

QModbusResponse is a container class containing the function code and payload that is stored inside a Modbus ADU. More...

Header: #include <QModbusResponse>
qmake: QT += serialbus
Since: Qt 5.6
Inherits: QModbusPdu
Inherited By:

QModbusExceptionResponse

Public Functions

QModbusResponse() = default
QModbusResponse(const QModbusPdu &pdu)
QModbusResponse(FunctionCode code, const QByteArray &data = QByteArray())
QModbusResponse(FunctionCode code, Args... data)

Static Public Members

int calculateDataSize(const QModbusResponse &response)
int minimumDataSize(const QModbusResponse &response)
  • 1 static public member inherited from QModbusPdu
QDataStream &operator>>(QDataStream &stream, QModbusResponse &pdu)

Additional Inherited Members

Detailed Description

QModbusResponse is a container class containing the function code and payload that is stored inside a Modbus ADU.

A typical Modbus response can looks like this:

QModbusResponse response(QModbusResponse::ReadCoils, QByteArray::fromHex("02cd01"));

Note: When using the constructor taking the QByteArray, please make sure to convert the containing data to big-endian byte order before creating the request.

The same response can be created like this, if the values are know at compile time:

quint8 payloadInBytes = 2, outputHigh = 0xcd, outputLow = 0x01;
QModbusResponse response(QModbusResponse::ReadCoils, payloadInBytes, outputHigh, outputLow);

Member Function Documentation

[default] QModbusResponse::QModbusResponse()

Constructs an invalid QModbusResponse.

QModbusResponse::QModbusResponse(const QModbusPdu &pdu)

Constructs a copy of pdu.

QModbusResponse::QModbusResponse(FunctionCode code, const QByteArray &data = QByteArray())

Constructs a QModbusResponse with function code set to code and payload set to data. The data is expected to be stored in big-endian byte order already.

QModbusResponse::QModbusResponse(FunctionCode code, Args... data)

Constructs a QModbusResponse with function code set to code and payload set to data. The data is converted and stored in big-endian byte order.

Note: Usage is limited quint8 and quint16 only. This is because QDataStream stream operators will not only append raw data, but also e.g. size, count etc. for complex types.

[static] int QModbusResponse::calculateDataSize(const QModbusResponse &response)

Calculates the expected data size for response, based on the response's function code and data. Returns the full size of the response's data part; -1 if the size could not be properly calculated.

[static] int QModbusResponse::minimumDataSize(const QModbusResponse &response)

Returns the expected minimum data size for response based on the response's function code; -1 if the function code is not known.

Related Non-Members

QDataStream &operator>>(QDataStream &stream, QModbusResponse &pdu)

Reads a pdu from the stream and returns a reference to the stream.

Note: The function might fail to properly stream PDU's with function code QModbusPdu::Diagnostics or QModbusPdu::EncapsulatedInterfaceTransport because of the missing size indicator inside the PDU. In particular this may happen when the PDU is embedded into a stream that doesn't end with the diagnostic/encapsulated request itself.

© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.