MBAP Block |
A dedicated header is used on UDP packet to identify the MODBUS Application Data Unit. This header is called MBAP (MODBUS Application Protocol)
This header provides some differences compared to the MODBUS RTU application data unit used on a regular serial line (RS232C or RS485)
• | The MODBUS ‘slave address’ field usually used on MODBUS Serial Line is replaced by a single byte named ‘Unit Identifier’ within the MBAP Header. The ‘Unit Identifier’ is used to communicate via devices such as bridges, routers and gateways that use a single IP address to support multiple independent MODBUS end units |
• | All MODBUS requests and responses are designed in such a way that the recipient can verify that a message is finished. For function codes where the MODBUS PDU has a fixed length, the function code alone is sufficient. For function codes carrying a variable amount of data in the request or response, the data field includes a byte count. ? |
• | When MODBUS is carried over UDP, additional length information is carried in the MBAP header to allow the recipient to recognize message boundaries even if the message has been split into multiple packets for transmission. The existence of explicit and implicit length rules, and use of a CRC-32 error check code (on Ethernet) results in an infinitesimal chance of undetected corruption to a request or response message. |
The MBAP Header contains the following fields
Field |
Lenght |
Description |
Client |
Server |
Transaction Identifier |
2 Bytes |
Identification of a MODBUS Request / Response transaction |
Initialised by the client |
Recopied by the server form the received request |
Protocol Identifier |
2 Bytes |
0 = MODBUS protocol |
Initialised by the client |
Recopied by the server form the received request |
Lenght |
2 Bytes |
Number of following bytes |
Initialised by the client (request) |
Initialised by the server (response) |
Unit Identifier |
1 Byte |
Identification of a remote slave connected on a serial line or on other buses |
Initialised by the client |
Recopied by the server form the received request |
The header is 7 bytes long and is formed by
• Transaction Identifier - It is used for transaction pairing, the MODBUS server copies in the response the transaction identifier of the request
• Protocol Identifier – It is used for intra-system multiplexing. The MODBUS protocol is identified by the value 0
• Length - The length field is a byte count of the following fields, including the Unit Identifier and data fields
• Unit Identifier – This field is used for intra-system routing purpose. It is typically used to communicate to a MODBUS+ or a MODBUS serial line slave through a gateway between an Ethernet UDP network and a MODBUS serial line. This field is set by the MODBUS Client in the request and must be returned with the same value in the response by the server
All MODBUS/TCP ADU are sent via UDP to registered port 502