0

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.

David Zwart
  • 431
  • 5
  • 23

1 Answers1

2

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.

stevenv
  • 411
  • 3
  • 11
  • I cannot accept this answer for now, because an answer based on experience would be more practical. By the way, to me it seems counterintuitive that ADS would send the same data twice to 2 processes, which run on the same ip-address. Don't you agree that ip-address is the only thing for the TwinCAT system to differentiate between devices? – David Zwart Jan 24 '17 at 16:50
  • 1
    PyAds is just a thin wrapper around TcAds, which I have been using in .NET for over 5 years, if you want an answer based on experience :) Perhaps you can read more about TCP/IP to understand how the communication between the ADS client and the TC system works and how the TC system can differentiate between multiple connections coming from the same IP. For example, the answer here: http://stackoverflow.com/questions/3329641/how-do-multiple-clients-connect-simultaneously-to-one-port-say-80-on-a-server If you're still in doubt, you can always write some sort of prototype to (dis)prove it. – stevenv Jan 31 '17 at 18:36
  • Thanks dude, please upvote my question if you think it was good enough. – David Zwart Jan 02 '18 at 12:55