modbus.rtu_request

modbus.rtu_request

modbus.rtu_request

Function

Build a Modbus RTU request frame and automatically append CRC16.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
configObjectYesNoneRequests a configuration object.

Configuration fields

FieldTypeRequiredDefault valueDescription
unit_idIntNo1Slave address, 0 to 255.
function_codeIntNoNoneModbus function code. The function string can also be used.
functionStringNoNoneFunction name, for example read_holding_registers.
addressIntUse when reading and writing registers/coils0Starting address.
quantityIntWhen reading, use1to read the quantity.
valueInt/BoolWhen writing a single register/coil use0to write a value.
valuesArrayUse when writing multiple registers/coilsNoneMulti-value writing data.
pduBytes/ArrayNoNoneOriginal PDU; it will no longer be constructed based on the function code after being passed in.
dataBytes/Array/StringNoNoneUnsupported custom function code additional data.

Return value

TypeDescription
BytesRTU ADU complete request frame.

Code Example

Notes

  • RTU CRC is written to the end of the frame with the low byte first.
  • Result length is limited by BT_BYTES_LIMIT.