QModbusResponse Class

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

头: #include <QModbusResponse>
qmake: QT += serialbus
Since: Qt 5.8
继承: QModbusPdu
继承者:

QModbusExceptionResponse

公共函数

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

静态公共成员

int calculateDataSize (const QModbusResponse & response )
int minimumDataSize (const QModbusResponse & response )
void registerDataSizeCalculator (FunctionCode fc , CalcFuncPtr calculator )
QDataStream & operator>> (QDataStream & stream , QModbusResponse & pdu )

额外继承成员

详细描述

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"));
					

注意: 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);
					

成员函数文档编制

[default] QModbusResponse:: QModbusResponse ()

Constructs an invalid QModbusResponse .

QModbusResponse:: QModbusResponse (const QModbusPdu & pdu )

构造副本为 pdu .

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

构造 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 )

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

注意: 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.

另请参阅 minimumDataSize and registerDataSizeCalculator .

[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.

[static] void QModbusResponse:: registerDataSizeCalculator ( FunctionCode fc , CalcFuncPtr calculator )

This function registers a user-defined implementation to calculate the response data size for function code fc . It can be used to extend or override the implementation inside QModbusResponse::calculateDataSize ().

CalcFuncPtr is a typedef for a pointer to a custom calculator function with the following signature:

int myCalculateDataSize(const QModbusResponse &pdu);
					

相关非成员

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

读取 pdu stream 并返回流引用。

注意: 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.