@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
:
# 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
:
# 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. https://github.com/favalex/modbus-cli (assumes parity=none)