On this page
QModbusRequest Class
QModbusRequest is a container class containing the function code and payload that is stored inside a Modbus ADU. More...
| Header: | #include <QModbusRequest> | 
| qmake: | QT += serialbus | 
| Since: | Qt 5.6 | 
| Inherits: | QModbusPdu | 
Public Functions
| QModbusRequest() = default | |
| QModbusRequest(const QModbusPdu &pdu) | |
| QModbusRequest(FunctionCode code, const QByteArray &data = QByteArray()) | |
| QModbusRequest(FunctionCode code, Args... data) | 
- 11 public functions inherited from QModbusPdu
Static Public Members
| int | calculateDataSize(const QModbusRequest &request) | 
| int | minimumDataSize(const QModbusRequest &request) | 
- 1 static public member inherited from QModbusPdu
Related Non-Members
| QDataStream & | operator>>(QDataStream &stream, QModbusRequest &pdu) | 
Additional Inherited Members
- 1 protected function inherited from QModbusPdu
Detailed Description
QModbusRequest is a container class containing the function code and payload that is stored inside a Modbus ADU.
A Modbus request usually consists of a single byte describing the FunctionCode and N bytes of payload
A typical Modbus request can looks like this:
QModbusRequest request(QModbusRequest::WriteMultipleCoils,
    QByteArray::fromHex("0013000a02cd01"));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 request can be created like this, if the values are know at compile time:
quint16 startAddress = 19, numberOfCoils = 10;
quint8 payloadInBytes = 2, outputHigh = 0xcd, outputLow = 0x01;
QModbusRequest request(QModbusRequest::WriteMultipleCoils, startAddress, numberOfCoils,
    payloadInBytes, outputHigh, outputLow);Member Function Documentation
[default] QModbusRequest::QModbusRequest()
  Constructs an invalid QModbusRequest.
QModbusRequest::QModbusRequest(const QModbusPdu &pdu)
Constructs a copy of pdu.
QModbusRequest::QModbusRequest(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.
QModbusRequest::QModbusRequest(FunctionCode code, Args... data)
Constructs a QModbusRequest 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 QModbusRequest::calculateDataSize(const QModbusRequest &request)
  Calculates the expected data size for request based on the request's function code and data. Returns the full size of the request's data part; -1 if the size could not be properly calculated.
[static] int QModbusRequest::minimumDataSize(const QModbusRequest &request)
  Returns the expected minimum data size for request based on the request's function code; -1 if the function code is not known.
Related Non-Members
QDataStream &operator>>(QDataStream &stream, QModbusRequest &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.
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
 https://doc.qt.io/archives/qt-5.6/qmodbusrequest.html