HCBBS Forum (English)
Submit Chemical Projects / Find Solutions
Amplify Your Requirements on a Broader Chemical Platform *Engineering · Technology · Equipment · Solutions*
Submit Request

MODBUS_RTU communication protocol

2009-12-07View Original

Thread Content

(This agreement uses a master-slave Q&A format.) PDM series meters/transmitters: The PDM series meters/transmitters feature a completely new design that revolutionizes the concept of traditional meters; It features multi-functionality, high precision, digital operation, programmability, a compact design, and multi-screen display, enabling it to meet the future demands of the power industry for electricity meters. MODBUS communication protocol: The ModBus protocol enables the PDM series of instruments/transmitters to exchange information and transfer data with programmable logic controllers (PLCs), RTUs, SCADA systems, DCSs from various internationally renowned brands such as Schneider, Siemens, AB, GE, as well as with monitoring systems that are ModBus-compatible. The PDM series of instruments/transmitters can be turned into a power monitoring system simply by adding a set of computer-based (or industrial PC-based) monitoring software (such as KingView, Intouch, FIX, Synall, etc.). Wide system integration: The PDM series of instruments/transmitters feature standard RS-485/422 communication interfaces as well as the ModBus communication protocol, which is widely adopted by the power and industrial automation sectors both domestically and internationally as a standard for system integration. Type and format of communication data: Information is transmitted asynchronously in units of bytes. The communication data transmitted between the master station and the slave station is in a 11-bit word format: Word format (serial data) – 11 bits of binary data, 1 start bit, 8 data bits, 1 parity bit (with parity/checksum or without it), and 1 stop bit (with parity/checksum or 2 bits for no parity/checksum). ● Format of communication data (information frame): Data format – address code, function code, data area, error check; Data length – 1 byte, 1 byte, N bytes, or 16-bit CRC code (redundant cyclic code). ★ Note: 1. One byte consists of 8 bits of binary data. 2. ModBus is a registered trademark of Modicon Corporation. 3. “Slave” refers to PDM in this document. I. Communication information transmission process: When a communication command is sent from the sending device (host) to the receiving device (slave), the slave that matches the corresponding address code receives the command, reads the information based on the function code and relevant requirements. If the CRC check is successful, it carries out the corresponding task and then sends the result (data) back to the host. The information returned includes the address code, function code, data after execution, and CRC checksum. If the CRC check fails, no information is returned. 1.1 Address code: The address code is the first byte (8 bits) of each communication message frame, ranging from 0 to 255. This byte indicates that the slave with an address set by the user will receive the messages sent by the host. Each slave must have a unique address code, and only the slave whose address code matches can respond with a reply message. When the slave device sends back information, the returned data all start with their respective address codes. The address code sent by the master indicates the address of the slave to which the data is to be sent, while the address code returned by the slave indicates the slave address from which the response is coming. The corresponding address code indicates where the information comes from. 1.2 Function code: It is the second byte transmitted in each communication message frame. The function codes that can be defined by the ModBus communication protocol range from 1 to 127. The PDM series of instruments/transmitters utilize only a portion of the function codes. Sent as a host request, it uses a function code to tell the slave what action to perform. As a response from the slave, the function code returned by the slave is the same as the one sent by the master, indicating that the slave has responded to the master and has carried out the relevant operations. Table 8.1 Some MODBUS Function Codes Function Code Definition Operation (Binary) 02 Read Digital Input Read the status of one or more digital input channels 01 Read Digital Output Read the status data of one or more digital output channels 03 Read Register Data Read the data from one or more registers 05 Write Digital Output Control the \"on/off\" state of a relay 06 Write Single Register Write a set of binary data into a single register 10 Write Multiple Registers Write multiple sets of binary data into several registers 1.3 Data Area: The data area specifies what information should be returned by the slave device or what actions it should perform. This information can be data (such as digital input/output, analog input/output, registers, etc.), reference addresses, etc. For example, when the master device uses function code 03 to instruct the slave device to return the value of a register (including the starting address of the register to be read and the length of the data to be read), the returned data includes both the data length of the register and its actual content. For different slaves, the address and data information are different (a communication information table should be provided). The PDM series of instruments/transmitters use the Modbus communication protocol; the host device (PLC, RTU, PC, DCS, etc.) can read their data registers using communication commands (function code 03) – the details of their data information are provided in the appendix. The data registers of the PDM series of instruments/transmitters can store hundreds of electrical quantities (such as current, voltage, power, 0th to 31st harmonic components, etc.), all of which are 16-bit (2-byte) binary data with the higher bits coming first ; The maximum number of registers that can be read at once (i.e., the number of various quantities) is 50. The command format for PDM responses is slave address, function code, data area, and CRC code. The data in the data area is always two bytes long, with the higher byte coming first (except for electrical energy). Note: 1. The PDM-820AC/ACM/ACR and PDM-800AC/ACM have function codes “03”, “06”, and “10” ; 2. If PDM uses the MODBUS ASCII communication protocol, its communication data format is ; 7 data bits, 1 stop bit, even parity. II. Introduction to MODBUS Function Codes 2.1 Function Code “02”: Reading the status of 1 or more digital inputs. For example: The host wants to read the input status of DI1–DI4 at address 01. The address and data of the slave (PDM) data register are as follows: Start bit address, DI register data (in hexadecimal). Note: When DI1/DI2/DI4 are at “1” and DI3 is at “0”. The format of the message sent by the host is as follows: Number of bytes sent, Information sent. Note: Message sent from slave address 101 to slave address 01. Function code 102: Read the status of digital input signals. Start BIT bit: 20000; the address of the start BIT bit is 0000. Length of data to be read: 20004; reads the status of 4 digital input signals. CRC code: 279C9; this CRC code is calculated by the host. The format of the message returned by the slave (PDM) in response is as follows: Number of bytes returned, Information returned. Note: Message from slave address 101, coming from slave address 01. Function code 102: Read the status of digital input signals. Data length: 101, 1 byte (8 BITs). DI status data: 10B, content of the DI register. CRC code: 2E04F; this CRC code is calculated by the slave. 2.2 Function code “01”: Read the status of 1 or more digital output signals. For example, the host wants to read the output status of DO1 and DO2 at address 01. The address and data of the slave (PDM) data register are as follows: Start bit address, DO register data (in hexadecimal). Note: When the output status of DO2 is “1”, the output status of DO1 is “0”. The format of the message sent by the host is as follows: Number of bytes sent, Information sent. Note: Sent from slave address 101 to slave with address 01. Function code 101: Read the status of digital outputs. Start BIT bit 20000; the address of the start BIT bit is 0000. Data length 20002: Reads the status bits of 2 relay outputs. CRC code 2BDCB: The CRC code is calculated by the host. The format of the message returned by the slave (PDM) in response is as follows: Number of bytes returned, Information returned. Note: From slave address 101, coming from slave 01. Function code 101: Read the status of digital outputs. Data length 101: 1 byte (8 BITs). DO status data 102: Content of the DO register. CRC code 2D049: The CRC code is calculated by the slave. 2.3 Function code “03”: Read multiple register inputs. For example, the host wants to read the data from 3 slave registers with address 01 and start address 0116. The address and data of the slave (PDM) data register are as follows: Register Address, Register Data (in hexadecimal). Corresponding to PDM voltage levels: 01161784 for UA, 01171780 for UB, 0118178A for UC. The format of the message sent by the host is as follows: Number of bytes sent, Information sent, Remarks. Message sent from slave address 101 to slave with address 01; Function code 103 indicates reading registers; Starting address is 0116; Data length is 30003, meaning 3 registers are read (a total of 6 bytes); CRC code is 2E5F3, calculated by the host. The format of the response message sent back by the slave (PDM) is as follows: Number of bytes in the response, Information returned, Remarks. Response from slave address 101, coming from slave 01; Function code 103 indicates reading registers; Number of bytes read is 106, corresponding to 3 registers or 6 bytes in total; Register data 1 is 1784, which is the content of memory at address 0116; Register data 2 is 1780, which is the content of memory at address 0117; Register data 3 is 178A, which is the content of memory at address 0118; CRC code is 25847, calculated by the slave. 2.4 Function code “05”: Writing to a digital output channel (“remote control”). Example 1: For the digital output point DO1, whose current status is “off”, the host wants to control that relay to be in the “on” state. The control command is: “FF00” to control the relay to close” ; “\"0000\" indicates the control relay is in the \"off\" state” ; Message format sent by the host: The host sends the number of bytes along with the information to be transmitted. Note: Data is sent from slave address 101 to slave address 01. Function code 105 is used to write the status of the digital output; bit 20000 corresponds to the BIT of the output relay (DO1). Control command 2FF00 is used to set the output of that relay to the \"on\" state. CRC code 28C3A is calculated by the host. Message format returned by the slave (PDM): It is exactly the same as the message format and data content sent by the host. Example 2: For the digital output point DO2, whose current status is “closed”, the host needs to control the relay associated with this point to be in the “open” state. Message format sent by the host: The host sends the number of bytes along with the information to be transmitted. Note: Data is sent from slave address 101 to slave address 01. Function code 105 is used to write the status of the digital output; bit 20001 corresponds to the BIT position of the output relay (DO2). Control command 20000 is used to set the output of that relay to the \"on\" state. CRC code 29C0A is calculated by the host. Message format returned by the slave (PDM): It is exactly the same as the message format and data content sent by the host. 2.5 Function code “06”: Write to a single-register. For example: The host wants to save the data 07D0 in the slave register at address 002C (the slave’s address code is 01). After the communication data is saved, the original information stored in the PDM table with address 002C is as follows: the original data stored at that address (in hexadecimal) is 002C04B0. The format of the message sent by the host is as follows: the number of bytes sent, along with an example of the data sent – from slave address 101 to slave address 01, function code 106 indicates writing to a single register; the starting address is 2002C, which is the address of the register to be written to, the data to be written is 207D0, and the corresponding new CRC code is 24BAF, which is calculated by the host. The format of the response message sent back by the slave (PDM) is exactly the same as that of the message sent by the host, including the data content. 2.6 Function code “10”: Write to multiple registers – The host uses this function code to save multiple pieces of data into the data memory of the PDM table. In the Modbus communication protocol, registers are 16 bits in size (i.e., 2 bytes), with the higher bits coming first. In this way, the memory of PDM is always two bytes. Since the Modbus communication protocol allows a maximum of 60 registers to be stored at a time, PDM also allows a maximum of 60 data registers to be stored at once. For example: The host wants to save 0064 and 0010 in the slave registers at addresses 002C and 002D (the slave address code is 01). After the communication data is saved, the information stored in the PDM table with addresses 002C/002D is as follows: The original data stored at that address (in hexadecimal) is 002C04B0002D1388. The format of the message sent by the host is as follows: Number of bytes sent, example of the data sent – Address of slave device 101 sending data to slave device 01; Function code 110, meaning writing to multiple registers; Starting address 2002C, which is the starting address of the register to be written to; Length of data to be saved 20002, meaning the length in words (2 words in total); Length of data in bytes 104, meaning the length in bytes (4 bytes in total); Data to be saved: 1204B0, with data address 002C; Data to be saved: 221388, with data address 002D. CRC code: 2FC63, which is the CRC code calculated by the host. The format of the response message sent back by the slave device (PDM) is as follows: Number of bytes in the response, example – Address of slave device 101, response from slave device 01; Function code 110, meaning writing to multiple registers; Starting address 2002C, i.e., the starting address is 002C; Length of data to be saved 20002, meaning the length of 2 words of data; CRC code 28001, which is the CRC code calculated by the slave device. III. Error checking code (CRC verification): Both the host and the slave device can use this checksum to determine whether the received information is correct. Due to electronic noise or other disturbances, errors can occur in the transmission of information. Error-checking codes (CRC) allow it to determine whether there are errors in the data transmitted between the host and the slave device; erroneous data can be discarded, whether it is sent or received, thereby enhancing the security and efficiency of the system. The CRC (Cyclic Redundancy Code) of the MODBUS communication protocol consists of 2 bytes, that is, 16 binary digits. The CRC code is calculated by the sending device (host) and placed at the end of the transmitted data frame. The device that receives the information (the slave) then recalculates the CRC of the received information, and checks whether the calculated CRC matches the one received. If they do not match, it indicates an error. Only 8 data bits are used in CRC calculation, namely the start bit and the stop bit; if there are parity bits, those as well are not included in the CRC calculation. ● The method for calculating CRC codes is as follows: 1. Initialize a 16-bit register with the hexadecimal valueFFFF (i.e., all 1s) ; Call this register the CRC register ; 2. XOR the first 8-bit binary data (i.e., the first byte of the communication message frame) with the lower 8 bits of the 16-bit CRC register, and place the result in the CRC register ; 3. Shift the contents of the CRC register one bit to the right (toward the lower bits), fill the highest bit with 0, and check the bit that is shifted out as a result ; 4. If the shifted-out bit is 0: Repeat step 3 (shift right again) ; If the shift-out bit is 1: The CRC register is XORed with the polynomial A001 (1010 0000 0000 0001) ; 5. Repeat steps 3 and 4 until it has been shifted right 8 times, so that all 8 bits of data have been processed ; 6. Repeat steps 2 to 5 to process the next byte of the communication message frame ; 7. After calculating all bytes of this communication message frame according to the steps above, swap the high and low bytes of the resulting 16-bit CRC register ; 8. The final content of the CRC register is the CRC code. IV. Handling of communication error messages and data: When the PDM module detects an error other than a CRC code error, it must send a message back to the host. The most significant bit of the function code is set to 1; in other words, the function code sent back by the slave to the host is the host’s function code plus 128. The following code indicates that an unexpected error has occurred. If the information received by the PDM from the host contains a CRC error, it will be ignored by the PDM table. The format of the error code returned by PDM is as follows (excluding the CRC code): Address code: 1 byte; Function code: 1 byte (with the most significant bit set to 1); Error code: 1 byte; CRC code: 2 bytes. PDM responds with the following error code: 81. Invalid function code. The received function code PDM table is not supported. 82. Illegal data location. The specified data location is outside the range of the PDM table. 83. Illegal data value. The data value sent by the host exceeds the data range of the corresponding address in PDM.

Submit a Project

**Looking for Chemical Technology, Equipment & Solutions?** No Registration Required Broader Platform Exposure | Global Chemical Service Provider Connections

Submit Request — Free Consultation

Disclaimer

This is an automated machine translation of the original thread. Some technical terms may have inaccuracies; the original text shall prevail. Click "View Original" at the top right to access the source page, which supports IP-based automatic real-time language translation. Please watch out for contact details and sales inducements to prevent fraud. All content and translations are for reference only, representing solely the poster's personal views. For enquiries, email service@hcbbs.com.