Technical detail ยท Modbus and the Register Contract
Read the seven-byte Modbus TCP header
In Modbus TCP, the Modbus Application Protocol (MBAP) header carries transaction and routing fields. The protocol data unit (PDU) carries the function and its data. Inspect Figure 5 to see which MBAP fields track a TCP exchange and which field still identifies a downstream serial device.
Read Figure 5 by first splitting the application data unit. Its two parts are the MBAP header and the PDU. The header has three two-byte fields: Transaction Identifier, Protocol Identifier, and Length. It also has a one-byte Unit Identifier, so 2 + 2 + 2 + 1 = 7 bytes. The transaction field pairs each request with its response. The protocol field marks Modbus. At a gateway, the unit field selects the serial target. The PDU then states the function and its data. Keep gateway IP, transaction identity, and unit identity apart so one valid TCP exchange is not credited to the wrong field device.