
When it comes to communication between industrial automation, sensors, and devices, the Modbus protocol typically appears in your toolbox. Modbus is a communication protocol used for reading and controlling device data, which has been widely used in industrial control systems. Now, let's explain how Modbus reads and holds register data in a way that is understandable to beginners, including the reading of single registers and multiple registers.
What isModbus?
ModbusIt is a communication protocol,Used to connect various industrial equipment、Sensors and controllers。It allows data exchange between these devices,To achieve monitoring、Control and Data Collection。ModbusThere are different variants of the protocol,includingModbus RTU、Modbus ASCII和Modbus TCP/IP,But they all follow similar principles。
What is a Keep Register?
在Modbusin communication,Data is usually stored in hold registers within the device。These registers can contain various information,Like temperature、Humidity、Current, etc。To read these data,We need to understand how to communicate with these holding registers。
Read a single hold register
When usingModbusAgreement fromModbusSlave(Device)When reading a single hold register,Need to specify the slave address、Function code and address for holding registers。Here is an example,How to read a single hold register will be demonstrated,Including slave address and completeModbus RTUProtocol Frame。
Example:
Assuming we need to obtain a slave address of 1ModbusThe read address in the device is0002Maintain the value of the register。The specific steps are as follows:
- First,We need to build aModbus RTUProtocol Frame,This frame includes the following content:
- slave address:1
- function code:03(Read and hold register)
- Starting register address:0002
- Number of registers read:0001
- CRCVerification(Cyclic redundancy check) After completion of construction,The protocol frame is shown below:
从机地址: 01 功能码: 03 寄存器地址: 00 02 寄存器数量: 00 01 CRC校验: [根据前面的数据计算得出]
- next,We will send the protocol frame toModbusSlave。After receiving the request, the slave will process it。
- Slave response request,And return the value of the hold register。The response includes:
- function code:03
- Number of data bytes:02(2bytes)
- register value:The high byte is02,The low byte is50
- CRCThe verification response packet is shown below:
功能码: 03 数据字节数: 02 寄存器值: 02 50 CRC校验: [根据前面的数据计算得出]
Through this example,We have successfully read the slave address 1ModbusDevice's hold register0002The value of,The value is0250。completeModbus RTUThe protocol frame covers the slave address、function code、register address、Number of data bytes andCRCVerification,These pieces of information areModbusAn important part of communication。Please note,CRCVerification is used to ensure the integrity of communication。
This example can help you understand how to use itModbusAgreement fromModbusRead the value of a single hold register from the machine,It also includes a complete protocol frame structure。I hope this is helpful to you。
Read multiple hold registers
When usingModbusAgreement fromModbusSlave(Device)When reading multiple hold registers,Need to specify the slave address、function code、Starting register address and number of registers to be read。Here is an example,How to read multiple hold registers will be demonstrated,Including slave address and completeModbus RTUProtocol Frame。
Example:
Assuming we need to obtain a slave address of 1ModbusRead from the address in the device0002The first three consecutive hold register values。The specific steps are as follows:
- First,We need to build aModbus RTUProtocol Frame,This frame includes the following content:
- slave address:1
- function code:03(Read and hold register)
- Starting register address:0002 从00 02 Start
- Number of registers read:0003 Read 3 quantities
- CRCVerification(Cyclic redundancy check) After completion of construction,The protocol frame is shown below:
从机地址: 01 功能码: 03 起始寄存器地址: 00 02 寄存器数量: 00 03 CRC校验: [根据前面的数据计算得出]
- next,We will send the protocol frame toModbusSlave。After receiving the request, the slave will process it。
- Slave response request,And return the values of multiple hold registers requested。The response includes:
- function code:03
- Number of data bytes:06(6bytes)
- register value:Each register occupies 2 bytes
- CRCThe verification response packet is shown below:
功能码: 03 数据字节数: 06 寄存器值: [高字节低字节,高字节低字节,高字节低字节] CRC校验: [根据前面的数据计算得出]
for example,The value of the first register is:0x0250,The value of the second register is:0x03E8,The value of the third register is:0x000A。
Through this example,We have successfully read the slave address 1ModbusDevice's slave register0002The first three consecutive hold register values。completeModbus RTUThe protocol frame covers the slave address、function code、Starting register address、Number of data bytes andCRCVerification,These pieces of information areModbusAn important part of communication。I hope this is helpful to you,At the same time, understand how to use itModbusAgreement fromModbusRead multiple consecutive hold register values from the machine。
Summary
These examples helped us understand how to useModbusProtocol to read data from single and multiple hold registers。Please note,actualModbusCommunication may involve more details and configurations,But this simple explanation can help beginners understandModbusThe basic principle of。
in short,ModbusIt is a powerful communication protocol,Suitable for industrial automation and equipment control。It enables various devices to communicate with each other,Implement data collection and control operations。I hope this beginner's understanding of the introduction can help you better comprehendModbusProtocol read operation。
Leave a Reply