Introduction to Modbus protocol

Source: Internet
Author: User
Tags time interval


I. Introduction of Modbus protocol

Modbus protocol is a common language used in electronic controller. With this protocol, controllers can communicate between each other, the controller through the network (for example, Ethernet) and other devices. It has become a general industry standard. With it, the control equipment produced by different manufacturers can be connected to an industrial network for centralized monitoring.

This protocol defines the message structures that a controller can recognize, regardless of what network they are communicating with. It describes the process by which a controller requests access to other devices, if it responds to requests from other devices, and how to detect errors and log them. It develops a common format for message domain patterns and content.

When communicating on a Modbus network, this protocol determines which device addresses each controller needs to know, identifies messages sent by address, and determines what action to take. If a response is required, the controller generates feedback and is sent out using the Modbus protocol. On other networks, messages that contain the Modbus protocol are converted to frames or packet structures used on this network. This transformation also extends the method of addressing the node address, routing path, and error detection based on the specific network.

1, transfer on the Modbus network

The standard Modbus port is a RS-232C compatible serial interface that defines the PIN, cable, signal bit, transmit baud rate, and parity of the connection port. The controller can be directly or via modem networking.

Controller communication uses master-slave technology, which means that only one device (the primary device) can initialize the transmission (query). Other devices (from the device) respond accordingly to the data provided by the main device query. Typical main device: host and programmable meter. Typical slave device: Programmable controller.

The master device can communicate independently and from the device, as well as broadcast and all slave devices. If a message is returned from the device in response to a separate communication, no response will be made if it is queried in a broadcast manner. The Modbus protocol establishes the format of the main device query: The device (or broadcast) address, the function code, all data to be sent, and an error detection domain.

The response message from the device is also composed of the Modbus protocol, which includes confirming the domain to be acted on, any data to be returned, and an error detection domain. If an error occurs during message reception, or if the device cannot execute its command, the slave will establish an error message and send it as a response.

2. Transfer on other types of networks

On other networks, the controller communicates with peers, so any control can initially communicate with other controllers. In this way, the controller can be used as a slave device as well as a master device in a separate communication process. Multiple internal channels are provided to allow simultaneous transmission processes.

In the message bit, the Modbus protocol still provides the master-slave principle, although the network communication method is "peering". If a controller sends a message, it simply acts as the primary device and expects to get a response from the device. Similarly, when the controller receives a message, it will establish a response format from the device and return it to the sending controller.

3. Query-Response Period

(1) Enquiry

The function code in the query message tells you which function to perform from the device that is selected. The data segment contains any additional information from the device to perform the function. For example, function code 03 is required to read the hold registers from the device and return their contents. The data segment must contain information to be told from the device: from which register to read and the number of registers to read. The error detection domain provides a way for the slave device to verify that the message content is correct.

(2) Response

If a normal response is generated from the device, the function code in the response message is the response to the function code in the query message. The data segment includes data collected from the device: like a register value or status. If an error occurs, the function code is modified to indicate that the response message is incorrect, and the data segment contains the code that describes the error message. The error detection domain allows the primary device to confirm that the message content is available.

two modes of transmission

The controller can be set to two modes of transmission (ASCII or RTU) in any one of the standard Modbus network communications. Users choose the desired mode, including serial communication parameters (baud rate, check mode, etc.), in the configuration of each controller, all devices on a Modbus network must choose the same transmission mode and serial port parameters.

ASCII mode

:

Address

function code

Number of data

Data 1

...

Data n

LRC High-byte

LRC Low byte

Enter

Line break

RTU mode

Address

function code

Number of data

Data 1

...

Data n

CRC Low Byte

CRC High Byte

The selected ASCII or RTU mode only applies to the standard Modbus network, which defines each bit of the message segment that is continuously transmitted on those networks, and determines how the information is packaged into a message domain and how it is decoded.

Modbus messages on other networks (like map and Modbus Plus) are transferred to frames unrelated to the serial transfer.

1. ASCII mode

When the controller is set to communicate in ASCII (US standard Information Interchange Code) mode on the Modbus network, each 8Bit byte in the message is sent as two ASCII characters. The main advantage of this approach is that the character can be sent at a time interval of 1 seconds without generating an error.

Code system hex, ASCII character 0 ... 9,a ... Each ASCII character in the F message is made up of a hexadecimal character

Bits per byte 1 starting bit 7 data bits, the smallest significant bit first sends 1 parity bits, no check is not a stop bit (with check), 2 bit (no check)

Error detection Domain

· LRC (longitudinal lengthy inspection)

2. RTU mode

When the controller is set to communicate in RTU (remote terminal Unit) mode on the Modbus network, each 8Bit byte in the message contains two hexadecimal characters of 4Bit. The main advantage of this approach is that, at the same baud rate, more data can be transmitted than the ASCII method.

Code system 8-bit binary, hexadecimal number 0 ... 9,a ... Each 8-bit field in the F message is a two-hexadecimal character that consists of a bit of 1 starting bits of each byte, 8 data bits, and the smallest significant bit sends 1 parity bits first, no check without a stop bit (with checksum), 2 bit (no check)

Error detection domain CRC (cyclic verbose detection)

three, Modbus message frame

In either transmission mode (ASCII or RTU), the transmission device is transferred to a frame with a start and end point, which allows the receiving device to start working at the beginning of the message, read the address assignment information, determine which device is selected (broadcast to all devices), and decide when the information is complete. Part of the message can also be detected and the error can be set to return the result.

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.