Version
0.8.x_dev

Modbus helper


Modbus helper is builtin tool in boneio to:

  • read any register from connected modbus device
  • in CWT sensors to set correct baudrate or set new device address as all of the devices by default comes with address 1.

Note: remember to always use installed venv

source ~/boneio/venv/bin/activate

Main command

Always use help. As we use Python 3.7 command is nested.

# boneio --help
usage: boneio [-h] [--version] {run,modbus} ...

boneIO app for BeagleBone Black.

positional arguments:
  {run,modbus}

There are 3 main modbus commands. GET, SET and SEARCH

Before you give this positional argument set arguments named optional (even though those aren’t optional).

# boneIO modbus --help
usage: boneio modbus [-h] [--debug] --uart {uart1,uart4} --address ADDRESS
                     --baudrate {2400,4800,9600,19200} --bytesize BYTESIZE
                     --stopbits STOPBITS --parity {P,E,N}
                     {set,get} ...

positional arguments:
  {set,get}

optional arguments:
  -h, --help            show this help message and exit
  --debug, -d           Start boneIO in debug mode
  --uart {uart1,uart4}  Choose UART
  --address ADDRESS     Current device address (hex or integer)
  --baudrate {1200,2400,4800,9600,19200}
                        Current baudrate
  --bytesize BYTESIZE   Bytesize
  --stopbits STOPBITS   stopbits
  --parity {P,E,N}      Parity


Get command help

usage: boneio modbus get [-h] --register-address REGISTER_ADDRESS
                         --register-type {input,holding} --value-type
                         {U_WORD,S_WORD,U_DWORD,S_DWORD,U_DWORD_R,S_DWORD_R,U_QWORD,S_QWORD,U_QWORD_R,FP32,FP32_R}

optional arguments:
  -h, --help            show this help message and exit
  --register-address REGISTER_ADDRESS
                        Register address
  --register-type {input,holding}
                        Register type
  --value-type {U_WORD,S_WORD,U_DWORD,S_DWORD,U_DWORD_R,S_DWORD_R,U_QWORD,S_QWORD,U_QWORD_R,FP32,FP32_R}
                        Value types

Example GET command:

boneio modbus --address 61 --baudrate 9600 --uart uart4 -dd get --register-address 0 --register-type holding --value-type S_WORD

Set command help

usage: boneio modbus set [-h] [--custom-value CUSTOM_VALUE]
                         [--custom-register-address CUSTOM_REGISTER_ADDRESS]
                         --device {cwt,r4dcb08,liquid-sensor,sht20,custom}
                         [--new-address NEW_ADDRESS | --new-baudrate {1200,2400,4800,9600,19200}]

optional arguments:
  -h, --help            show this help message and exit
  --custom-value CUSTOM_VALUE
                        Set Custom value
  --custom-register-address CUSTOM_REGISTER_ADDRESS
                        Register address for custom value
  --device {cwt,r4dcb08,liquid-sensor,sht20,custom}
                        Choose device to set modbus address/baudrate. For
                        custom you must provide --custom-value and --custom-
                        register-address
  --new-address NEW_ADDRESS
                        Set new address (hex or integer / 1 - 253/)
  --new-baudrate {1200,2400,4800,9600,19200}
                        Choose new baudrate to set. CWT doesn't work on 1200.

Example command to set new baudrate to 9600

boneio modbus --address 61 --baudrate 4800 --uart uart4 set --device cwt --new-baudrate 9600

Example command to set new address

boneio modbus --address 1 --baudrate 9600 --uart uart4 set --device cwt --new-address 61

Search for Modbus device

You’d need to know at least specification of the device and register address on which it responds and type of this register.

usage: boneio modbus search [-h] --register-address REGISTER_ADDRESS
                            --register-type {input,holding}

optional arguments:
  -h, --help            show this help message and exit
  --register-address REGISTER_ADDRESS
                        Register address
  --register-type {input,holding}
                        Register type

Example command:

boneio modbus -dd --baudrate 9600 --uart uart4 search --register-address 1 --register-type input

Always reboot device by powering it down and up after set operation