0

I'm trying to read/write some registers to some modbus devices. My software uses Python 3.4 and Twisted, so I wanted a library that integrates with such stack and allows async communications.

I'm trying to use pymodbus to implement a modbus serial client, but the library doesn't seem to offer a ModbusSerialClient anymore?

The following code:

from pymodbus.client.async import ModbusSerialClient as ModbusClient

Will raise an ImportError on Python 3.4 with pymodbus 1.4.0.

Standard examples use ModbusClient with connectTCP, but Twisted doesn't offer a serial endpoint yet.

I've seen there's a StartSerialServer, but it's not clear to me whether and how I could use it.

I'd like to either get a syntax for reading/writing registers via pymodbus, or have suggestion for another working library, as long as it works on Linux with a tty, Python 3.x and Twisted.

Alan Franzoni
  • 3,041
  • 1
  • 23
  • 35

1 Answers1

1

You can connect to a serial port using Twisted like this:

from twisted.internet.serialport import SerialPort
from twisted.internet import reactor

port = SerialPort(protocol, deviceName, reactor)

pymodbus offers a modbus protocol. So in the above, protocol should be:

from pymodbus.client.async import ModbusClientProtocol

protocol = ModbusClientProtocol()
Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • Yes, it is working, it wasn't that difficult. I still wish Twisted would implement a proper serial endpoint... work on that branch seems stalled. Thanks! – Alan Franzoni Mar 27 '18 at 15:46