pythonpython-multiprocessingtwincatethercat

Use pyads library in multiple python processes in parallel


I've imported pyads (Python lib to communicate through the TwinCAT library with TcAdsDll.dll. I've read here that this library has multi-threading capability.

Is it also possible to use the pyads library in multiple processes without conflict?

To avoid conflict, I have considered making a pyads wrapper which shares the ADS data to multiple Processes with multiprocessing and queues, but it would be quite some work compared to just perform:

# process1:
pyads.open_port()
self.adr = pyads.AmsAddr('192.168.2.11.1.1', 851)
data = pyads.read_by_name(adr, args)

And in a similar process:

# process2:
pyads.open_port()
self.adr = pyads.AmsAddr('192.168.2.11.1.1', 851)
data = pyads.read_by_name(adr, args):

Just running pyads.open_port() in multiple processes throws no error. I hope someone can tell me if I would receive the same data in both processes without conflicts/prioritizing.

[Edit:] We implemented our system by multiprocessing and sharing data between processes to avoid having to risk sync-problems. This works flawlessly, but introduces some dataflow and programming overhead.


Solution

  • From what I can see in the pyads source code and based on what I know about the TcAds dll, you should be fine with your two processes making their own connection. You can have many client simultaneous connections to a TwinCAT system. The ADS router will ensure proper synchronization of data communication.