Skip to the content.

SHM Modbus - STDIN to Modbus Shared Memory

SHM Modbus > SHM Modbus Tools > stdin to modbus shm

This application reads commands from stdin and writes data to the shared memory created by one of the shared memory Modbus clients (TCP/RTU).

Use the Application

The application can be started, after starting one of the Modbus clients with standard shared memory prefix, without any further arguments.

If the shared memory name prefix has been changed, it can be adjusted via the argument --name-prefix.

After its startup, the application reads commands from stdin. Provide one command per line.

The application terminates as soon as no more input data can be read.

Input format

The commands for the application have the following format:

register_type:register_address:value[:data_type]

register_type specifies into which register the value should be written. The following values are possible (case is ignored):

register_address specifies the address of the register

value specifies the value that is written.
The representation depends on the type of modbus register and data type. For hex and octal numbers the same notation as in C/C++ is used. Some string constants are available.

data_type optionally specifies a data type.
If no data type is specified, one register is written in host byte order.
The following data types are possible:

Note:
The endianness refers to the layout of the data in the shared memory and may differ from the Modbus Server’s definition of the endianness.

Note:
No data type must be specified for writing the bit registers (DO, DI).

Command Passthrough

By using the option --passthrough, all valid inputs are written to stdout. By additionally enabling the option --bash, the output is created as a bash script that reproduces the inputs (including the timing).

Protection against simultaneous access

The shared memory Modbus clients can be set up to provide a semaphore as protection mechanism against simultaneous shared memory access. Use the option --semaphore to use such a semaphore.

Note:
It is recommended to use the semaphore mechanism as concurrent access to the shared memory may cause data corruption.

Monitor Modbus Client

The option --pid is used to specify the process id that stdin-to-modbus-shm monitors. If this process terminates, stdin-to-modbus-shm is terminated.

Usage example:

stdin-to-modbus-shm --pid $(pidof stdin-to-modbus-shm)

Note: stdin-to-modbus-shm does not reconnect to a new shared memory if the modbus client is restarted. Thus, using the --pid option is highly recommended.

Install

The application is available as stdin-to-modbus-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.

stdin-to-modbus-shm is invoked by executing the following command:

flatpak run io.github.shmmodbus.shm-modbus stdin-to-modbus-shm

Snap

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

stdin-to-modbus-shm is invoked by executing the following command:

shm-modbus.stdin-to-modbus-shm