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: |
Public Functions
QModbusResponse(const QModbusPdu &pdu) | |
QModbusResponse(FunctionCode code, const QByteArray &data = QByteArray()) |
- 11 public functions inherited from QModbusPdu
Static Public Members
int | calculateDataSize(const QModbusPdu &pdu, const QByteArray &data) |
int | minimumDataSize(const QModbusPdu &pdu) |
- 1 static public member inherited from QModbusPdu
Related Non-Members
QDataStream & | operator>>(QDataStream &stream, QModbusResponse &pdu) |
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
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.
[static]
int QModbusResponse::calculateDataSize(const QModbusPdu &pdu, const QByteArray &data)
Calculates the expected data size for a response, based on the pdu function code. The data byte array is expected to be the part directly following the function code. Returns the full size of the PDU's data part; -1
if the size could not be properly calculated.
[static]
int QModbusResponse::minimumDataSize(const QModbusPdu &pdu)
Returns the minimum data size for a response, based on the pdu function code.
Note: The function returns -1
if the size could not be properly calculated.
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.