I'm having an issue with the python pymodbus3 module.
I have a modbus device and these two scripts:
pymodbus_tester.py
#!/usr/bin/env python
from pymodbus.client.sync import ModbusSerialClient
if __name__ == '__main__':
mdbcli = ModbusSerialClient(
method = "rtu",
parity = "N",
stopbits = 1,
bytesize = 8,
timeout = 1,
port = "/dev/ttyUSB0",
baudrate = "115200"
)
if not mdbcli.connect():
print("Could not connect to Modbus")
print("""
********************************************************************
***** SINGLE READ TEST *****
********************************************************************
""")
ret = mdbcli.read_input_registers(
address = 0x3104,
count = 1,
unit = 0x01
)
print("Single read: {0}".format(ret))
pymodbus3_tester.py
#!/usr/bin/env python3
from pymodbus3.client.sync import ModbusSerialClient
if __name__ == '__main__':
mdbcli = ModbusSerialClient(
method = "rtu",
parity = "N",
stopbits = 1,
bytesize = 8,
timeout = 1,
port = "/dev/ttyUSB0",
baudrate = "115200"
)
if not mdbcli.connect():
print("Could not connect to Modbus")
print("""
********************************************************************
***** SINGLE READ TEST *****
********************************************************************
""")
ret = mdbcli.read_input_registers(
address = 0x3104,
count = 1,
unit = 0x01
)
print("Single read: {0}".format(ret))
As you can see they are virtually identical, aside from the pymodbus module.
This is, however, what I get when I launch them (combined launch for simplicity):
griccardo@pc:~$ python pymodbus_tester.py ; echo "---------------" ; python3 pymodbus3_tester.py
********************************************************************
***** SINGLE READ TEST *****
********************************************************************
Single read: ReadRegisterResponse (1)
---------------
********************************************************************
***** SINGLE READ TEST *****
********************************************************************
Single read: None
On the device side, I receive the same request and output the same response in both cases, as you can see from the following log (kinda):
REQ: '1~�'
RES: '�0'
REQ: '1~�'
RES: '�0
Is something off with the pymodbus3 module? Or am I using it wrong?
Thank you, Riccardo