As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea.

2025/07/1623:16:36 technology 1224

This article is the basic article of modbusRTU problem. First, we talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea.

first list an introduction. The problem: plc is connected to the equipment on site, such as pump, level meter , blower and other equipment, and then plc connects dtu for 4G data transmission, cloud server accepts the data and displays and reverses the equipment data.

A brain map to understand the framework of modbus:

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews. Definition of Modbus

Modbus Communication Protocol: published by Modicon Corporation (now Schneider Electric Schneider Electric) in 1979 for programmable logic control (i.e. PLC) communication. At present, Modbus has become the industry standard for communication protocols in the industrial field, and is now a commonly used connection method between industrial electronic devices. Modbus is the most widely used protocol in the industrial field (for example: PLC).

Compared with other communication protocols modbus protocol features: free; simple; rich interfaces.

(1)Modbus protocol standard is open, publicly published and has no copyright requirements.

(2) Modbus protocol supports a variety of electrical interfaces, including RS232, RS485, TCP/IP, etc., and can also be transmitted on various media, such as twisted pair , optical fiber, infrared, wireless, etc.

(3) The Modbus protocol message frame format is simple, compact and easy to understand. Users are simple to understand and use, manufacturers are easy to develop and integrate, and convenient to form an industrial control network. The Modbus protocol is an application-layer message transmission protocol, including three message types: ASCII, RTU, and TCP. The protocol itself does not define the physical layer, but only defines the message structure that controller can recognize and use.

2. Modbus content

First understand two concepts: coil and register .

coil: From an electrical perspective, in the electrical circuit, the control is generally achieved by contactor or intermediate relay . The contactor or relay ultimately relies on the power gain and loss of the coil to control the contact closing and disconnection. Therefore, the coil is used to represent the boolean amount ;

register: is used to temporarily store the data and calculation results participating in the operation, and has the functions of receiving data, storing data and outputting data.

. The register in the computer is used to store data, so the data of is not Boolean is placed in the register.

is used to form modbus storage according to two types. Since there are read and write, there will be 4 different combinations. For the sake of convenience, the code is defined.

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

Since there are 4 storage areas, there are more combinations for reading and writing to the 4 storage areas. Since the input coil and input register can only be read, there are 6 cases in total. However, writing is divided into single write and multiple writes, so there are two more cases, so there are 8 cases (modbus core function code).

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews, Modbus protocol classification

Modbus protocol currently has three versions: Modbus RTU, Modbus ASCII, and Modbus TCP. Communication media: Including serial port and network port.

Before talking about the protocol, let’s talk about the relationship between bit (bit), byte (byte), and word (word) .

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

ASCII reference

The underlying computer is binary code, and it is necessary to convert it inconsistently, but hexadecimal is used more, and there is no need to use ten , because 16 is a multiple of 2, which is easier to express. The ASCII character set uses 8 bits, which can be represented by 2 hexadecimals. Currently, uses hexadecimal system on .

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNewsword=2byte=16bitml2

high eight bits, low eight bits in

memory, a unit is a byte, that is, 8 bits, and 16 bits instruction is to operate two consecutive memory addresses at the same time, treating these two consecutive memory addresses as one unit, so there are differences between high 8 bits and low 8 bits.

Since the computer only recognizes the numbers described in binary, for a memory address, that is, 8-bit binary, such as: 0000 0001, 0000 is the upper four digits, and 0001 is the lower four digits.

Why?

This problem does not exist for 8-bit processors, but this problem will exist when 16, 32, and 64 bits, and there will be a problem with which one is in front and which one is in the back.

Let’s talk about the modbus protocol below.

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

Modbus-TCP: consists of TCP header + address + PDU,

Modbus-RTU: consists of address + PDU + CRC verification

a: Modbus is a Q&A protocol. After sending a request, you have to wait for a reply before sending a second request.

b: The physical interface of Modbus-RTU is a serial port.

c: The physical interface of Modbus-TCP is Ethernet .

Modbus message is as follows:

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

Modbus communication is as follows:

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

[In the modbus protocol]

The host sends a modbus request, and the slave returns a response to the host according to the request content. In the modbus protocol, the host is always active, and the slave is always passive.

4. Modbus message parsing

Modbus protocol two communication modes exchange information: unicast mode and broadcast mode.

Whether it is a request message or a reply message, the data structure is as follows:

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

that is, the message (frame data) consists of four parts: address (Slave Number) + function code (Function Codes) + data (Data) + check (Check). The address in it represents the ID address of the slave device as addressing information. function code indicates what specific operation the current request performs, such as reading or writing. The data represents the service data that needs to be communicated and can be determined based on actual conditions. The last verification is to verify whether the data is incorrect. The function code description is as follows:

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

博:

a. Request: 01 03 00 00 00 02 C4 0B

01: Device address, device address is 1

03: Function code, currently 03 Read request

00 00: Register start address, read

00 from 00 register 02: Read register length, read 2 lengths, which means reading 2 registers, that is, 4 bytes.

C4 0B: CRC validity test sum

reply: 01 03 04 00 0C 00 02 BB F1

01: Device address, device address is 1

03: Function code, currently read reply

04: Data length, data containing 4 bytes

00 0C: Register 1 value

00 02: Register 2 value

BB F1: CRC validity test sum

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews3, 04 length is register.

Take reading packets as an example:

01, 02:

packet: 01 01 00 00 00 08 XX XX

Backpackage: 01 01 01 00 XX XX

Here 00 08 represents reading 8 bits, that is, one byte, so the data length of the backpackage is 01.

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews1, 02 length is bit.

reverse control:

As the basic article of the modbusrtu problem, this article will first talk about the modbus-related protocols, and then talk about how the problem is solved and what is the idea. - DayDayNews

technology Category Latest News