Protocol fields in Modbus RTU Mode
Start position |
Device address |
Function Code |
Data |
CRC verification |
Terminator |
At least 3.5 characters |
8bit |
8bit |
N * 8bit |
16bit |
At least 3.5 characters |
The Modbus RTU mode requires that the start and end of each frame be separated by up to 3.5 characters.
Each character interval is the number of digits/baud rate. It starts with one bit, eight digits of data, one digit of stop bit, and 10 digits of no parity bit.
Taking the baud rate as 9600b/s as an example, the character interval is 1.04 ms, that is, the start and end of each frame are accompanied by a time interval of at least 3.5*1.04 = 3.64ms.
In a byte stream, 1.5 characters are used as the interval between frames. For the above communication rate, 1.5*1.04 = 1.56 mS, that is to say, when the interval of 1 to Ms appears in the upstreaming stream, it may mean that one frame of data ends.
However, it must not be received again within a certain period of time (two characters) after it is met. Otherwise, the frame ended is considered as an error frame.
Since each received byte may be the last byte of a frame of data,Close the previous Enabled3.5Characters and1.5The timer starts again after processing the received data.3.5Characters and1.5To detect the end of the frame data..
This means that the data cannot be received within a period (two characters) after the interframe interval. Otherwise, the frame is an error frame.1.5Characters and3.5The starting point of the timer time is the same, which isModbusProtocolRTUKey points of the Pattern.
Of course, this also increases the interruption load of the system. After a 1.5-character interruption occurs, process the received data (the device address, timeout, parity, and other errors are not considered here ), calculate the number of characters received-2 bytes CRC checksum, and compare the calculation result with the received last two bytes (as the sent CRC checksum, this shows whether this is a complete frame of data. The CRC check is correct, indicating that this is a complete frame of data. The CRC check is incorrect, indicating that this is a frame of wrong data frame and the data frame is incomplete.
After a 1.5-character time interruption occurs, if no 3.5-character time interruption occurs, the received character again, it also indicates that the received frame is an incomplete data frame; in the event of a subsequent 3.5-character interruption, the system processes the complete received data frame and responds accordingly.Here3.5Can also be used as the start of the next frame of data..
From: http://blog.csdn.net/zhongjiezhenuaa/article/details/6552386