Giter Site home page Giter Site logo

mbpoll's Introduction

mbpoll

Copyright © 2015-2023 Pascal JEAN, All rights reserved.

Abstract

mbpoll is a command line utility to communicate with ModBus slave (RTU or TCP).
This is a multiplatform project, the compilation was tested on GNU Linux x86, x86_64, armhf and arm64 (Armbian/Raspbian), Microsoft Windows, and Mac OSX.

Development of major version 1 of mbpoll is complete, version 2 using libmodbuspp is under development. Proposals for new features will be transferred to this new branch.

mbpoll can:

  • read discrete inputs
  • read and write binary outputs (coil)
  • read input registers
  • read and write output registers (holding register)

The reading and writing registers may be in decimal, hexadecimal or floating single precision.

Note: mbpoll's output syntax and command line option syntax is similar to the original modpoll command line program published by proconX. However mbpoll is a completely independent project and based on different source code than the original modpoll program. mbpoll is distributed under the GPL license, but the original modpoll program is not covered by the GPL license.

Quickstart guide

The fastest and safest way to install mbpoll is to use the APT repository from piduino.org, so you should do the following :

wget -O- http://www.piduino.org/piduino-key.asc | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.piduino.org stretch piduino'
sudo apt update
sudo apt install mbpoll

This repository provides mbpoll and libmodbus (version 3.1.4) packages for i386, amd64, armhf and arm64 architectures. In the above commands, the repository is a Debian Stretch distribution, but you can also choose Ubuntu Trusty, Xenial or Bionic by replacing stretch with trusty, xenial or bionic.
It may be necessary to install the software-properties-common package for add-apt-repository.

For Raspbian you have to do a little different :

wget -O- http://www.piduino.org/piduino-key.asc | sudo apt-key add -
echo 'deb http://raspbian.piduino.org stretch piduino' | sudo tee /etc/apt/sources.list.d/piduino.list
sudo apt update
sudo apt install mbpoll

The Raspbian repository provides Piduino packages for armhf architecture for Stretch only.

Build from source

For example, for a debian system:

  • Install libmodbus (Version >= 3.1.4) :

      $ sudo apt-get install build-essential libtool git-core autoconf automake
      $ git clone https://github.com/stephane/libmodbus.git
      $ cd libmodbus
      $ ./autogen.sh
      $ ./configure
      $ make
      $ sudo make install
    

You can also install it with apt if the version of libmodbus is greater than or equal to 3.1.4. For example to query a debian system:

$ apt-cache show libmodbus-dev
  • Install piduino only if you want to manage the RS485 with a GPIO signal:

      $ sudo apt-get install cmake libcppdb-dev pkg-config libsqlite3-dev sqlite3 libudev-dev
      $ git clone https://github.com/epsilonrt/piduino.git
      $ cd piduino 
      $ git checkout dev
      $ mkdir build
      $ cd build
      $ cmake ..
      $ make
      $ sudo make install
    
  • Generate Makefile with cmake:

      $ sudo apt-get install cmake pkg-config
      $ cd mbpoll
      $ mkdir build
      $ cd build
      $ cmake ..
    
  • Compile and install mbpoll:

      $ make
      $ sudo make install
      $ sudo ldconfig
    

If you prefer, you can in the place of direct compilation create a package and install it:

    $ make package
    $ sudo dpkg -i * .deb

That's all !

For Windows, you can follow the instructions in the README-WINDOWS.md file.

Examples

The following command is used to read the input registers 1 and 2 of the slave at address 33 connected through RTU /dev/ttyUSB2 (38400 Bd)


    $ mbpoll -a 33 -b 38400 -t 3 -r 1 -c 2 /dev/ttyUSB2
    
    mbpoll 1.5 -  Modbus® Master Simulator
    Copyright (c) 2015-2023 Pascal JEAN, https://github.com/epsilonrt/mbpoll
    This program comes with ABSOLUTELY NO WARRANTY.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type 'mbpoll -w' for details.

    Protocol configuration: Modbus RTU
    Slave configuration...: address = [33]
                            start reference = 1, count = 2
    Communication.........: /dev/ttyUSB2, 38400-8E1 
                            t/o 1.00 s, poll rate 1000 ms
    Data type.............: 16-bit register, input register table

    -- Polling slave 33... Ctrl-C to stop)
    [1]: 	9997
    [2]: 	10034
    -- Polling slave 33... Ctrl-C to stop)
    [1]: 	10007
    [2]: 	10034
    -- Polling slave 33... Ctrl-C to stop)
    [1]: 	10007
    [2]: 	10034
    -- Polling slave 33... Ctrl-C to stop)
    [1]: 	10007
    [2]: 	10034
    ^C--- /dev/ttyUSB2 poll statistics ---
    4 frames transmitted, 4 received, 0 errors, 0.0% frame loss

    everything was closed.
    Have a nice day !

Help

A complete help is available with the -h option:

usage : mbpoll [ options ] device|host [ writevalues... ] [ options ]

ModBus Master Simulator. It allows to read and write in ModBus slave registers
                         connected by serial (RTU only) or TCP.

Arguments :
  device        Serial port when using ModBus RTU protocol
                  COM1, COM2 ...              on Windows
                  /dev/ttyS0, /dev/ttyS1 ...  on Linux
                  /dev/ser1, /dev/ser2 ...    on QNX
  host          Host name or dotted IP address when using ModBus/TCP protocol
  writevalues   List of values to be written.
                If none specified (default) mbpoll reads data.
                If negative numbers are provided, it will precede the list of
                data to be written by two dashes ('--'). for example :
                mbpoll -t4:int /dev/ttyUSB0 -- 123 -1568 8974 -12
General options : 
  -m #          mode (rtu or tcp, TCP is default)
  -a #          Slave address (1-255 for rtu, 0-255 for tcp, 1 is default)
                for reading, it is possible to give an address list
                separated by commas or colons, for example :
                -a 32,33,34,36:40 read [32,33,34,36,37,38,39,40]
  -r #          Start reference (1 is default)
                for reading, it is possible to give an address list
                separated by commas or colons
  -c #          Number of values to read (1-125, 1 is default)
  -u            Read the description of the type, the current status, and other
                information specific to a remote device (RTU only)
  -t 0          Discrete output (coil) data type (binary 0 or 1)
  -t 1          Discrete input data type (binary 0 or 1)
  -t 3          16-bit input register data type
  -t 3:int16    16-bit input register data type with signed int display
  -t 3:hex      16-bit input register data type with hex display
  -t 3:string   16-bit input register data type with string (char) display
  -t 3:int      32-bit integer data type in input register table
  -t 3:float    32-bit float data type in input register table
  -t 4          16-bit output (holding) register data type (default)
  -t 4:int16    16-bit output (holding) register data type with signed int display
  -t 4:hex      16-bit output (holding) register data type with hex display
  -t 4:string   16-bit output (holding) register data type with string (char) display
  -t 4:int      32-bit integer data type in output (holding) register table
  -t 4:float    32-bit float data type in output (holding) register table
  -0            First reference is 0 (PDU addressing) instead 1
  -B            Big endian word order for 32-bit integer and float
  -1            Poll only once only, otherwise every poll rate interval
  -l #          Poll rate in ms, ( > 100, 1000 is default)
  -o #          Time-out in seconds (0.01 - 10.00, 1.00 s is default)
  -q            Quiet mode.  Minimum output only
Options for ModBus / TCP : 
  -p #          TCP port number (502 is default)
Options for ModBus RTU : 
  -b #          Baudrate (1200-921600, 19200 is default)
  -d #          Databits (7 or 8, 8 for RTU)
  -s #          Stopbits (1 or 2, 1 is default)
  -P #          Parity (none, even, odd, even is default)
  -R [#]        RS-485 mode (/RTS on (0) after sending)
                 Optional parameter for the GPIO RTS pin number
  -F [#]        RS-485 mode (/RTS on (0) when sending)
                 Optional parameter for the GPIO RTS pin number

  -h            Print this help summary page
  -V            Print version and exit
  -v            Verbose mode.  Causes mbpoll to print debugging messages about
                its progress.  This is helpful in debugging connection...

Copyright © 2015-2023 Pascal JEAN, All rights reserved.

mbpoll is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

mbpoll is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with mbpoll. If not, see http://www.gnu.org/licenses/.

mbpoll's People

Contributors

epsilonrt avatar jonadem avatar kamakado avatar prasannajnaeyulu avatar pstzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mbpoll's Issues

Add a 'quiet' option

In some use cases, it could be nice if the output will be as concise as possible.

A '-q' option is not yet used.

Remove the two references to FieldTalk trademark in modpoll.c and the README files.


Hello Pascal Jean,

I am asking you for your cooperation on a small matter regards your mbpoll application published on github.

I am the author of the original modpoll program. I understand that you have re-implemented our modpoll's program functionality and are publishing this under the GPL on github. This is in principal OK with us, as it is based on a different source code and a different way of implementing the features compared to our original program.

However you are referring to our trademark FieldTalk in your program, probably because you simply copied some verbatim text from our modpoll program's output. To avoid any confusion, may I kindly ask you to remove the two references to our FieldTalk trademark in modpoll.c and the README files.

We are also receiving emails from time to time where people accuse us of violating the GPL, with people thinking that our program is based on yours. This is despite the fact that you make it clear in the README on github with the text "Although the syntax of these options is very close modpoll proconX program, it is a completely independent project." But it seems this text not enough to explain the differences.

May I suggest to make this clearer to avoid any problems in the future, for example using this text:

Note: mbpoll's output syntax and command line option syntax is compatible to the original modpoll command line program published by proconX on [modbusDRIVER.com]([https://www.modbusdriver.com/modpoll.html]. However mbpoll is a completely independent project and based on different source code than the original modpoll program. The original modpoll program is not covered by the GPL license.

Thank you for your understanding and cooperation.

Kind regards

Henrik Maier

Force use of FC06 or FC16 for single 16bit writes via cmd line switch like modpoll

Currently the program switches automatically between FC06 and FC16 depending on the number of bytes requested

libmodbus's Arduino port does not support FC06 so mbpoll does not work for single register writes

it would be nice if there was a way to force FC06 or FC16 depending on a command line switch/option

This write functionality is different to modpoll which uses FC16 by default and offers the ability to force FC06

Don't work with RPi Zero W (new install)

Installation works well, but after installation I get:

pi@raspberrypi:~ $ mbpoll -h
Illegal instruction

I used to use this application on RPi 2 B+. Everything worked fine. If I set the image from the old raspberry to zero, everything works.

The problem is with the new installation

TY!

Allow RTU also writing to address 0x00 (=broadcast address)

Some RTU devices need to get initialized to a certain address via the 0x00 broadcast address. But currently RTU_SLAVEADDR_MIN is defined as 1

If I change it to #define RTU_SLAVEADDR_MIN 0 I can write successfully to it and the device gets configured accordingly:

./mbpoll -a 0 -b 9600  -t 4  -r 0x4000 -0  /dev/ttyUSB3 2 -v
debug enabled
Set mode to RTU for serial port
Set device=/dev/ttyUSB3
1 write data have been found
Set data=2
Word[0]=0x2
mbpoll 1.4-17 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'mbpoll -w' for details.

Opening /dev/ttyUSB3 at 9600 bauds (E, 8, 1)
Set response timeout to 1 sec, 0 us
Protocol configuration: Modbus RTU
Slave configuration...: address = [0]
                        start reference = 16384, count = 1
Communication.........: /dev/ttyUSB3,       9600-8E1 
                        t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, output (holding) register table

[00][06][40][00][00][02][1C][1A]
Waiting for a confirmation...
<02><06><00><00><00><02><08><38>
Request for slave 2 ignored (not 0)
Message length not corresponding to the computed length (0 != 8)
Write output (holding) register failed: Invalid data

But the check does not match, as the device now responds with its new configured address (=0x02) (which is okay, imo) - afaik responses to broadcasts are not defined/supported.

Is there any specific reason why the RTU_SLAVEADDR_MIN=1 for RTU? Or is there a other way to send to the broadcast address?

error when polling slave address 255

get following message when polling slave address 255, device is Renogy Wanderer 10A battery charger.

-- Polling slave 255...
mbpoll: modbus-rtu.c:110: _modbus_rtu_build_request_basis: Assertion `ctx->slave != -1' failed.
Aborted

Have tried on other Renogy Wanderer 30A battery charger which has slave address 1 and 255, works on 1 and got the same error on 255. This device can be polled from either slave address 1 or 255 when using qmodmaster, https://sourceforge.net/projects/qmodmaster/, under MS-windows 10

Any help/suggestion would be much appreciated.

Regards,
Wade H.

No Make File For Raspberry Pi

Hi

This is a great project!

I am super impressed :-)

I want to compile this on a raspberry pi to use ttyS0 UART but I cannot compile it as your installation instructions for RPi appear incomplete.

I do not understand why you should need qmake installed to compile this, can you provide a more basic make file that would work without installing this first?

Thanks for helping

Andrew.

Dependency for libmodbus in README.md

The Debian package autoconf needs to be installed when installing libmodbus. Maybe you want to add it to the README.md

The dependency cmake for mbpoll is missing as well.

endian swap feature

Can I suggest you add the feature to swap the byte order for 32 bit reads (either long ints or floats)

This comes up more often than you'd expect in the field :-(

Error While Installing on Ubuntu Server

I followed your Quickstart Guide, after adding repository while running sudo apt update I faced the error below:

  • N: Skipping acquire of configured file 'piduino/binary-amd64/Packages' as repository 'http://apt.piduino.org stretch InRelease' doesn't support architecture 'amd64'

  • I am trying to install it on a Ubuntu 20.04.2 LTS server. I tried to change deb http://apt.piduino.org stretch piduino to deb [arch= amd64] http://apt.piduino.org stretch piduino but didn't work.

  • What should I do to install it? Thanks for your help.

List of registers -r is no longer handled correctly in version 1.4, as in version 1.0

Moin,
My command is:
pi@gk59:~/mbpoll $ mbpoll /dev/ttyUSB0 -t3:float -b 19200 -d 8 -s 1 -P even -a 14 -r 1,7,11,17 -1 -B -c 4 -q

in version 1.0 the result is as expected
-- Polling slave 14...
[1]: 237.225
[7]: 0.34117
[11]: 0.284538
[17]: 36.8121

in the new Version 1.4-12 the result is

-- Polling slave 14...
[1]: 237.644
[3]: 237.554
[5]: 237.689
[7]: 0.343417

It seems that mbpoll ignores the list and only pulls the count given with -c starting with the first number of the list.

Thanks for the good tool mbpoll.

Christian

Arduino.h not found

"make -j4" since revision 1.4 on my "RaspberryPi 2 Model B Rev 1.1" is not possible:

(#)~/mbpoll/build:$ make -j4 08:05:23
-- PiDuino found !
-- Check the target platform, you can use PIBOARD_ID to force the target...
-- Detecting host CPU - bcm2835 found
/usr/bin/env: „node“: Datei oder Verzeichnis nicht gefunden
-- No Pi board found.
-- Debian architecture armhf
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mbpoll/build
Scanning dependencies of target mbpoll
[ 50%] Building C object CMakeFiles/mbpoll.dir/src/custom-rts.c.o
[ 50%] Building C object CMakeFiles/mbpoll.dir/src/mbpoll.c.o
[ 75%] Building C object CMakeFiles/mbpoll.dir/src/serial.c.o
/root/mbpoll/src/custom-rts.c:17:21: fatal error: Arduino.h: Datei oder Verzeichnis nicht gefunden
#include <Arduino.h>
^
compilation terminated.
CMakeFiles/mbpoll.dir/build.make:86: die Regel für Ziel „CMakeFiles/mbpoll.dir/src/custom-rts.c.o“ scheiterte
make[2]: *** [CMakeFiles/mbpoll.dir/src/custom-rts.c.o] Fehler 1
make[2]: *** Es wird auf noch nicht beendete Prozesse gewartet...
CMakeFiles/Makefile2:67: die Regel für Ziel „CMakeFiles/mbpoll.dir/all“ scheiterte
make[1]: *** [CMakeFiles/mbpoll.dir/all] Fehler 2
Makefile:149: die Regel für Ziel „all“ scheiterte
make: *** [all] Fehler 2
[Exit 2 ]

Arduino libs are installed in /usr/share/arduino and /usr/lib/avr but can not be found.

Is it possible to deactivate this buggy building of "custom-rts.c"?

I probed comment custom-rts.c in CMakeLists.txt, but in this case build ends also with errors:

CMakeFiles/mbpoll.dir/src/mbpoll.c.o: In function main': mbpoll.c:(.text.startup+0x7ac): undefined reference to init_custom_rts'
mbpoll.c:(.text.startup+0x9b4): undefined reference to `set_custom_rts'
collect2: error: ld returned 1 exit status
CMakeFiles/mbpoll.dir/build.make:120: die Regel für Ziel „mbpoll“ scheiterte
make[2]: *** [mbpoll] Fehler 1
CMakeFiles/Makefile2:67: die Regel für Ziel „CMakeFiles/mbpoll.dir/all“ scheiterte
make[1]: *** [CMakeFiles/mbpoll.dir/all] Fehler 2
Makefile:149: die Regel für Ziel „all“ scheiterte
make: *** [all] Fehler 2
[Exit 2 ]

Is it possible to fix this te problem or deactivate your new "custom-rts" support optionally?

64 bit float and integer reading in linux

As there is inaccuracy in reading float values, I'm using some bash commands to get right value in different byte orders and endiannesses.
Maybe someone else will find this usefull:

#32 bit float:
#BIG Endian
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#LITTLE Endian
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#BIG Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#LITTLE Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#64 bit float:
#BIG Endian
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'

#LITTLE Endian
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'

#BIG Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'

#LITTLE Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'


##32 bit integer:
#commands are the same, as for 32 bit float, except:
#for signed 32bit integer, use "l" in python unpack format - "...struct.unpack("!l",...";
#for unsigned 32bit integer, use "L" in python unpack format - "...struct.unpack("!L",...".

##64 bit integer:
#commands are the same, as for 64 bit float, except:
#for signed 64bit integer, use "q" in python unpack format - "...struct.unpack("!q",...";
#for unsigned 64bit integer, use "Q" in python unpack format - "...struct.unpack("!Q",...".

mbpoll_32_64bit_tests.txt

qmake not running in Raspberry pi

Hi

I have followed the instructions on installing it on Raspberry Pi Stretch. I have properly setup qmake like below:

find /usr -name qmake | grep qt4
/usr/lib/arm-linux-gnueabihf/qt4/bin/qmake
/usr/share/qt4/bin/qmake

alias qmake="/usr/lib/arm-linux-gnueabihf/qt4/bin/qmake"

qmake

But when I run qmake, it only gives me its help options and nothing else. If I execute command make after qmake, it says no target files specified. Please help

Extended modbus function codes

Hi,

I'm not a programmer but found your mbpoll utility very usefull for field debugging.
Would it be possible to add support for extended function codes for reading & writing ?
(i.e. function 43,67,68,...)

Windows version?

Hi all, is there any mbpoll windows version free to download?
Thanks.

mbpoll timeout

Hello,

I'm trying to communicate with a RTU current and voltage analizer for Photovoltaic Plants.

I have been able to communicate with it with Modbus Poll in Windows 10 but it has been imposible with mbpoll in ubuntu server 18.04.5.
These are the registers I'm trying to read.
image

These are my modbus poll parameters.

image
image

The ttyoS0 from my Ubuntu Server PC is configured:

image

And I use a cable with this configuration:
BPC (DB9) - RTU
A+ 2 A+
B- 1 B-
GND 5 GND

And this is my mbpoll command.
Apparently I'm sending the send bytes as in Modbus Poll with windows.

image

I have also tried with 2 stop bits but without any success,

Do you have any clue. I'm totally lost.

Swapped input and holding register?

I'm a little bit confused about the numbers in the -t parameter:
Function code 03 are holding registers, used with -t 4
Function code 04 are input registers, used with -t 3
Intentional?

indicate toolchain used to build on Windows

I tried to build mbpoll on Windows 10 without success so far.
I tried with MS Visual Studio 2013 and with MinGW but it always fails (with MinGW, I was able to build mbpoll.c but the linker still gives me errors).
An hint will be highly appreciated !

Connection timeout: `Connection timed out: select`

Im trying to query my smart meter, with a USB/RS485 adapter. (Datasheet with modbus documentation)

With the "EEM Meter Setting" tool from the Manufacturer everything works fine, but with mbpoll i get always a connection timeout.

 sudo mbpoll -a 1 -b 9600 -t 3:float -r 1 -v  -c 1 /dev/ttyUSB0
debug enabled
Set number of values=1
Set mode to RTU for serial port
Set device=/dev/ttyUSB0
mbpoll 1.4-12 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'mbpoll -w' for details.

Opening /dev/ttyUSB0 at 9600 bauds (E, 8, 1)
Set response timeout to 1 sec, 0 us
Protocol configuration: Modbus RTU
Slave configuration...: address = [1]
                        start reference = 1, count = 1
Communication.........: /dev/ttyUSB0,       9600-8E1 
                        t/o 1.00 s, poll rate 1000 ms
Data type.............: 32-bit float (little endian), input register table

-- Polling slave 1... Ctrl-C to stop)
[01][04][00][00][00][02][71][CB]
Waiting for a confirmation...
ERROR Connection timed out: select
Read input register failed: Connection timed out
-- Polling slave 1... Ctrl-C to stop)
[01][04][00][00][00][02][71][CB]
Waiting for a confirmation...
ERROR Connection timed out: select
Read input register failed: Connection timed out
^C--- /dev/ttyUSB0 poll statistics ---
2 frames transmitted, 0 received, 2 errors, 100.0% frame loss

everything was closed.
Have a nice day !

When i compare the data that is send ([01][04][00][00][00][02][71][CB]), it looks exact the same as from the "EEM Meter" tool:
Unbenannt

Why do i cant get the values via mbpoll?

Thanks for any hint/help.


EDIT: I changed the connection settings, the parity was wrong.
Now it "connects" but the returned values are strange:

sudo mbpoll -a 1 -b 9600 -t 3:float -r 1 -v -P none -c 1 /dev/ttyUSB0
debug enabled
Set rtu parity=none
Set number of values=1
Set mode to RTU for serial port
Set device=/dev/ttyUSB0
mbpoll 1.4-12 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'mbpoll -w' for details.

Opening /dev/ttyUSB0 at 9600 bauds (N, 8, 1)
Set response timeout to 1 sec, 0 us
Protocol configuration: Modbus RTU
Slave configuration...: address = [1]
                        start reference = 1, count = 1
Communication.........: /dev/ttyUSB0,       9600-8N1 
                        t/o 1.00 s, poll rate 1000 ms
Data type.............: 32-bit float (little endian), input register table

-- Polling slave 1... Ctrl-C to stop)
[01][04][00][00][00][02][71][CB]
Waiting for a confirmation...
<01><04><04><43><6E><EC><F5><03><5A>
[1]: 	-2.37204e+27
-- Polling slave 1... Ctrl-C to stop)
[01][04][00][00][00][02][71][CB]
Waiting for a confirmation...
<01><04><04><43><6E><CE><26><5A><67>
[1]: 	-6.97359e+08
-- Polling slave 1... Ctrl-C to stop)
[01][04][00][00][00][02][71][CB]
Waiting for a confirmation...
<01><04><04><43><6E><CF><77><9A><0B>
[1]: 	-4.14839e+09
^C--- /dev/ttyUSB0 poll statistics ---
3 frames transmitted, 3 received, 0 errors, 0.0% frame loss

everything was closed.
Have a nice day !

Ubuntu 20.04 (Mac Parallel VM Arm64) installation issue using apt-repository

Hello there,

I recently try to install this program in Ubuntu 20.04 Arm64 using Parallel virtual machine. Errors are encountered when using APT repository from piduino.org.

sudo add-apt-repository 'deb http://apt.piduino.org stretch piduino'
Hit:1 http://apt.piduino.org buster InRelease                                     
Get:2 http://apt.piduino.org stretch InRelease [2,836 B]                          
Hit:3 http://ports.ubuntu.com/ubuntu-ports focal InRelease
Get:4 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease [108 kB]                          
Get:6 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [114 kB]                           
Get:7 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 DEP-11 Metadata [278 kB]           
Get:8 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 DEP-11 Metadata [389 kB]       
Get:9 http://ports.ubuntu.com/ubuntu-ports focal-backports/main arm64 DEP-11 Metadata [8,000 B]        
Get:10 http://ports.ubuntu.com/ubuntu-ports focal-backports/universe arm64 DEP-11 Metadata [30.8 kB]   
Get:11 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 DEP-11 Metadata [40.6 kB]        
Get:12 http://ports.ubuntu.com/ubuntu-ports focal-security/universe arm64 DEP-11 Metadata [66.2 kB]    
Fetched 1,152 kB in 8s (148 kB/s)                                                                      
Reading package lists... Done
N: Skipping acquire of configured file 'piduino/binary-arm64/Packages' as repository 'http://apt.piduino.org stretch InRelease' doesn't support architecture 'arm64'

It indicates the distribution apt-repository does not support arm64. Can any body help to resolve this??

Thank you.

Problem with float output in exponential: different from what was written

$ /usr/local/bin/mbpoll -t4:float -0 -B -1 -q -r 10 127.0.0.1 -p 1502 -- 1269349
Written 1 references.

$ /usr/local/bin/mbpoll -t4:float -0 -B -1 -q -r 10 127.0.0.1 -p 1502
-- Polling slave 1...
[10]: 1.26935e+06

$ /usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502
-- Polling slave 1...
[10]: 0x499A
[11]: 0xF328

As you can see - if I convert read (output to shell) value "1.26935e+06" to normal number, it will be 1269350 instead of 1269349.
Using online IEEE-754 converter hex is decoded normally to 1269349.
Why is it displayed in exponential form?

OS X

Hi.

I tried compiling under OS X latest version.
The cake fails on the getgitversion line 9 in the Cmakechecklist.
I am not an expert but this error halts the make.
BTW, there is no Modbus cli for OS X that supports serial bus.

mbpoll giving a 'std::system_error' (Pi 4B 2G - Buster)

Cannot seem to get mbpoll to run on Pi 4B 2GB running Buster.

terminate called after throwing an instance of 'std::system_error'
what(): It seems that this system is not supported !: Operation not supported
Aborted

First time seeing the error. Replicated the error of a fresh install of Raspbian

Please assist, not sure if I have missed something.

exit code not set properly

It looks like I do not get proper exit codes on (any) failures (I tried so far):

pem scripts # ../bin/mbpoll -1 -t1 -r 15 -c1 10.117.12.12
mbpoll 1.3-3 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright (c) 2015 epsilonRT, All rights reserved.
This software is governed by the CeCILL license http://www.cecill.info

Protocol configuration: Modbus TCP
Slave configuration...: address = [1]
start reference = 15, count = 1
Communication.........: 10.117.12.12, port 502, t/o 1.00 s, poll rate 1000 ms
Data type.............: discrete input

-- Polling slave 1...
Read discrete input failed: Illegal function

pem scripts # echo $?
0

This should be different from 0.

modbus ascii support

Hi,

would it be possible to add support for modbus ascii. I need it for a heating controller project

thanks

I cannot install using the quickstart guide for Raspbian

I am still a newbie, but I have run this installation before using the quickstart guide and it worked fine.

I cannot seem to start the installation using the (this is under the raspbian section):

wget -O- http://www.piduino.org/piduino-key.asc | sudo apt-key add -
echo 'deb http://raspbian.piduino.org stretch piduino' | sudo tee /etc/apt/sources.list.d/piduino.list
sudo apt update
sudo apt install mbpoll

I get "HTTP request sent, awaiting response....404 Not Found."

The installation then terminates with the remaining steps having no data to refer to.

I am currently running Buster

Am I doing something wrong? Please assist.

Regards,

Modbus read RTU gives timeout

Hi,
I have a problem with an embeddedpi with mbpoll reading modbus registers on ttyAMA0 from a simply modbus slave running on windows. The laptop has an rs485 to usb converter like on the picture. It has been working before but now i only get timeouts. So the read is received on the laptop and the response i send. But the respons isn't received on the embeddedpi.

When i issue the command, i get this respons:

root@raspberrypi:~# mbpoll -b 9600 -m rtu -a 1 -r 1 -c 1 /dev/ttyAMA0 -1 -P none
mbpoll 0.1-23 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright (c) 2015 epsilonRT, All rights reserved.
This software is governed by the CeCILL license <http://www.cecill.info>

Protocol configuration: Modbus RTU
Slave configuration...: address = [1]
                        start reference = 1, count = 1
Communication.........: /dev/ttyAMA0,       9600-8N1 
                        t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, output (holding) register table

-- Polling slave 1...
Read output (holding) register failed: Connection timed out

Is there something i can do to debug this?

slave
converter

implicit declaration of function 'MAX' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Compiling on macOS (clang), I get these errors:

$ make
[ 25%] Building C object CMakeFiles/mbpoll.dir/src/mbpoll.c.o
/Users/rmann/Projects/Clients/NASA/FurnaceController/misc/mbpoll/src/mbpoll.c:684:22: error: implicit declaration of function 'MAX' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    int iNbToWrite = MAX (0, argc - optind - 1);
                     ^
/Users/rmann/Projects/Clients/NASA/FurnaceController/misc/mbpoll/src/mbpoll.c:1629:17: error: implicit declaration of function 'MAX' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        iLast = MAX (iFirst, i);
                ^
/Users/rmann/Projects/Clients/NASA/FurnaceController/misc/mbpoll/src/mbpoll.c:1630:18: error: implicit declaration of function 'MIN' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        iFirst = MIN (iFirst, i);
                 ^
/Users/rmann/Projects/Clients/NASA/FurnaceController/misc/mbpoll/src/mbpoll.c:1677:23: error: implicit declaration of function 'MAX' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
          int iLast = MAX (iFirst, i);
                      ^
/Users/rmann/Projects/Clients/NASA/FurnaceController/misc/mbpoll/src/mbpoll.c:1678:20: error: implicit declaration of function 'MIN' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
          iFirst = MIN (iFirst, i);
                   ^
5 errors generated.
make[2]: *** [CMakeFiles/mbpoll.dir/src/mbpoll.c.o] Error 1
make[1]: *** [CMakeFiles/mbpoll.dir/all] Error 2
make: *** [all] Error 2

I fixed this by hacking in quick definitions:

inline int MIN(int a, int b) { return a > b ? b : a; }
inline int MAX(int a, int b) { return a > b ? a : b; }

But it felt a bit hacky and likely won’t compile on other platforms.

mbpoll built on OpenWRT

Hi epsilonrt,

I want to build mbpoll in OpenWRT system running on MTK MT7688 which is MIPS CPU.
How do you think it should be built to an OpenWRT package for mbpoll?

Thanks!

unable to compline on windows 10 using mingw64

Hi, I'm receiving the following issue when I try to make.

Admin@DESKTOP-JCBL1LK MINGW64 /c/Users/Admin/Desktop/mbpoll-master/mbpoll-master/build
$ make
[ 25%] Building C object CMakeFiles/mbpoll.dir/src/mbpoll.c.obj
/c/Users/Admin/Desktop/mbpoll-master/mbpoll-master/src/mbpoll.c:409:1: error: static declaration of ‘strlwr’ follows non-static declaration
409 | strlwr (char * str) {
| ^~~~~~
In file included from /c/Users/Admin/Desktop/mbpoll-master/mbpoll-master/src/mbpoll.c:19:
/usr/include/string.h:129:7: note: previous declaration of ‘strlwr’ was here
129 | char *strlwr (char *);
| ^~~~~~
make[2]: *** [CMakeFiles/mbpoll.dir/build.make:82: CMakeFiles/mbpoll.dir/src/mbpoll.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/mbpoll.dir/all] Error 2
make: *** [Makefile:171: all] Error 2
make error

Function codes

Thanks for the project!
It's very useful and easy to use. I have a question, the general options to read the values in this tool is not concordant with the function codes in classical Modbus function codes, is it?

In Modbus the function code 3 is to read holding register and 4 is to read input register, instead in the implementation of this tool the opcion -t 3 is for read input register data types and 4 is to read output holding register, that is, they are the other way around.

the same for -t 0/1 maybe would be better to use 1, 2, 3, 4 classic modes for modbus function codes

Static build - possible?

Is it possible to build mbpoll as static binary? I'd like to put it into docker container so single binary with libmodbus included would be best for me.

Support for INT64

As it is quite common now that meters are using INT64 and UINT64 registers it would be great if this dataformat can be supported by mbpoll options.

No support for the 05/bit operation?

Currently, it seems the mbpoll only support following types:
-t 0 Discrete output (coil) data type (binary 0 or 1)
-t 1 Discrete input data type (binary 0 or 1)
-t 3 16-bit input register data type
-t 3:int16 16-bit input register data type with signed int display
-t 3:hex 16-bit input register data type with hex display
-t 3:string 16-bit input register data type with string (char) display
-t 3:int 32-bit integer data type in input register table
-t 3:float 32-bit float data type in input register table
-t 4 16-bit output (holding) register data type (default)
-t 4:int16 16-bit output (holding) register data type with signed int display
-t 4:hex 16-bit output (holding) register data type with hex display
-t 4:string 16-bit output (holding) register data type with string (char) display
-t 4:int 32-bit integer data type in output (holding) register table
-t 4:float 32-bit float data type in output (holding) register table

Can we add the function of bit operation?

Adding a man page

I think it is very interesting that mbpoll has a man page. As I am not very efficient in English :-( I would be very happy if a volunteer could do the job starting from the help page de mbpoll.
It is possible to use a 'pull request' to do this.
Thank you.

Problem with Modbus RTU over RS485 - RTS signal

Hi all
Last time I was trying to use the "mbpoll" program in my setup. The "mbpoll" is installed on UpBoard (mostly compatible with RPi board), on the board there is a custom RS485 hat. The TX/RX pins of the UpBoard(RPi) are GPIO14/GPIO15 respectively, and the DE/RE pin of the 485 transmiter IC is connected to GPIO4. The UART port name in the UpBaoard system is /dev/ttyS4.

My question is - how to use mbpoll with the hardware RS485 data direction control? I know, that there is an option shown in the manual:

-R [#]        RS-485 mode (/RTS on (0) after sending)
                 Optional parameter for the GPIO RTS pin number
-F [#]        RS-485 mode (/RTS on (0) when sending)
                 Optional parameter for the GPIO RTS pin number

but i dont know, how exactly use it in command line. Lets say, I would like to use 2 mbpool commands with my MODBUS remote server (UpBoard is MODBUS Client/Master in this design):
mbpoll -1 -m rtu -a 1 -b 9600 -t 4 -P none -r 1 -c 12 /dev/ttyS4 - command to read the holding registers 1-12,
mbpoll -1 -m rtu -a 1 -b 9600 -t 4 -P none -r 1 /dev/ttyS4 -- 100 - write value 100 to register 1.

The command:
mbpoll -1 -m rtu -a 1 -b 9600 -R [4] -t 4 -P none -r 1 /dev/ttyS4 -- 100
gives me an error: mbpoll: Illegal data value /dev/ttyS4.

Do you have any suggestions?

Can't build with CentOS 7

I'm trying to build your tools on CentOS 7. I started by installed the libmodbus in yum, but realized it was too old. I then cloned v1.4 from your repo and built that.

Cmake wasn't finding libmodbus.so at all, so I hacked the CMakeLists.txt by commenting out the find package part and just put in /usr/local/lib for the link_dirs. Cmake then appeared to run correctly.

Followed up with make and getting errors:
>make Linking C executable mbpoll CMakeFiles/mbpoll.dir/src/mbpoll.c.o: In function vSigIntHandler: mbpoll.c:(.text+0x35): undefined reference to modbus_close mbpoll.c:(.text+0x41): undefined reference to modbus_free CMakeFiles/mbpoll.dir/src/mbpoll.c.o: In function vReportSlaveID: mbpoll.c:(.text+0x31e): undefined reference to modbus_set_slave mbpoll.c:(.text+0x363): undefined reference to modbus_report_slave_id mbpoll.c:(.text+0x45e): undefined reference to modbus_strerror CMakeFiles/mbpoll.dir/src/mbpoll.c.o: In function main: mbpoll.c:(.text.startup+0x5e0): undefined reference to modbus_new_tcp_pi mbpoll.c:(.text.startup+0x603): undefined reference to modbus_set_debug mbpoll.c:(.text.startup+0x63b): undefined reference to modbus_connect mbpoll.c:(.text.startup+0x697): undefined reference to modbus_set_response_timeout mbpoll.c:(.text.startup+0x750): undefined reference to modbus_read_registers mbpoll.c:(.text.startup+0x76f): undefined reference to modbus_strerror mbpoll.c:(.text.startup+0x7e6): undefined reference to modbus_set_slave mbpoll.c:(.text.startup+0x846): undefined reference to modbus_read_bits mbpoll.c:(.text.startup+0x899): undefined reference to modbus_read_input_bits mbpoll.c:(.text.startup+0x8b9): undefined reference to modbus_read_input_register' mbpoll.c:(.text.startup+0x8d6): undefined reference to modbus_set_slave mbpoll.c:(.text.startup+0x911): undefined reference to modbus_write_registers mbpoll.c:(.text.startup+0x930): undefined reference to modbus_strerror mbpoll.c:(.text.startup+0xa96): undefined reference to modbus_write_bits mbpoll.c:(.text.startup+0xaeb): undefined reference to modbus_new_rtu mbpoll.c:(.text.startup+0xb59): undefined reference to modbus_free mbpoll.c:(.text.startup+0xb65): undefined reference to modbus_strerror mbpoll.c:(.text.startup+0xc8c): undefined reference to modbus_write_bit mbpoll.c:(.text.startup+0xcad): undefined reference to modbus_write_register mbpoll.c:(.text.startup+0xdc7): undefined reference to modbus_rtu_set_serial_mode mbpoll.c:(.text.startup+0xdd9): undefined reference to modbus_rtu_set_rts collect2: error: ld returned 1 exit status make[2]: *** [mbpoll] Error 1 make[1]: *** [CMakeFiles/mbpoll.dir/all] Error 2 make: *** [all] Error 2

This seems like the modbus.h header is missing but it's in /usr/local/include/modbus.

Any help is appreciated, I think your tools will help me avoid Windows apps.
TIA

ERROR Illegal function. help!

Hi All,

Im trying to get data from Circuitor CEM-C6-MID.

The address is

Voltage addres: 0131
Function 03

my command is

mbpoll -a1 -r313 -b9600 -t4int -c20 -mrtu -F2 -Pnone /dev/ttyS2 -l 500 -v

but it says
ERROR Illegal function Read input register failed: Illegal function -- Polling slave 1... Ctrl-C to stop) [01][04][00][58][00][02][F0][18] Sending request using RTS signal Waiting for a confirmation... <01><84><01><82><C0>

Any help?

Thanks!

start reference is off by -1

Hello,

Testing mbpoll with Victron Energry Color GX. The Victron Energry Color GX error logs shows
mbpoll 1.0-0 (Debian 1.4.11+dfsg-2~bpo10+1) starting reference (-r) is off by -1.
Example: ./mbpoll -1 -a 100 -t 3 -r 840 -c 1 192.168.10.180
mbpoll will starts at 839 not 840.

Fix source file mbpoll.c
change line 952~
iStartReg = ctx.piStartRef[j] - ctx.iPduOffset;
to
iStartReg = ctx.piStartRef[j];

Support for double precision float

This request is similar to #23. Some devices store values as 64-bit floating point in four consecutive registers, for example the Siemens PAC2200 energy meters store their demand/supply Wh values as double precision floats, so some -t 3:double type would be nice.

Register Addressing Bug

When I execute the following command, my server responds with the value of the first holding register (which is correct).

mbpoll <ip_address> -B -t 4:hex -r 1 -c1 -1

when I execute the following command, my server responds with the value of the second holding register (which is incorrect).

mbpoll <ip_address> -B -t 4:int -r 1 -c1 -1

Unless I'm mistaken, the request sent by mbpoll should be identical in both of these cases... the part after the colon should only affect how mbpoll parses the response, right?

mbpoll to simulate a Modbus slave?

I would like to use mbpoll in place of ModbusPal as a Modbus slave simulator for testing purposes. Is that possible? ModbusPal is GUI based, but my lightweight Ubuntu 16 Core OS does not allow GUI, which is why I like mbpoll since it runs from the command line. But when I try to simulate slave 1 writing value 42 to register 2 :

$ mbpoll -m tcp -p 502 -a 1 -r 2 -v 127.0.0.1 42 #port 502, slave 1, start reference aka register 2, value 42, verbose, generated from localhost

I get the error

mbpoll: Connection failed: Connection refused

I thought mbpoll could simulate a slave, because the output from it says "mbpoll 0.1-23 - FieldTalk(tm) Modbus(R) Master Simulator". Please tell me what command line parameters I should use. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.