ModBus RTU Protocol

Source: Internet
Author: User

(a), communication mode of transmission :
Communication transmission is divided into independent information headers, and transmitted encoded data. The following communication mode definitions are also compatible with the Modbus RTU Communication protocol:

compilation Code 8 bits Binary
Starting bit 1 guests
Data bits 8 Guests
Parity bit 1-bit (even parity bit)
Stop bit 1 guests
Wrong school Check CRC (redundant cyclic code)
Initial structure =≥4 bytes of time
Address Code = 1 bytes
function code = 1 bytes
Data area = N bytes
Error checking = 16-bit CRC code
Time to end structure =≥4 bytes
Address Code: The address code is the first byte of the communication transmission. This byte indicates that the slave that set the address code by the user will receive the information sent by the host. And each slave has a unique address code, and the response loopback begins with its own address code. The address code sent by the host indicates the slave address that will be sent to, and the address code sent from the machine indicates the slave address of the loopback. function Code: The second byte of the communication transmission. The Modbus communication protocol defines a function number from 1 to 127. This instrument only utilizes a subset of the function codes. Sent as a host request, the function code tells the slave what action to perform. As a slave response, the function code sent from the machine is the same as the function code sent from the host, and indicates that the slave has responded to the host. If the highest bit of the function code sent from the machine is 1 (for example, the function code is large at the same time 127), the slave does not respond to the operation or send an error. Data Area: The data area is different depending on the function code. The data area can be an actual value, a set point, and the address that the host sends to the slave or slave to the host.    CRC Code: Two bytes of error detection code. (ii), communication protocol:When the communication command is sent to the instrument, the device that conforms to the corresponding address code communicates the command, removes the address code, reads the information, executes the corresponding task if there is no error, and then returns the execution result to the sender. The information returned includes the address code, the function code to perform the action, the data after the execution of the action, and the error check code. If an error occurs, no information is sent. 1 . Information frame Structure
Address Code function code Data area Error Check Code
8 Guests 8 Guests Nx8 bit 16 Guests
Address Code: The address code is the first byte (8 bits) of the information frame, from 0 to 255. This byte indicates that the slave that sets the address by the user will receive the information sent by the host. Each slave must have a unique address code, and only the slave that conforms to the address code responds to the loopback. When the slave loopback information, the equivalent address code indicates where the information came from. function Code: The function code sent by the host tells the slave what task to perform. The function codes listed in table 1-1 have specific meanings and actions.
Code Meaning Operation
03 Reading data Reads one or more binary values in the current register
06 Resetting a single register Writes a binary value of a set to a single register
   Data Area: The data area contains the actions that need to be performed from the machine or the return information collected by the slave machine. This information can be numeric values, reference addresses, and so on. For example, the function code tells the slave to read the register value, then the data area must contain the starting address to read the register and the read length. For different slave machines, the address and data information are not the same. Error Check code: The host or slave check code can be used to determine whether to receive information error. Sometimes, due to electronic noise or some other interference, the information in the transmission process will be minor changes, error check code to ensure that the host or slave to the transmission process error information does not work. This increases the security and efficiency of the system. The error check uses the CRC-16 checksum method. Note: The format of the information frame is basically the same: address code, function code, data area and error check code. 2 . Error checkingThe redundant cyclic code (CRC) contains 2 bytes, which is the 16-bit binary. The CRC code is calculated by the sending device and placed at the end of the sending message.  The device receiving the information then recalculates the CRC code that receives the information, compares the computed CRC code with the received, and if the two do not match, it indicates an error. CRC code is calculated by first pre-set 16-bit registers are all 1. Each of the 8 bits of data is then processed progressively.  The CRC code is calculated using only 8 bits of data, starting and stopping bits, such as parity bit and even parity bit, do not participate in CRC code calculation. When the CRC code is computed, the 8-bit data differs from the data in the register or the resulting result is a low-displacement one-byte, with 0 filling the highest bit.  Check the lowest bit, if the lowest bit is 1, the contents of the register is different from the preset number or, if the lowest bit is 0, do not make an XOR operation. This process has been repeated 8 times. After the 8th shift, the next 8 bits are different from the contents of the current register or, the process repeats 8 times as above. When all the data information is processed, the content of the last register is CRC code value.  CRC code in the data sent, received low bytes in front.   The procedure for calculating the CRC code is: · Preset 16-bit registers are hex ffff (i.e. all 1).   This register is called a CRC register; •   The first 8-bit data is different from the low of the 16-bit CRC register or, the result is placed in the CRC register;   Move the contents of the register right one (toward the low), fill the highest bit with 0, check the lowest bit; If the lowest bit is 0: repeat the 3rd step (shift again);   If the minimum bit is 1:CRC register and polynomial A001 (1010 0000 0000 0001) are different or;   Repeat steps 3 and 4 until you move 8 times to the right, so that the entire 8-bit data is all processed;   Repeat steps 2 through 5 for the next 8-bit data processing; The last CRC register is the CRC code. 3 . function Code Geneva , read points and return values:The instrument adopts Modbus RTU Communication protocol, and the operation of the reading point ("hold Register") or return value ("Input register") can be made by using the communication command. Both the hold and input registers are 16-bit (2-byte) values, and the highs are in front. This allows both the read point and the return value for the gauge to be 2 bytes. The maximum number of registers that can be read at a time is 60. Since some programmable controllers do not use function code 03, function code 03 is used as the reading point and return value. The slave response command format is slave address, function code, data area and CRC code. The register data in the data area is every two bytes high byte in front. 4 . function Code . , single-point savingThe host uses this command to save the single point data to the meter's memory. The slave also uses this function code to return information to the host.

ModBus RTU Protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.