0

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

Guerriky
  • 529
  • 1
  • 5
  • 15
  • can you the official pymodbus and try ? `pip3 install pymodbus==1.3.0.rc2`. Note the pymodbus official pip installable supports both python2 an python3. https://pypi.python.org/pypi/pymodbus – Sanju Jun 23 '17 at 04:50
  • Hello, @Sanju. I tried that, but it didn't work. I get a TypeError in the pymodbus library itself. – Guerriky Jun 23 '17 at 08:24
  • could you paste the error traceback here ? also you can enable the logging and check the logs for the packet transmission and receive. `import logging logging.basicConfig() log = logging.getLogger() log.setLevel(logging.DEBUG)` – Sanju Jun 23 '17 at 12:19
  • btw, the I could see that you are passing the baudrate as a string, you need to pass it as an int to avoid type error. – Sanju Jun 23 '17 at 12:25

0 Answers0