How to do reconnection logic? #435
Replies: 1 comment
-
The reconnection of ADS (not just pyads) is not straightforward, I've often found it to be a little annoying. I normally have a heartbeat running that I can monitor on a notification (or in your specific case here you are just polling so that also works), then if I have an error I cause the program to have to be restarted. I understand this is not practical in every case. However, looking at your code I can't see anything inherently wrong, theoretically just trying to recreate the connection as you are doing should work. I suspect the 15 minute timeout error is being caused by the underlying ADS library or some python "cacheing" of the plc / pyads instance. What happens when you restart the python program, does it now just read ok? Could you try reloading pyads after the time out too, |
Beta Was this translation helpful? Give feedback.
-
After a long time disconnect with PLC, the python program in ubuntu can not reconnect to PLC.
The code run on ubuntu22.04 and python3.12. When PLC and python program is running, the variable can be read from PLC successfully.
If I turn off the PLC, the program will give the error message," ADSError: timeout elapsed (1861)". Then I turn on the PLC, the error will disappear and the variable can be read successfully.
However,if the PLC was turn off more then 15 minutes, the program will throw the error",Error: read frame failed with error: No route to host". Then I turn on the PLC, but I still can not read variable form PLC, the error is same as before.
The code is as following:
Beta Was this translation helpful? Give feedback.
All reactions