1.ASCII mode When the controller is set to communicate in ASCII (American Standard Code for Information Interchange) mode on Modbus network, every 8-bit byte in the message is sent as an ASCII code (two hexadecimal characters). The main advantage of this method is that the time interval of character sending can reach 1 second without error. Hexadecimal code system, ASCII characters 0...9, each ASCII character in a...f message is a hexadecimal character, which consists of bits of each byte, 1 start bits and 7 data bits. Least significant bit is first sent with 1 parity bits, and no 1 stop bits are not checked (when there is a check). 2-bit (uncalibrated) error detection field LRC (vertical redundancy detection) 2. RTU mode When the controller is set to communicate in RTU mode on Modbus network, each 8-bit byte in the message contains two 4-bit hexadecimal characters. The main advantage of this method is that it can transmit more data than ASCII at the same baud rate. Code system 8-bit binary, hexadecimal number 0...9, each 8-bit field ... f message is 1 start bit of each byte and one bit of 8 data bits. Least significant bit first sends 1 parity bits. If there is no check, there are no 1 stop bits (when there is check) and 2 bits (when there is no check), which are calculated by the transmission equipment and added to the message. The receiving device recalculates the CRC of the received message and compares it with the value in the received CRC field. If the two values are different, there is an error. CRC is to call a 1 6-bit register with all values of "1",and then call a procedure to process the values in each current register of 8 consecutive bytes in the message. Only 8-8 bits of data in each character are valid for CRC, and the start bit, stop bit and parity bit are invalid. In the process of CRC generation, every 8-bit character is XOR with the contents of the register, and the result moves to least significant bit, and most significant bit is filled with zeros. Extract and detect LSB. If the LSB is 1, the register will be reset to the preset value separately. If LSB is 0, it will not be executed. This process will be repeated eight times. After the last bit (bit 8) is completed, the next 8-bit byte is added separately or with the current value of the register. The value in the final register is the CRC value after all the bytes in the message have been executed. When CRC is added to a message, the low-order bytes are added first, and then the high-order bytes are added. The simple function of CRC is as follows: unsigned short CRC16 (puchmsg, us data len) unsigned char * puchmsg; /* message to be CRC checked */unsigned short us datalen; /* Number of bytes in the message */{unsigned charuchhi = 0xff; /* high CRC byte initialization */unsigned charuchrclo = 0xff; /* low CRC byte initialization */unsigned uindex; /* index in CRC loop * */ while (usDataLen-) /* * transmission message buffer */{uindex = uchirch * puchmsgg++; /* Calculate CRC */uchirchi = uchirclo auchrchi[ui index]; uchCRCLo = auchrclo[ui index]; } return((uchCRCHi & lt; & lt8)| uchCRCLo); } /* CRC high byte value table */static unsigned char auchcchi [] = {0x00, 0xc 1, 0x8 1, 0x40, 0x 0 1, 0xc0, 0x80, 0x4 1. 0x4 1,0x00,0xC 1,0x8 1,0x40,0x0 1,0x0,0x80,0x4 1,0x8 1,0x40,0x00,0xC 1,0x8 1,0x40, 0x8 1, 0x40, 0x00/* CRC low byte value table */static char auchrclo[]= {0x 00, 0xc0, 0xc 1, 0x0 1, 0xc3, 0x03, 0x02, 0xc2, 0xc6. 0x0D,0xCD,0x0F,0xCF,0xCE,0x0E,0x0A,0xCA,0xCB,0x0B,0xC9,0x09,0x08,0xC8,0xD8,0x 18,0xD9,0x 1B,0xDB,0xDA,0x 1A,0x 1E,0xDE,0xDF,0x 1F,0xDD,0x 654444