Skip to main content

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]
OptionDescription
-hDisplays 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

  1. Create a configuration file (e.g. modbus_config.cf) with the desired Modbus parameters.
  2. Open your terminal and navigate to the directory containing the MModbusTest executable.
  3. Run the application:
./MModbusTest -f modbus_config.cf
  1. If your configuration file uses modbus_register = ?, provide the register value with -r:
./MModbusTest -f modbus_config.cf -r 258
note
  • The -f option 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_path exists 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.

KeyDescription
cmd_baseCommand base. Use 10 for decimal addresses, 16 for hex.
modbus_typeModbus 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_idModbus slave ID (hex format)
modbus_functionModbus function code (hex format). Common codes: 03 = Read Holding Registers, 06 = Write Single Holding Register
modbus_registerStarting register address (hex format). Use ? to override with -r option.
modbus_flagsModbus flags (hex format)
modbus_valueValue to write in a write request (hex format)
modbus_request_lengthNumber of registers to read or write
data_expData expression string
data_typeData type of the register(s) being accessed (see Data Types below)
modbus_sendSet to true to process and send the Modbus request

Data Types

ValueType
0Uint8
1Int8
2Uint16
3Int16
4Uint32
5Int32
6Uint64
7Int64
8Float

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