0
votes

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.

1

1 Answers

1
votes

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()