Detailed Explanation of Modbus Communication Protocol Message Format
Detailed Explanation of Modbus Communication Protocol Message Format
The MODBUS protocol command format is mainly divided into Modbus RTU format and Modbus ASCII format. The command formats of the two formats are introduced respectively below.
MODBUS protocol command format
1. Modbus RTU format command format
The Modbus RTU format transmits data in the form of binary data, and the communication speed is fast. Its command format is as follows:
| Address code | Function code | Data | CRC check code |
illustrate:
Address code: specify the address of the device to be communicated, which can be a broadcast address, a single device address or a multi-device address. The address code occupies 1 byte, and the effective value range is 1~247.
Function code: instruction type, detailing whether the operation performed by the program is to read, write or query the serial port communication protocol. The function code occupies 1 byte, and the effective value range is 1~255.
Data: Encapsulate the data content according to the executed command instruction, and the data length is multi-byte.
CRC check code: The checksum needs to be calculated before data transmission to check whether the data transmission is correct. CRC check occupies 2 bytes.
MODBUS protocol command format
2. Modbus ASCII format command format
The Modbus ASCII format transmits data in ASCII characters. Its command format is as follows:
| : | Address code| Function code| Data| Check code| Enter| Line feed|
illustrate:
":": start character, represented by a colon;
Address code: specify the address of the device to be communicated, which can be a broadcast address, a single device address or a multi-device address. The address code occupies 2 ASCII characters, and the valid value range is 01~FE.
Function code: instruction type, detailing whether the operation performed by the program is reading, writing or querying. The function code occupies 2 ASCII characters, and the valid value range is 01~FF.
Data: Encapsulate the data content according to the executed command instruction, and the data length is multi-byte.
Check code: Check whether the data is transmitted correctly, occupying 2 ASCII characters.
Carriage return: Indicates the end of data transmission, represented by a carriage return.
Newline: Indicates the end of data transmission, represented by a newline.