Skip to the content.

SHM Modbus - Modbus TCP Client

SHM Modbus > Modbus Clients > TCP

The modbus-tcp-client-shm is a simple command line based Modbus TCP client for POSIX compatible operating systems that stores the contents of its registers in shared memory.

The client creates four shared memories. One for each register type:

All registers are initialized with 0 at the beginning. The values from these registers (shared memory) are directly accessed by the Modbus server. The actual functionality of the client is realized by applications that read data from or write data to the shared memory.

Usage

modbus-tcp-client-shm [OPTION...]

Network options:

Note:
The Modbus default port can not be used as unprivileged user. See Use privileged ports for details.

Shared memory options:

Note:
--separate and especially --separate-all creates a lot of files. This might exceed the maximum user file limit. See common problems.

Modbus options:

None:
--monitor can have a strong performance impact.

Note:
Usually there is no need to specify --byte-timeout and --response-timeout

Examples

Example 1

modbus-tcp-client-shm

Start client and listen to all incoming connections on the Modbus standard port (502).

Example 2

modbus-tcp-client-shm -p 10000 -r

Start client and listen to all incoming connections on port 10000. The client does not terminate if the Server disconnects.

Example 3

modbus-tcp-client-shm -p 10000 -i 127.0.0.1

Start client and listen to incoming connections via ip 127.0.0.1 on port 10000.

Use privileged ports

Ports below 1024 cannot be used by standard users. Therefore, the default Modbus port (502) cannot be used without further action.

Here are two ways to use the port anyway:

An entry can be added to the iptables that forwards the packets on the actual port to a higher port.

The following example redirects all tcp packets on port 502 to port 5020:

iptables -A PREROUTING -t nat -p tcp --dport 502 -j REDIRECT --to-port 5020

setcap

The command setcap can be used to allow the application to access privileged ports. However, this option grants the application significantly more rights than it actually needs and should therefore be avoided.

This option cannot be used with flatpaks.

setcap 'cap_net_bind_service=+ep' </path/to/binary>

Install

The application is available as modbus-tcp-client-shm in the Arch User Repository. See the Arch Wiki for information about how to install AUR packages.

Using the Modbus Collection Package: SHM Modbus

SHM Modbus is a collection of multiple tools to simulate a Modbus client.

Flatpak

The Flatpak package is available via Flathub as io.github.shmmodbus.shm-modbus.

modbus-tcp-client-shm is invoked by executing the following command:

flatpak run io.github.shmmodbus.shm-modbus modbus-tcp-client-shm

Snap

The snap package can be downloaded via the github release page.

modbus-tcp-client-shm is invoked by executing the following command:

shm-modbus.modbus-tcp-client-shm