2

I'm perusing the pyModbusTCP with the intent of writing a Modbus slave running on Linux.

[begin rant]: pyModbusTCP uses the terms "client" and "server" instead of "slave/master", so the docs are a bit confusing. [end rant]

It seems all they do in the demos is use the library as a Master, either reading or writing from remote slave devices.

Is it possible to set up pyModbusTCP to act as a Modbus slave, listening to a port and allowing Modbus devices (PLCs, etc) to connect and read/write values from/to this slave?

As a bonus, is it possible to automatically execute a Python function (like an event) when a remote master reads or writes to/from this slave?

Thanks!

Ryan Griggs
  • 2,457
  • 2
  • 35
  • 58

1 Answers1

2

pyModbusTCP can work as Modbus slave. They call it “server”, you can find a simple example here http://pymodbustcp.readthedocs.io/en/latest/examples/server.html

Regarding your last question it looks like it’s not possible out of the box, but the source code looks relatively simple, maybe you can modify it. Specifically look at the DataBank class here https://github.com/sourceperl/pyModbusTCP/blob/master/pyModbusTCP/server.py

algrid
  • 5,600
  • 3
  • 34
  • 37
  • Thanks for the clarification. Basically, "server" == "modbus slave", right? Also, does this simply expose a blank set of modbus memory locations which can be read/written? Where are these stored in the system? in a database? in a file? do they persist a restart of the process? – Ryan Griggs Apr 30 '18 at 19:27
  • 1
    @RyanGriggs Yes, in this context “server” is “modbus slave”. Regarding that DataBank - as far as I can see it is very simple and stores all the data in memory, no persistence. You would have to replace it if you need something more involved than that. – algrid Apr 30 '18 at 19:54
  • @RyanGriggs if you want to control how the data is stored refer [pymodbus](https://github.com/riptideio/pymodbus). It comes with a variety of options for you to choose on how to store the data (sql/redis/memory etc). And if something is not available meeting your requirement, you can easily extend it as well. Refer http://pymodbus.readthedocs.io/en/latest/source/example/synchronous_server.html , https://github.com/riptideio/pymodbus/tree/master/examples/common , http://pymodbus.readthedocs.io/en/latest/source/library/pymodbus.datastore.html – Sanju May 02 '18 at 04:43
  • I wasn't aware pymodbus supported TCP. Thanks for this info. – Ryan Griggs May 02 '18 at 05:31