Skip to content

bonifaido/modbus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

modbus

A modbus CLI written in C based on libmodbus.

Usage

modbus [-p=<profile>] [-a=<addr:port>] [-s=<slave_id>] [-t=<u16|u32>] [-w=<hl|lh>] <register>[=<value>]
  • -t: register type, u16 (default) or u32
  • -w: word order for u32, hl (default, high word first) or lh (low word first)

Profiles

The modbus CLI makes it easy to handle multiple modbus devices in your home with the help of profiles. It supports a simple CSV based profile file, located in the user's home directory.

If there is only one valid profile listed it will be used when -p is not specified. If multiple profiles exist, one named default will be used when -p is not specified. If multiple profiles exist and none is named default, pass -p <name>.

Line format: Name,IP,PORT,SlaveID

Example content of the file under ~/.modbus:

default,192.168.1.200,4196,1
boiler,192.168.2.101,502,0

Examples

# Read the register 41 from the given address
modbus -a 192.168.1.200:4196 41

# Specify slave id for the above operation
modbus -a 192.168.1.200:4196 -s 1 41

# Read a uint32 from registers 41 and 42 (high word at 41, low word at 42)
modbus -a 192.168.1.200:4196 -t u32 41

# Read a uint32 where word order is low word first
modbus -a 192.168.1.200:4196 -t u32 -w lh 41

# Write uint32 value 123456 to registers 41 and 42
modbus -a 192.168.1.200:4196 -t u32 41=123456

In this case you have profile file the usage is just simply:

# Read the register 41
modbus 41

# Write the value 34 to the register number 41
modbus 41=34

# Write the value 34 to the register number 41 for the boiler
modbus -p boiler 41=34

Build and use

You need to have libmodbus installed. On macOS it is:

# Install libmodbus
brew install libmodbus

# Expose brew based headers and shared libraries
export CPATH="$HOMEBREW_PREFIX/include:$CPATH"
export LIBRARY_PATH="$HOMEBREW_PREFIX/lib:$LIBRARY_PATH"

Build and run:

# Compile
make
# Run
./modbus -h

Tests

Run unit tests:

make test

The test binary covers parser helpers, word-order conversion helpers, address parsing, and profile-selection behavior.

About

a modbus cli client written in C based on libmodbus

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages