MModbusTest Application
MModbusTest is a command-line application for sending and processing Modbus requests. It reads its configuration from a specified file, allowing you to define various Modbus parameters.
Installation
Download the appropriate binary for your platform using wget:
ARM64 (Compulab IMX8MP, InHand EC900)
wget -O MModbusTest http://update.moleculeos.io/mpackages/files/apps/arm64/MModbusTest
Teltonika (RUT955, RUT240)
wget -O MModbusTest http://update.moleculeos.io/mpackages/files/apps/rut9_r/MModbusTest
Rainforest (RFE200)
wget -O MModbusTest http://update.moleculeos.io/mpackages/files/apps/rfe200/MModbusTest
Usage
./MModbusTest [options]
| Option | Description |
|---|---|
-h | Displays the help message |
-f <filename> | Specifies the configuration file (mandatory) |
-r <register_value> | Overrides the modbus_register value when ? is used as a placeholder |
Running the Application
- Create a configuration file (e.g.
modbus_config.cf) with the desired Modbus parameters. - Open your terminal and navigate to the directory containing the
MModbusTestexecutable. - Run the application:
./MModbusTest -f modbus_config.cf
- If your configuration file uses
modbus_register = ?, provide the register value with-r:
./MModbusTest -f modbus_config.cf -r 258
note
- The
-foption is mandatory. - Modbus IDs, function codes, register addresses, flags, and values must be in hexadecimal format (e.g.
0x0A). - For Modbus RTU, ensure the serial port specified by
rtu_pathexists and your user has the necessary permissions. - For Modbus TCP, ensure the server at the specified IP address and port is reachable.
- The application exits after processing the configuration and sending the Modbus request.
Configuration File
The configuration file uses a simple key = value format with each parameter on a new line.
| Key | Description |
|---|---|
cmd_base | Command base. Use 10 for decimal addresses, 16 for hex. |
modbus_type | Modbus protocol type: 0 = RTU, 1 = TCP |
server_ip | (TCP only) IP address of the Modbus server |
server_port | (TCP only) Port number of the Modbus server (default: 502) |
rtu_baud | (RTU only) Baud rate for serial communication |
rtu_path | (RTU only) Path to the serial port device (e.g. /dev/ttyS0, /dev/rs485) |
modbus_id | Modbus slave ID (hex format) |
modbus_function | Modbus function code (hex format). Common codes: 03 = Read Holding Registers, 06 = Write Single Holding Register |
modbus_register | Starting register address (hex format). Use ? to override with -r option. |
modbus_flags | Modbus flags (hex format) |
modbus_value | Value to write in a write request (hex format) |
modbus_request_length | Number of registers to read or write |
data_exp | Data expression string |
data_type | Data type of the register(s) being accessed (see Data Types below) |
modbus_send | Set to true to process and send the Modbus request |
Data Types
| Value | Type |
|---|---|
0 | Uint8 |
1 | Int8 |
2 | Uint16 |
3 | Int16 |
4 | Uint32 |
5 | Int32 |
6 | Uint64 |
7 | Int64 |
8 | Float |
Example Configuration Files
Modbus RTU
modbus_type = 0
rtu_path = /dev/rs485
rtu_baud = 9600
modbus_id = 0x01
modbus_function = 0x03
modbus_register = 0x00
modbus_request_length = 1
data_type = 2
modbus_send = true
Modbus TCP
modbus_type = 1
server_ip = 192.168.1.100
server_port = 502
modbus_id = 0x02
modbus_function = 0x06
modbus_register = ?
modbus_value = 0x1234
modbus_send = true