wire / wire-format / modbus-tcp

Modbus TCP frame

Modbus TCP wraps a Modbus RTU PDU in a 7-byte MBAP (Modbus Application Protocol) header. MBAP: transaction ID (2), protocol ID (2, always 0), length (2, bytes following), unit ID (1). Then the PDU: function code (1 byte) + data. Common function codes: 0x01 read coils, 0x02 read discrete inputs, 0x03 read holding registers, 0x04 read input registers, 0x05 write single coil, 0x06 write single register, 0x0F write multiple coils, 0x10 write multiple registers.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: Modbus TCP frame

wire format

spec: Modbus TCP specification

Modbus TCP wraps a Modbus RTU PDU in a 7-byte MBAP (Modbus Application Protocol) header. MBAP: transaction ID (2), protocol ID (2, always 0), length (2, bytes following), unit ID (1). Then the PDU: function code (1 byte) + data. Common function codes: 0x01 read coils, 0x02 read discrete inputs, 0x03 read holding registers, 0x04 read input registers, 0x05 write single coil, 0x06 write single register, 0x0F write multiple coils, 0x10 write multiple registers.

fieldsizemeaning
Transaction ID2 bytes (uint16, big-endian)Transaction identifier (echoed by the server).
Protocol ID2 bytes (uint16, big-endian)Always 0 for Modbus.
Length2 bytes (uint16, big-endian)Number of bytes following (unit ID + PDU).
Unit ID1 byteSlave address (1-247; 0 for TCP gateway, 255 for broadcast).
Function code1 byte0x01 read coils, 0x02 read discrete inputs, 0x03 read holding registers, 0x04 read input registers, 0x05 write single coil, 0x06 write single register, 0x0F write multiple coils, 0x10 write multiple registers, 0x17 read/write multiple registers.
DatavariableFunction-specific parameters (address, count, values).

example:

00 01 00 00 00 06 01 03 00 00 00 0a

Modbus TCP: transaction 1, protocol 0, length 6, unit 1, function 0x03 (read holding registers), address 0, count 10


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/modbus-tcp or /wire-format/modbus-tcp.json