# Modbus openHAB2 binding available for alpha testing

**URL:** <https://community.openhab.org/t/modbus-openhab2-binding-available-for-alpha-testing/27657>\
**Category:** Bindings\
**Tags:** openhab2-addons, modbus, binding\
**Created:** [May 1, 2017, 7:05pm UTC](https://community.openhab.org/t/modbus-openhab2-binding-available-for-alpha-testing/27657 "2017-05-01T19:05:40Z")\
**Posts on this page:** 1\
**Showing post:** 272

<div class="post-metadata">

**Author:** ![ssalonen](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@ssalonen](https://community.openhab.org/u/ssalonen)\
**Post date:** [January 11, 2018, 7:15pm UTC](https://community.openhab.org/t/modbus-openhab2-binding-available-for-alpha-testing/27657/272 "2018-01-11T19:15:01Z")

</div>

@narf27 hmm I think you are right ☹ modpoll does not work with raspi and mbpoll only supports TCP slaves…

Not sure what to advice. We have seen slaves that do not answer to some specific requests, perhaps this is similar case. Can you read in two parts (two registers + two registers)?

Is there anything in device documentation regarding some limitations with respect to requests?

Edit : realized you previously used the old binding (successfully?) to read values. Please ensure that the serial port parameters are correct. I am curious if you find a case which worked before but anymore.

EDIT2: @narf27 here are two examples using python libraries `pymodbus` and `minimalmodbus`

These should work with python 2.7 or higher. The only trick is to install dependencies for these scripts (`pymodbus` or `minimalmodbus`). Hope you get the idea and adjust the scripts accordingly.

**`test_pymodbus.py`** :

```python
# Installation
# - install dependencies:
# pip install pymodbus six
# or 
# easy_install pymodbus six
# Running script:
# python test_pymodbus.py

from pymodbus.client.sync import ModbusSerialClient

# https://github.com/riptideio/pymodbus/blob/master/pymodbus/constants.py
port = '/dev/pts/3'
baudrate = 38400
stopbits = 1
bytesize = 8
parity = 'N' # 'E', 'O' or 'N'

address = 0
count = 5
unit = 1

slave = ModbusSerialClient(method='rtu', 
                           port=port, 
                           baudrate=baudrate, 
                           stopbits=stopbits, 
                           bytesize=bytesize, 
                           parity=parity)
out = slave.read_holding_registers(address, count, unit=unit)
 
print('%s: %s' % (out, out.registers))

```

**`test_minimalmodbus.py`** :

```python

# Installation
# - install dependencies:
# pip install minimalmodbus
# or 
# easy_install minimalmodbus
# Running script:
# python test_minimalmodbus.py

import minimalmodbus
import serial

unit = 1
address = 24
count = 1

port = '/dev/pts/3'
baudrate = 38400
stopbits = 1
bytesize = 8
parity = serial.PARITY_NONE

slave = minimalmodbus.Instrument(port, unit)

slave.serial.port # this is the serial port name
slave.serial.baudrate = baudrate # Baud
slave.serial.bytesize = bytesize
slave.serial.parity = parity
slave.serial.stopbits = stopbits

print(slave.read_register(address, count))

```

There are others as well, e.g. [GitHub - favalex/modbus-cli: Command line tool to access Modbus devices](https://github.com/favalex/modbus-cli) (assumes parity=none)

---

_[View the full topic](https://community.openhab.org/t/modbus-openhab2-binding-available-for-alpha-testing/27657)._
