- Table of Contents
- Related Documents
-
Title | Size | Download |
---|---|---|
01-Modbus commands | 156.35 KB |
Modbus commands
This feature is not supported in an IRF fabric.
Modbus commands
display modbus-tcp information interface
Use display modbus-tcp information interface to display information required for the device to read local port data by using the Modbus-TCP protocol.
Syntax
display modbus-tcp information interface { interface-type interface-number | interface-name }
Views
Any view
Predefined user roles
network-admin
network-operator
Parameters
interface { interface-type interface-number | interface-name }: Specifies an interface by its interface type, interface number, and interface name.
Usage guidelines
Application scenarios
A Modbus-TCP PDU contains a function code and data, representing the action to be executed and the object of the action, respectively. If a Modbus client needs to read port information from a local device, it must send a Modbus-TCP message that contains the function code and the register address. If the Modbus client cannot obtain the port's register address, you can execute this command to view the corresponding hardware address. This enables the Modbus client to send commands to obtain detailed port information from the local device by using that address.
Restrictions and guidelines
You can execute this command only after you execute the modbus-tcp enable command.
Examples
# Display information required for the device to read information about GigabitEthernet 1/0/1 by using the Modbus-TCP protocol.
<Sysname> display modbus-tcp information interface gigabitethernet 1/0/1
Interface name: GigabitEthernet1/0/1
Port ID: 1
Table/IfBaseInfo Start-Reg-Address: 0x1000
Table/IfAlarm Start-Reg-Address: 0x3000
Table 1 Command output
Field |
Description |
Port ID |
Port ID, which is used to calculate the start address of port data. The start address of information Y for port X=start address of information Y + Y data length for each port x (port ID-1). |
Table/IfBaseInfo Start-Reg-Address |
Start address of the base information for the specified port. |
Table/IfBaseInfo Start-Reg-Address |
Start address of alarm information for the specified port. |
modbus-tcp enable
Use modbus-tcp enable to enable Modbus-TCP for the device.
Use undo modbus-tcp enable to disable Modbus-TCP for the device.
Syntax
modbus-tcp enable
undo modbus-tcp enable
Default
Modbus-TCP is disabled for the device.
Views
System view
Predefined user roles
network-admin
Usage guidelines
Application scenarios
In automated industrial Ethernet scenarios, when a control device (Modbus client) manages a Modbus server by using Modbus-TCP, the Modbus server must also support Modbus-TCP for communication. When an H3C device acts as a Modbus server, you must execute this command to enable Modbus-TCP for the H3C device to recognize Modbus-TCP protocol messages from the Modbus client, process them accordingly, and report its information or change its state.
Operating mechanism
With this command configured, an H3C device uses port 502 to listen to Modbus-TCP messages from Modbus clients. A Modbus client can establish a TCP connection to the H3C device and exchange Modbus protocol messages through TCP.
Restrictions and guidelines
H3C industrial switches can enable or disable a port and obtain port and alarm information through Modbus-TCP. They can read and edit information about a maximum of 128 ports.
Examples
Enable Modbus-TCP for the device.
<Sysname> system-view
[Sysname] modbus-tcp enable
modbus-tcp working-mode read-only
Use modbus-tcp working-mode read-only to set the operating mode for Modbus-TCP to read only.
Use undo modbus-tcp working-mode read-only to restore the default.
Syntax
modbus-tcp working-mode read-only
undo modbus-tcp working-mode read-only
Default
Modbus-TCP operates in read write mode. The device can read its information and edit its status.
Views
System view
Predefined user roles
network-admin
Usage guidelines
By default, a Modbus client can read and write information from H3C devices through Modbus-TCP. Changing the device status without permission can pose a severe security risk. To address this issue, you can execute this command to set the operating mode of Modbus-TCP on H3C devices to read only, allowing Modbus clients to only read information from H3C devices through Modbus-TCP.
Make sure Modbus-TCP is enabled for the device.
Examples
# Set the operating mode of Modbus-TCP to read only.
<Sysname> system-view
[Sysname] modbus-tcp working-mode read-only
Related commands
modbus-tcp enable
Modbus relay commands
baudrate
Use baudrate to set the baud rate for an RS485 serial interface.
Use undo baudrate to restore the default.
Syntax
baudrate baudrate-value
undo baudrate
Default
The baud rate of an RS485 interface is 9600 bps.
Views
RS485 serial interface view
Predefined user roles
network-admin
Usage guidelines
baudrate-value: Specifies the baud rate in bps. The baud rate of an RS485 serial interface can be 2400 bps, 9600 bps, 19200 bps, 38400 bps, 57600 bps, or 115200 bps. Set the baud rate based on the Modbus servers that the RS485 serial interface communicates with.
Examples
# Set the baud rate to 19200 bps for RS485 serial interface UART 1/0/1.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] baudrate 19200
databits
Use databits to specify the number of data bits for an RS485 serial interface.
Use undo databits to restore the default.
Syntax
databits 8
undo databits
Default
The number of data bits for an RS485 serial interface is 8.
Views
RS485 serial interface view
Predefined user roles
network-admin
Usage guidelines
8: Uses eight data bits for a character.
Examples
# Set the number of data bits to 8 for RS485 serial interface UART 1/0/1.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] databits 8
default
Use default to restore the default settings for an RS485 serial interface.
Syntax
default
Views
RS485 serial interface view
Predefined user roles
network-admin
Usage 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 command 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 command reference to restore their default settings. If your restoration attempt still fails, follow the error message instructions to solve the problem.
Examples
# Restore the default settings for RS485 serial interface UART 1/0/1.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] default
description
Use description to configure the description of an RS485 serial interface.
Use undo description to restore the default.
Syntax
description text
undo description
Default
The description of an interface is the interface name plus Interface (for example, Serial2/1/0 Interface).
Views
RS485 serial interface view
Predefined user roles
network-admin
Parameters
text: Specifies the interface description, a case-sensitive string of 1 to 255 characters.
Examples
# Set the description of RS485 serial interface UART 1/0/1 to uart-interface.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] description uart-interface
display interface uart
Use display interface uart to display information about RS485 serial interfaces.
Syntax
display interface uart [ interface-number ] [ brief [ description ] ]
Views
Any view
Predefined user roles
network-admin
network-operator
Parameters
interface-number: Specifies an RS485 serial interface number. If you do not specify this argument, the command displays information about all created RS485 serial interfaces.
brief: Displays brief interface information. If you do not specify this keyword, the command displays detailed interface information.
description: Displays complete interface descriptions. If you do not specify this keyword, the command displays only the first 27 characters of each interface description.
Examples
# Display information about RS485 serial interface UART 1/0/1.
<Sysname> display interface uart 1/0/1
UART1/0/1
Current state: UP
Line protocol state: UP
Description: UART1/0/1 Interface
Bandwidth: 9 kbps
Maximum transmission unit: 1500
Internet protocol processing: Disabled
Last link flapping: Never
Current system time:2023-04-06 14:39:38
Baud rate: 9600
Flow-control: none
Data bits : 8
Stop bits : 1
Parity : none
Table 2 Command output
Field |
Description |
Current state |
Physical state and management state of the interface. This field displays two hyphens (--) if it is not supported. |
Line protocol state |
Data link layer state of the interface. This field displays two hyphens (--) if it is not supported. |
Description |
Description of the interface. |
Bandwidth |
Expected bandwidth of the interface. |
Maximum transmission unit |
MTU of the interface. |
Internet protocol processing: Disabled |
The interface cannot process IP packets. |
Last link flapping |
The amount of time that has elapsed since the most recent physical state change of the interface. This field displays Never if the interface has been physically down since device startup. |
Current system time |
Current system time. |
Baud rate |
Baud rate of the interface: · 2400 bps. · 9600 bps. · 19200 bps. · 38400 bps. · 57600 bps. · 115200 bps. |
Flow-control |
Flow control mode of the interface. The value is None, which indicates no flow control. |
Data bits |
Number of data bits for the interface. The value is 8, which indicates eight data bits for a character. |
Stop bits |
Number of stop bits for the interface: · 1—One stop bit for a character. · 2—Two stop bits for a character. |
Parity |
Parity of the interface. The value is None, which indiates no parity. |
display modbus session
Use display modbus session to display TCP sessions for an RS485 serial interface.
Syntax
display modbus session [ interface interface-type interface-number ]
Views
Any view
Predefined user roles
network-admin
network-operator
Parameters
interface interface-type interface-number: Specifies an interface by its type and number. If you do not specify an interface, the command displays TCP sessions for all RS485 serial interfaces.
Examples
# Display TCP sessions for all RS485 serial interfaces.
<Sysname> display modbus session
Interface : Uart 1/0/1
Forwarding mode : agent
Connection mode : TCP Server
Server port : 502
Total packets sent : 8398
Total packets received: 8404
Total clients : 3
Client info :
Client address : 22.2.2.2
Client port : 6654
Server address : 22.2.2.1
Server port : 502
Connect time : 2022/10/22 17:55:45
Packet send : 3655
Packet received : 3655
Client address : 22.2.2.8
Client port : 6654
Server address : 22.2.2.1
Server port : 502
Connect time : 2022/10/22 18:45:01
Packet send : 2755
Packet received : 2760
Client address : 22.2.2.16
Client port : 6654
Server address : 22.2.2.1
Server port : 502
Connect time : 2022/10/22 19:31:38
Packet send : 1988
Packet received : 1989
Interface : Uart 1/0/2
Forwarding mode : raw
Connection mode : TCP Client
Total packets sent : 5340
Total packets received: 5340
Total servers : 2
Server info :
Server address : 55.1.1.2
Server port : 502
Client address : 55.1.1.1
Client port : 1788
Connect time : 2022/10/22 17:55:45
Packet send : 3655
Packet received : 3655
Server address : 55.1.1.35
Server port : 2788
Client address : 55.1.1.1
Client port : 1788
Connect time : 2022/10/22 20:21:45
Packet send : 1685
Packet received : 1685
Table 3 Command output
Field |
Description |
Interface |
Name of an RS485 serial interface. |
Forwarding mode |
Forwarding mode of the RS485 serial interface: · raw—Transparent mode. · agent—Agent mode. |
Connection mode |
Role of the RS485 serial interface: · TCP Server—The RS485 serial interface acts as a TCP server to establish TCP connections with Modbus clients. · TCP Client—The RS485 serial interface acts as a TCP client to establish TCP connections with Modbus clients. |
Server port |
Port number of the TCP server. |
Client port |
Port number of the TCP client. |
Total packets sent |
Total number of data packets sent by the RS485 serial interface through the TCP connections. |
Total packets received |
Total number of data packets received by the RS485 serial interface through the TCP connections. |
Total clients |
Number of TCP clients that establish TCP connections with the local RS485 serial interface. |
Client info |
TCP client information. |
Client address |
IP address of the TCP client. |
Connect time |
Time when the TCP connection was established with the TCP client. |
Packet send |
Number of data packets sent from the local RS485 serial interface to the TCP client or server. |
Packet received |
Number of data packets received by the RS485 serial interface from the TCP client or server. |
Total servers |
Number of TCP servers that establish TCP connections with the local RS485 serial interface. |
Server info |
TCP server information. |
Server address |
IP address of the TCP server. |
flow-control
Use flow-control to configure the flow control mode for an RS485 serial interface.
Use undo flow-control to restore the default.
Syntax
flow-control none
undo flow-control
Default
Flow control is not performed on an RS485 serial interface.
Views
RS485 serial interface view
Predefined user roles
network-admin
Parameters
none: Specifies no flow control.
Examples
# Configure none flow control in the inbound and outbound directions for RS485 serial interface UART 1/0/1.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] flow-control none
interface uart
Use interface uart to enter the view of an RS485 interface.
Syntax
interface uart interface-number
Views
System view
Predefined user roles
network-admin
Usage guidelines
interface-number: Specifies an RS485 serial interface number.
Examples
# Enter the view of RS485 serial interface UART 1/0/1.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1]
modbus mode
Use modbus mode to configure the forwarding mode for an RS485 serial interface, and enter the view of the forwarding mode.
Use undo modbus mode to remove the configuration and delete configurations in both forwarding mode views.
Syntax
modbus mode { agent | raw }
undo modbus mode
Default
No forwarding mode is specified for an RS485 serial interface. This indicates that the RS485 serial interface is disabled with Modbus and does not receive any Modbus messages.
Views
RS485 serial interface view
Predefined user roles
network-admin
Parameters
agent: Specifies the agent mode.
raw: Specifies the transparent mode.
Usage guidelines
Application scenarios
Typically, a Modbus client resides on the Ethernet and sends Modbus-TCP messages. Modbus servers are connected via serial links and can recognize 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.
Operating mechanism
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. It 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.
In transparent mode, an RS485 serial interface on the H3C industrial switch transparently transmits Modbus-RTU messages between the Modbus client and Modbus servers.
· 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.
Restrictions and guidelines
You cannot edit the forwarding mode of 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 deletes configurations in both forwarding mode views, which might cause Modbus communication interruption. Use this command with caution.
Examples
# Specify the agent mode for RS485 serial interface UART 1/0/1 and enter the Modbus agent mode view.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode agent
[Sysname-Uart1/0/1-modbus-agent]
# Specify the transparent mode for RS485 serial interface UART 1/0/1 and enter the Modbus transparent mode view.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode raw
[Sysname-Uart1/0/1-modbus-raw]
# Remove the forwarding mode configuration for RS485 serial interface UART 1/0/1 and delete configurations in both forwarding mode views.
<Sysname> system-view
[Sysname] interface uart 0/0/1
[Sysname-Uart0/0/1] undo modbus mode
This configuration will clear all configurations and data under all forwarding mode view. Continue? [Y/N]
modbus packet-size
Use modbus packet-size to set the minimum length of TCP packets that an RS485 serial interface sends to a Modbus client.
Use undo modbus packet-size to restore the default.
Syntax
modbus packet-size size
undo modbus packet-size
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.
Views
RS485 serial interface view
Predefined user roles
network-admin
Parameters
size: Specifies the minimum length of TCP packets which an RS485 serial interface sends to a Modbus client. The value range is 16 to 1400 bytes.
Usage guidelines
Use this command to configure 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.
To edit the minimum length of TCP packets, repeat this command. The new settings take effect immediately.
If an RS485 serial interface establishes UDP connections with Modbus clients, this command does not take effect.
Examples
# Set the minimum length of TCP packets that RS485 serial interface UART 1/0/1 sends to a Modbus client to 100 bytes.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus packet-size 100
Related commands
tcp client
tcp server
modbus packet-time
Use modbus packet-time to configure the interval for an RS485 serial interface to send Modbus-RTU messages to a Modbus server.
Use undo modbus packet-time to restore the default.
Syntax
modbus packet-time interval
undo modbus packet-time
Default
An RS485 serial interface sends Modbus-RTU messages to a Modbus server every 100 milliseconds.
Views
RS485 serial interface view
Predefined user roles
network-admin
Parameters
interval: Specifies the interval for an RS485 serial interface to send Modbus-RTU messages to a Modbus server. The value range for this argument is 20 to 100000 milliseconds in steps of 20.
Usage guidelines
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.
Examples
# Configure an RS485 serial interface to send Modbus-RTU messages to a Modbus server every 800 milliseconds.
<Sysname> system-view
[Sysname-Uart1/0/1] modbus packet-time 800
Related commands
modbus mode
parity
Use parity to specify the parity for an RS485 serial interface.
Use undo parity to restore the default.
Syntax
parity none
undo parity
Default
The setting is none. No parity is used.
Views
RS485 serial interface view
Predefined user roles
network-admin
Usage guidelines
none: Uses no parity.
Usage guidelines
To ensure correct communication, the access endpoint and the device must use the same parity.
Examples
# Configure RS485 serial interface UART 1/0/1 to not use parity.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] parity none
stopbits
Use stopbits to specify the number of stop bits for an RS485 serial interface.
Use undo stopbits to restore the default.
Syntax
stopbits { 1 | 2 }
undo stopbits
Default
The number of stop bits for an RS485 serial interface is 1.
Views
RS485 serial interface view
Predefined user roles
network-admin
Usage guidelines
1: Uses one stop bit for a character.
2: Uses two stop bits for a character.
Examples
# Set the number of stop bits to 2 for RS485 serial interface UART 1/0/1.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-UART1/0/1] stopbits 2
tcp client
Use tcp client to configure an RS485 serial interface as a TCP client to establish a TCP connection with a Modbus client (TCP server).
Use undo tcp client to disconnect the TCP connection.
Syntax
tcp client server-ip server-ip server-port server-port [ vpn-instance vpn-instance-name ]
undo tcp client [ server-ip server-ip ]
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.
Views
Modbus transparent mode view
Predefined user roles
network-admin
Parameters
server-ip server-ip: Specifies the IPv4 address of the TCP server. If you do not specify this option, the command disconnects TCP connections that an RS485 serial interface, configured as a TCP client, has established with all Modbus clients.
server-port server-port: Specifies the port number of the TCP server. The value range for the server-port argument is 1 to 65534.
vpn-instance vpn-instance-name: Specifies a VPN instance by its name. The RS485 serial interface must be associated with the specified VPN instance.
Usage guidelines
Application scenarios
After you execute this command in Modbus transparent mode view of an RS485 serial interface, the interface acts as a TCP client to establish a TCP connection with a Modbus client. Once the TCP connection is successfully established, the RS485 serial interface can receive Modbus messages from the Modbus client through the TCP connection on the Ethernet.
Restrictions and guidelines
You can repeat this command 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.
You cannot edit the port number of a TCP server by repeating the tcp client command. To edit the port number of a TCP server, first execute the undo tcp client command to disconnect the connection established with the TCP server.
Examples
# In Modbus transparent mode view, configure RS485 serial interface UART 1/0/1 as a TCP client to establish a TCP connection with the Modbus client that has port number 502 and IP address 7.7.7.7.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode raw
[Sysname-Uart1/0/1-modbus-raw] tcp client server-ip 7.7.7.7 server-port 502
tcp server
Use tcp server to configure an RS485 serial interface as a TCP server to establish a TCP connection with a Modbus client (TCP client).
Use undo tcp server to disconnect the TCP connection.
Syntax
tcp server [ server-port server-port ] [ vpn-instance vpn-instance-name ]
undo tcp server
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.
Views
Modbus agent mode view
Modbus transparent mode view
Predefined user roles
network-admin
Parameters
server-port server-port: Specifies the port number of the TCP server. The value range for the server-port argument is 1 to 65534. If you do not specify this option, the RS485 serial interface uses default port number 502.
vpn-instance vpn-instance-name: Specifies a VPN instance by its name. The RS485 serial interface must be associated with the specified VPN instance.
Usage guidelines
Application scenarios
After you execute this command in a forwarding mode view of an RS485 serial interface, the interface acts as a TCP server to establish a TCP connection with a Modbus client. Once the TCP connection is successfully established, the RS485 serial interface can receive Modbus messages from the Modbus client through the TCP connection on the Ethernet.
When an RS485 serial interface operates in Modbus agent mode, it receives Modbus-TCP messages transmitted through the TCP protocol from a Modbus client. As a result, the RS485 serial interface must establish a TCP connection with the Modbus client.
On a Modbus network, a Modbus client sends requests to read information and an RS485 serial interface replies to the requests. This causes the RS485 serial interface operating in agent mode to act only as a TCP server when establishing a TCP connection.
Restrictions and guidelines
To ensure correct operation of Modbus and other services, specify an unused port number.
The port numbers specified for different RS485 serial interfaces by using this command cannot be the same.
The tcp client, tcp server, udp client, and udp server commands are mutually exclusive. Do not configure two or more of these commands in the same view.
You cannot edit the port number of a TCP server by repeating the tcp server command. To edit the port number of a TCP server, first execute the undo tcp server command to cancel the configuration that specifies the RS485 serial interface as a TCP server.
Examples
# In Modbus agent mode view, configure RS485 serial interface UART 1/0/1 as a TCP server and specify the TCP server port number as 1172.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode agent
[Sysname-Uart1/0/1-modbus-agent] tcp server server-port 1172
# In Modbus agent mode view, configure RS485 serial interface UART 1/0/1 as a TCP server and specify the TCP server port number as 1022.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode agent
[Sysname-Uart1/0/1-modbus-agent] tcp server server-port 1022
Port between 1~1024 might be used by another application. Continue? [y/n]
Related commands
modbus mode
udp client
Use udp client to configure an RS485 serial interface as a UDP client to establish a UDP connection with a Modbus client (UDP server).
Use undo udp client to disconnect the UDP connection.
Syntax
udp client server-ip server-ip server-port server-port [ local-port local-port ] [ vpn-instance vpn-instance-name ]
undo udp client [ server-ip server-ip ]
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.
Views
Modbus transparent mode view
Predefined user roles
network-admin
Parameters
server-ip server-ip: Specifies the IPv4 address of the UDP server. If you do not specify this option, the command disconnects UDP connections that an RS485 serial interface, configured as a UDP client, has established with all Modbus clients.
server-port server-port: Specifies the port number of the UDP server. The value range for the server-port argument is 1 to 65534.
local-port local-port: Specifies the UDP port number of the local RS485 serial interface. The value range for the local-port argument is 1 to 65534. If you do not specify this option, the interface uses default port number 502.
vpn-instance vpn-instance-name: Specifies a VPN instance by its name. The RS485 serial interface must be associated with the specified VPN instance.
Usage guidelines
Application scenarios
After you execute this command in Modbus transparent mode view of an RS485 serial interface, the interface acts as a UDP client to establish a UDP connection with a Modbus client. Once the UDP connection is successfully established, the RS485 serial interface can receive Modbus messages from the Modbus clients through the UDP connection on the Ethernet.
Restrictions and guidelines
To ensure correct operation of Modbus and other services, specify an unused port number for the local RS485 serial interface.
The port numbers specified for different RS485 serial interfaces by using this command cannot be the same.
You can repeat this command 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.
You cannot edit the executed configuration by repeating the udp client command. To edit the configuration, first execute the undo udp client command.
Examples
# In Modbus transparent mode view, configure RS485 serial interface UART 1/0/1 as a UDP client to establish a UDP connection with the Modbus client that has port number 502 and IP address 7.7.7.7. Specify 4567 as the UDP port number of the RS485 serial interface.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode raw
[Sysname-Uart1/0/1-modbus-raw] udp client server-ip 7.7.7.7 server-port 502 local-port 4567
# In Modbus transparent mode view, configure RS485 serial interface UART 1/0/1 as a UDP client to establish a UDP connection with the Modbus client that has port number 502 and IP address 7.7.7.7. Specify 1022 as the UDP port number of the RS485 serial interface.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode raw
[Sysname-Uart1/0/1-modbus-raw] udp client server-ip 7.7.7.7 server-port 502 local-port 1022
Port between 1~1024 might be used by another application. Continue? [y/n]
Related commands
modbus mode
udp server
Use udp server to configure an RS485 serial interface as a UDP server to establish a UDP connection with a Modbus client (UDP client).
Use undo udp server to disconnect the UDP connection.
Syntax
udp server [ server-port server-port ] [ vpn-instance vpn-instance-name ]
undo udp server
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.
Views
Modbus transparent mode view
Predefined user roles
network-admin
Parameters
server-port server-port: Specifies the port number of the UDP server. The value range for the server-port argument is 1 to 65534. If you do not specify this option, the RS485 serial interface uses default port number 502.
vpn-instance vpn-instance-name: Specifies a VPN instance by its name. The RS485 serial interface must be associated with the specified VPN instance.
Usage guidelines
Application scenarios
After you execute this command in Modbus transparent mode view of an RS485 serial interface, the interface acts as a UDP server to establish a UDP connection with a Modbus client. Once the UDP connection is successfully established, the RS485 serial interface can receive Modbus messages from Modbus client through the UDP connection on the Ethernet.
Restrictions and guidelines
To ensure correct operation of Modbus and other services, specify an unused port number.
The port numbers specified for different RS485 serial interfaces by using this command cannot be the same.
The tcp client, tcp server, udp client, and udp server commands are mutually exclusive. Do not configure two or more of these commands in the same view.
You cannot edit the port number of a UDP server by repeating the udp server command. To edit the port number of a UDP server, first execute the undo udp server command to cancel the configuration that specifies the RS485 serial interface as a UDP server.
Examples
# In Modbus transparent mode view, configure RS485 serial interface UART 1/0/1 as a UDP server and specify the UDP server port number as 1172.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode raw
[Sysname-Uart1/0/1-modbus-raw] udp server server-port 1172
# In Modbus transparent mode view, configure RS485 serial interface UART 1/0/1 as a UDP server and specify the UDP server port number as 1022.
<Sysname> system-view
[Sysname] interface uart 1/0/1
[Sysname-Uart1/0/1] modbus mode raw
[Sysname-Uart1/0/1-modbus-raw] udp server server-port 1022
Port between 1~1024 might be used by another application. Continue? [y/n]
Related commands
modbus mode