
MANUEL STA46
Modbus TCP
JP Viskovic 30/08/2005 OEE-F
5
1-3
Modbus TCP frame Format
A dedicated header is used on TCP/IP to identify the MODBUS Application Data Unit. It is called the
MBAP header (MODBUS Application Protocol header).
This header provides some differences compared to the MODBUS RTU application data unit used on
serial line:
•
The MODBUS ‘ slave address’ field usually used on MODBUS Serial Line is replaced by a single
byte ‘ 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 TCP, 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.
1-3-0
MBAP Header description
The MBAP Header contains the following fields:
Fields Length
Description
Client
Server
Transaction
Identifier
2 Bytes
Identification of a
MODBUS Request /
Response transaction
Initialized by the
client ( request)
Recopied by the
server from the
received request
Protocol
Identifier
2 Bytes
0 = MODBUS protocol
Initialized by the
client ( request)
Recopied by the
server from the
received request
Length
2 Bytes
Number of following
bytes
Initialized by the
client ( request)
Initialized by the
server (Response)
Unit Identifier
1 Byte
Identification of a
remote slave
connected on a serial
line or on other buses
Initialized by the
client ( request)
Recopied by the
server from the
received request
The header is 7 bytes long:
•
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 serial line slave through a gateway between an
Ethernet TCP-IP 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 TCP on registered port 502.