- Table of Contents
- Related Documents
-
Title | Size | Download |
---|---|---|
01-Modbus configuration | 203.49 KB |
Restrictions and guidelines: Modbus relay configuration
Modbus relay tasks at a glance
Configuring operating parameters of an RS485 serial interface
Enabling Modbus and specifying the Modbus mode
Configuring an RS485 serial interface to establish a TCP connection with a Modbus client
Configuring an RS485 serial interface to establish a UDP connection with a Modbus client
Restoring the default settings for an RS485 serial interface
Display and maintenance commands for Modbus
Configuring Modbus
About Modbus
Modbus is an open, standardized, easy-to-use, and reliable communication protocol in the industrial field. It enables client/server communication between devices connected to different types of buses or networks, suitable for automation control scenarios. Currently, the Modbus protocol is widely used for communication among various control devices in automation control systems, instruments, robot control, and mobile device control. Modbus holds a significant position especially in smart manufacturing and industrial internet fields.
Benefits
Modbus provides the following benefits:
· The Modbus protocol standards are openly available, allowing for data exchange between devices from different manufacturers.
· Modbus, an application layer protocol, defines message structures that can be understood and used by industrial controllers and does not define the physical layer, enabling data transmission within various network architectures. Modbus not only supports multiple electrical interfaces such as RS485 and TCP/IP, but also transmits data through various media including twisted pair cables and optical fibers.
· The Modbus protocol has a simple and easy-to-understand message format, which facilitates user understanding and usage, as well as development and integration by manufacturers in industrial control networks.
Modbus network model
Modbus communication layer
Modbus supports deployment on a serial link or an Ethernet TCP/IP network. It utilizes network layers for communication in different networks as shown in Figure 1.
Figure 1 Modbus communication layer
Modbus communication mechanism
As shown in Figure 2, Modbus uses a client/server structure. In Modbus communication, only the client sends requests, and the server responds to the requests. Data is transmitted between the client and server over Modbus. On an industrial control network, PLC devices typically act as clients, and peripheral I/O sensors, valves, network drives, or other measuring devices act as servers.
Modbus transmission messages
Modbus has two types of transmission messages, Modbus-RTU messages and Modbus-TCP messages.
Modbus-RTU messages
In Modbus-RTU transmission mode, the format of the Application Data Unit (ADU) uses the structure, as shown in Figure 3.
The fields in the Modbus-RTU ADU structure are as follows:
· Server address—Address of the server, which is the target of the Modbus request sent by the client. The address length is one byte.
· Function code—Instruction sent by the client to the server, such as reading/writing data from the server. The instruction length is one byte.
· Function-specific data—Describes the content of a specific request or response instruction based on different function codes. The data length varies.
· Error checking—Checks the correctness of the received data to avoid errors during message transmission. The filed length is two bytes.
Modbus-TCP messages
In Modbus-TCP transmission mode, the format of the Application Data Unit (ADU) uses the structure, as shown in Figure 4.
Different from Modbus messages transmitted over a serial link, the Modbus-TCP ADU does not require an error checking field, as the TCP/UDP protocols inherently provide error checking capabilities. In addition, the Modbus-TCP ADU no longer needs an address field; and addressing is achieved via encapsulation through the network and data link layers on the Ethernet network. To distinguish Modbus messages on the Ethernet network, a Modbus Application Header (MBAP) is encapsulated onto the PDU of the Modbus-TCP ADU. The fields in the Modbus-TCP ADU are as follows:
· Transaction identifier—Identifies the transaction of the Modbus request or response. The field length is two bytes.
· Protocol identifier—Value 0 identifies the Modbus protocol. The field length one byte.
· Length identifier—Identifies the subsequent field length. The field length is two bytes.
· Unit identifier—Used for system internal routing, identifying the remote servers connected via serial links or other buses, The field length is one byte.
· Function code—Instruction sent by the client to the server, such as reading/writing data from the server. The instruction length is one byte.
· Function-specific data—Describes the content of a specific request or response instruction based on different function codes. The data length varies.
Modbus relay
About Modbus relay
Typically, a Modbus client resides on the Ethernet network and sends Modbus-TCP messages. Modbus servers are connected via serial links and can identify only Modbus-RTU messages. As a result, the Modbus client cannot directly communicate with the Modbus servers. An H3C industrial switch acts as a relay gateway, enabling Modbus messages to be successfully exchanged between the client and servers, as shown in Figure 5.
Operating mechanism of the Modbus relay gateway
On a Modbus network, an H3C industrial switch physically connects to a Modbus client via an Ethernet interface and to Modbus servers via an RS485 serial interface. The switch must establish a TCP or UDP connection with the Modbus client so that the Ethernet TCP/IP network can carry Modbus messages. The switch also uses an RS485 serial interface to support the Modbus protocol. The RS485 serial interface enables the switch to establish a TCP or UDP connection and Ethernet communication with the Modbus client and serial communication with the Modbus servers.
An RS485 serial interface supports the following forwarding modes:
· Transparent mode—Typically, a Modbus client sends Modbus-TCP messages. However, a high-performance Modbus client can directly generate Modbus-RTU messages when it detects that a Modbus server supports only Modbus-RTU messages. The Modbus client then sends Modbus-RTU messages to the H3C industrial switch via the TCP/IP Ethernet path, as shown in Figure 6.
In transparent mode, an RS485 serial interface on the H3C industrial switch transparently transmits Modbus-RTU messages between the Modbus client and Modbus servers.
Figure 6 Transparent mode of the relay gateway
· Agent mode—An RS485 serial interface on the H3C industrial switch converts the Modbus-TCP messages received from a Modbus client to Modbus-RTU messages, and then forwards the converted messages to Modbus servers. The switch changes the Modbus-RTU messages received from a Modbus server to Modbus-TCP messages, and then forwards the converted messages to the Modbus client, as shown in Figure 7.
Figure 7 Agent mode of the relay gateway
The correspondence between the forwarding mode and the transport layer connection established for RS485 serial interfaces is as listed in Table 1.
Forwarding mode |
Transport layer connection to be established |
Transparent mode |
As Modbus-RTU messages have no requirements for the transport layer protocol on the Ethernet network, an RS485 serial interface can establish both TCP and UDP connections with the client. In addition, the RS485 serial interface can act as either the client or server during the establishment of TCP and UDP connections. |
Agent mode |
The Modbus-TCP protocol supports only TCP, so an RS485 serial interface must establish a TCP connection with the client, and must act as the TCP server. |
Restrictions and guidelines: Modbus relay configuration
The device in IRF mode does not support Modbus.
Modbus relay tasks at a glance
To configure Modbus relay, perform the following tasks:
1. Configuring operating parameters of an RS485 serial interface
2. Enabling Modbus and specifying the Modbus mode
3. Configure an RS485 serial interface to establish a TCP or UDP connection with the client
¡ Configuring an RS485 serial interface to establish a TCP connection with a Modbus client
¡ Configuring an RS485 serial interface to establish a UDP connection with a Modbus client
Only one type of connection can be configured for an RS485 serial interface. You can repeat the steps on multiple RS485 serial ports to establish multiple connections.
4. (Optional.) Optimizing Modbus performance
5. Restoring the default settings for an RS485 serial interface
Configuring operating parameters of an RS485 serial interface
About RS485 serial interfaces
An industrial switch acts as a relay device for Modbus protocol communication between the client and servers. The switch establishes a physical connection with a Modbus server via an RS485 serial interface. To ensure connectivity of RS485 links, make sure the parameters of the RS485 serial interface matches those for the industrial switch.
Procedure
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. Configure the description for the RS485 serial interface.
description text
By default, the description for an interface is interface name Interface (for example, UART1/0/1 Interface).
4. Configure the flow control mode.
flow-control none
By default, no flow control mode is configured for an RS485 serial interface.
5. Set the baud rate.
baudrate baudrate-value
By default, the baud rate is 9600 bps.
6. Specify the number of data bits
databits 8
By default, the number of data bits is 8.
7. Specify the number of stop bits.
stopbits 1
By default, the number of stop bits for an RS485 serial interface is 1.
8. Specify the parity.
parity none
By default, the setting is none. No parity is used.
Enabling Modbus and specifying the Modbus mode
About this task
After you specify the forwarding mode for an RS485 serial interface, Modbus on this interface is enabled.
Restrictions and guidelines
You cannot edit the forwarding mode for an RS485 serial interface by repeating the modbus mode command. To edit the forwarding mode, execute the undo modbus mode command to remove the forwarding mode configuration, and then execute the modbus mode command to reconfigure the forwarding mode.
Executing the undo modbus mode command will restore the Modbus configuration to the factory defaults, which might cause a Modbus communication interruption.
Procedure
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. Enable Modbus and specify a forwarding mode for the RS485 serial interface and enter the corresponding Modbus mode view.
¡ Specify the agent mode for the RS485 serial interface and enter the Modbus agent mode view.
modbus mode agent
¡ Specify the transparent mode for the RS485 serial interface and enter the Modbus transparent mode view.
modbus mode raw
By default, no forwarding mode is specified for an RS485 serial interface. This indicates that the RS485 serial interface is disabled with Modbus and cannot process Modbus messages.
Configuring an RS485 serial interface to establish a TCP connection with a Modbus client
About this task
In agent mode, an H3C industrial switch acts as a Modbus server for a Modbus client and needs to receive Modbus-TCP messages from the client. Then, a TCP server connection is required. In transparent mode, an RS485 serial interface on an H3C industrial switch can act as a TCP server or TCP client to establish a TCP connection with a Modbus client for reliable transparent transmission of Modbus-RTU messages.
You can execute the modbus packet-size command to edit the minimum length of TCP packets that an RS485 serial interface sends to a Modbus client, accommodating various network environments. Increasing the minimum length enables multiple messages to be encapsulated into one TCP packet, which reduces system resource consumption caused by multiple packet encapsulations.
Restrictions and guidelines
You can configure this feature multiple times to configure an RS485 interface as a TCP client to establish TCP connections with a maximum of four Modbus clients. Do not specify TCP or UDP servers that have the same IP address for different RS485 serial interfaces on the device.
The tcp client, tcp server, udp client, and udp server commands are mutually exclusive. Do not execute two or more of these commands in the same view.
To ensure correct operation of Modbus and other services, specify an unused port number.
Configuring an RS485 serial interface as a TCP server to establish a TCP connection with a Modbus client
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. (Optional.) Set the minimum length of TCP packets that an RS485 serial interface sends to a Modbus client.
modbus packet-size size
By default, the minimum length of TCP packets that an RS485 serial interface sends to a Modbus client is not configured. The TCP packet length varies by actual data size.
4. Enter the Modbus transparent mode view or Modbus agent mode view.
modbus mode { agent | raw }
5. Configure an RS485 serial interface as a TCP server to establish a TCP connection with a Modbus client (TCP client).
tcp server [ server-port server-port ] [ vpn-instance vpn-instance-name ]
By default, no role is configured for an RS485 serial interface in establishing a transport layer connection. The interface does not establish any connection with a Modbus client at the transport layer.
Configuring an RS485 serial interface as a TCP client to establish a TCP connection with a Modbus client
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. (Optional.) Set the minimum length of TCP packets that an RS485 serial interface sends to a Modbus client.
modbus packet-size size
By default, the minimum length of TCP packets that an RS485 serial interface sends to a Modbus client is not configured. The TCP packet length varies by actual data size.
4. Enter the Modbus transparent view.
modbus mode raw
5. Configure an RS485 serial interface as a TCP client to establish a TCP connection with a Modbus client (TCP server).
tcp client server-ip server-ip server-port server-port [ vpn-instance vpn-instance-name ]
By default, no role is configured for an RS485 serial interface in establishing a transport layer connection. The interface does not establish any connection with a Modbus client at the transport layer.
Configuring an RS485 serial interface to establish a UDP connection with a Modbus client
About this task
The Modbus-TCP transmission mode depends on the TCP protocol. During the establishment of a UDP connection between an RS485 serial interface and a Modbus client, only transparent mode can be used to transmit Modbus-RTU messages. Establishing a UDP connection is efficient in message transmission.
Restrictions and guidelines
You can configure this feature multiple times to configure an RS485 serial interface to establish UDP connections with a maximum of four Modbus clients. Do not specify TCP or UDP servers that have the same IP addresses for different RS485 serial interfaces on the device.
The tcp client, tcp server, udp client, and udp server commands are mutually exclusive. Do not execute two or more of these commands in the same view.
To ensure correct operation of Modbus and other services, specify an unused port number.
Configuring an RS485 serial interface as a UDP server to establish a UDP connection with a Modbus client
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. Enter the Modbus transparent view.
modbus mode raw
4. Configure an RS485 serial interface as a UDP server to establish a UDP connection with a Modbus client (UDP client)
udp server [ server-port server-port ] [ vpn-instance vpn-instance-name ]
By default, no role is configured for an RS485 serial interface in establishing a transport layer connection. The interface does not establish any connection with a Modbus client at the transport layer.
Configuring an RS485 serial interface as a UDP client to establish a UDP connection with a Modbus client
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. Enter the Modbus transparent view.
modbus mode raw
4. Configure an RS485 serial interface as a UDP client to establish a UDP connection with a Modbus client (UDP server).
udp client server-ip server-ip server-port server-port [ local-port local-port ] [ vpn-instance vpn-instance-name ]
By default, no role is configured for an RS485 serial interface in establishing a transport layer connection. The interface does not establish any connection with a Modbus client at the transport layer.
Optimizing Modbus performance
Configuring minimum interval for an RS485 serial interface to send Modbus-RTU messages to a Modbus server
About this task
Modbus servers vary in type and their ability to process Modbus-RTU messages also differs. For low-performance Modbus servers, set a long Modbus-RTU message sending interval to avoid packet congestion. For high-performance Modbus servers, set a short Modbus-RTU message sending interval to accelerate the speed at which a Modbus client receives responses.
Procedure
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. Configure the minimum interval for the RS485 serial interface to send Modbus-RTU messages to a Modbus server.
modbus packet-time interval
By default, an RS485 serial interface sends Modbus-RTU messages to a Modbus server at least every 100 milliseconds.
Restoring the default settings for an RS485 serial interface
Restrictions and guidelines
CAUTION: The default command might interrupt ongoing network services. Make sure you are fully aware of the impact of this command when you use it on a live network. |
This feature might fail to restore the default settings for some commands because of command dependencies or system restrictions. You can use the display this command in interface view to identify these commands, and use their undo forms or follow the Modbus command reference to restore their default settings. If your restoration attempt still fails, follow the error message instructions to solve the problem.
Procedure
1. Enter system view.
system-view
2. Enter RS485 serial interface view.
interface uart interface-number
3. Restore the default settings for the RS485 serial interface.
default
Display and maintenance commands for Modbus
Execute display commands in any view.
Task |
Command |
Display information about RS485 serial interfaces. |
display interface [ uart [ interface-number ] ] [ brief [ description ] ] |
Display TCP sessions for an RS485 serial interface. |
display modbus session [ interface interface-type interface-number ] |