Originally developed by Modicon, the Modbus protocol is an application-layer bus device protocol based on serial bus-based master-slave mode for plc devices. ModbusTCP is a Modbus protocol encapsulated in a TCP packet. Although there are some changes, it is basically a master-slave mode.
With the development of embedded technology, the control and acquisition units of many domestic systems are independently developed by the company. It is generally recommended that the serial communication protocols of these companies adopt the Modbus protocol. Many users have misunderstandings in the modbus protocol. The analysis is as follows:
First, the modbus keep and input registers are in word (16bit).
For example, 4**** (hold register/output register) and 3**** (input register) are in words. Therefore, if you read a 16-bit unsigned number starting with the 40001 register, then return 2 Bytes, and you can read the next 16-bit unsigned number starting from 40002.
However, if you read a 32-bit floating point number starting with the 40001 register, then 4 Bytes are returned, and the next 32-bit floating point number must start at 40003.
common problem:
1), define 40001 as a Byte of data;
2) Define 40001 as a 32-bit floating point number and 40002 as the next 32-bit floating point number.
Second, the minimum address of the register is 1, and the start address of the message is 0.
In the data message, all modbus addresses start at 0. That is, the first occurrence of the data item is 0 in the message. such as:
1. In the controller, "coil 1" has an address of 00 00 in the address field of the Modbus message.
2. The hexadecimal message address of coil 127 is 007E hex (126 in decimal)
3. Keep the register address of register 40001 at 00 00. Because the message function code explicitly operates the "hold register", the protocol represents this register with "4XXXX".
4. Keep the register address of register 40108 006B hex (decimal 107)
In summary, the Modbus address generally refers to 4**** (hold register / output register) and 3**** (input register), at this time the application level:
For example, the device manual can briefly describe the device supporting the Modbus RTU standard protocol, and describe its address correspondence in detail: 40001 -- analog acquisition channel 1, 16-bit signed number, ..... For example, the address setting of the configuration software is generally the output register, starting from address 1, and how many consecutive. Or specify 400001: 16-bit signed number. However, at the data message level, the register start address starts at 0.
The data message includes: device address + function code + start address + number of registers + check digit. Among them, the starting address is starting from 0.
For example: the message device address of the two register data starting from 40001 is read from device 17 Function code Start address register number check 11 03 00 00 00 02 --
common problem:
1. Use and define 40000 addresses;
2. When analyzing the message, directly regard the start address of the message as the application layer register address.
3. Modbus write register commands are different.
Commonly used Modbus registers are: Coil, Input, Holding Registers, and Input Registers.
From the perspective of the Modbus device, the input is the information of the host computer to collect the Modbus device, that is, these registers are read-only, so the Modbus protocol does not have the commands to write input (Input) and input registers (Input Registers).
The coil (Coil) is the state quantity corresponding to the digital output (DO) of the Modbus device. The holding registers (Holding Registers) are analog quantities, corresponding to the analog output (AO) of the Modbus device. These registers need to be set by the host computer of the Modbus device. That is, a register that can be written.
In the Modicon_Modbus protocol, both the write coil (Coil) and the holding register (Holding Registers) have two write commands:
1) Write a single register:
Force Single Coil Function Code 05 (0x05)
Write a single register (Preset Single Holding Register) function code 06 (0x06)
2) Write multiple registers to write multiple coils (Force Multiple Coils) function code 15 (0x0F)
Write multiple registers (Preset Multiple Registers) function code 16 (0x10)
Leather Phone Case,Wallet Phone Case,Bullstrap Iphone Case,Leather Phone Holster
Guangzhou Jiaqi International Trade Co., Ltd , https://www.make-case.com