QModbusRequest#
QModbusRequest
is a container class containing the function code and payload that is stored inside a Modbus ADU. More…
Synopsis#
Static functions#
def
calculateDataSize
(pdu)def
minimumDataSize
(pdu)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
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 known at compile time:
quint16 startAddress = 19, numberOfCoils = 10; quint8 payloadInBytes = 2, outputHigh = 0xcd, outputLow = 0x01; QModbusRequest request(QModbusRequest::WriteMultipleCoils, startAddress, numberOfCoils, payloadInBytes, outputHigh, outputLow);
- class PySide6.QtSerialBus.QModbusRequest#
PySide6.QtSerialBus.QModbusRequest(code[, newData=QByteArray()])
PySide6.QtSerialBus.QModbusRequest(pdu)
- Parameters:
newData –
PySide6.QtCore.QByteArray
code –
FunctionCode
Constructs an invalid QModbusRequest
.
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.
Constructs a copy of pdu
.
- static PySide6.QtSerialBus.QModbusRequest.calculateDataSize(pdu)#
- Parameters:
- Return type:
int
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.
See also
minimumDataSize
registerDataSizeCalculator
- static PySide6.QtSerialBus.QModbusRequest.minimumDataSize(pdu)#
- Parameters:
- Return type:
int
Returns the expected minimum data size for request
based on the request’s function code; -1
if the function code is not known.