Modbus ASCII vs Modbus RTU
To review, we can see that each byte of data can be represented in different ways.
Binary (base2): 10101110 2 characters 0 and 1
Decimal (base10): 174 10 characters 0 through 9
Hexadecimal (base 16): AE 16 characters 0 through F
ASCII (base 256): ® 256 different characters
In Modbus RTU, bytes are sent consecutively with no space in between them with a 3-1/2 character space between messages for a delimiter. This allows the software to know when a new message is starting.
Any delay between bytes will cause Modbus RTU to interpret it as the start of a new message. This keeps Modbus RTU from working properly with modems.
Modbus ASCII marks the start of each message with a colon character " : "
In Modbus RTU each byte is sent as a string of 8 binary characters framed with a start bit, and a stop bit, making each byte 10 bits.
In Modbus ASCII, the number of data bits is reduced from 8 to 7. A parity bit is added before the stop bit which keeps the actual byte size at 10 bits.
Split Data bytes
In Modbus ASCII, each data byte is split into the two bytes representing the two ASCII characters in the Hexadecimal value. For example,
The range of data bytes in Modbus RTU can be any characters from
Error Checksum - LRC Calculation
As mentioned earlier, each Modbus RTU message is terminate with two error checking bytes called a CRC or Cyclic Redundancy Check. Similarly, Modbus ASCII is terminated with an error checking byte called an LRC or Longitudinal Redundancy Check.
Here is a spreadsheet CRC calculator for messages up to 16 bytes.
The calculation of the LRC is much easier than the CRC.
The sum of the resulting byte stream with the LRC will then be 0 since adding the negative subtotal will make the final total zero.
For example, this command shows the data bytes required to request the content of analog output holding registers 40108 to 40110 from the slave device with address 17.
11 03 00 6B 00 03
Add the bytes:
two's compliment (make negative) to get the LRC
total of the entire message including the LRC
The single hex LRC byte is 7E
The LRC byte is then split into two ASCII bytes with the rest of the data.
The two ASCII bytes for the LRC are then 37 and 45
ASCII vs RTU example:
Using the same example shown above to request registers 40108 to 40110 from slave address 17.
11 03 00 6B 00 03
The complete ASCII request is made by first adding the message delimiting characters. A colon is added to the start of the message, the LRC, carriage return and line feed are added to the end:
: 1 1 0 3 0 0 6 B 0 0 0 3 7 E CR LF
Each character is now treated as an ASCII character and replaced with it's hex value to give the final message.
3A 3131 3033 3030 3642 3030 3033 3745 0D 0A
This Modbus ASCII request size is 17 bytes (170 bits)
The equivalent Modbus RTU message would be:
11 03 00 6B 00 03 76 87
This Modbus RTU request size is 8 bytes (80 bits)
Copyright © 2008 Simply Modbus. All rights reserved