Closed joshgraff-planted closed 2 years ago
This is just a guess/question: How many ADS connections do you have from the client (the WSL box) to the PLC ? There can only by one: If you run TwinCAT.exe at the same time as you run the pyads code: The ADS router on the PLC gets confused. Solution: Close TwinCAT.exe while using pyads on the same machine.
Your comment makes me think of the issues I've been having executing my pyads code from the same PC (on localhost). I'll open another issue for that, though, as it doesn't seem to apply to this issue.
Interesting suggestion. My architecture is as below, one PC with WSL and Pyads connected to another with Windows and TwinCAT. PC (Windows, Pyads on WSL) - > PC (Windows, TwinCAT) There isn't a TwinCAT.exe running on the twincat PC, not that I can see anyways; I have TCshell and the PLC execution service running though; I tried closing the shell/IDE and it didn't have an impact on the issue I show here.
One thing that did solve this issue was to not open a connection on every iteration, but instead to keep the connection open between iterations of the code. I'm running a test now, and it shows 0 failures for a few hours now (even with Timeout set lower than the delay between executions, so I'm not sure what exactly it measures to keep the connection open.)
I've attached my code here in case someone comes across this issue in the future. test_pyads.txt
I get intermittent failures on my pyads connection to the PLC. ~%20-%30 fail in this way five times in a row. connecting to: <AmsAddress 192.168.10.145.1.1:851> connected to: <AmsAddress 192.168.10.145.1.1:851> on Port: None ADSError: timeout elapsed (1861). 2022-05-16T14:51:21-0700 Info: connection closed by remote
New user, it took me a few days to figure out connections. I have a windows PC running TC3, connected over ethernet to a windows PC running windows Subsystem for Linux, with python version Python 3.8.10. The TC3 ADS router is configured:![image](https://user-images.githubusercontent.com/105249101/168684788-d0d5697e-90a3-4573-adc1-a17a48dfd426.png)
simplified code (full program attached): plc = pyads.Connection(ads_addr, 851) with plc: plc.open() try: actual_pos = plc.read_by_name except pyads.pyads_ex.ADSError: plc.close()
My entire code is attached, but the test script essentially calls the ADS system at irregular intervals 100 times. I found that on any given run, ~%20-%30 fail in this way. The pattern is similar every time, the code will fail exactly five times, and then succeed for a seemingly random number of attempts. I'm not quite sure what's going on, or where to look; I'm pretty sure my code is very similar to the examples. When I use the "example_09.cpp" provided on infosys, I don't see the same issue.
test_pyads.txt
This is actually my first github issue, too (I've read many of them), so if I should change my strategy in the future, that would also be helpful.