python-opcua icon indicating copy to clipboard operation
python-opcua copied to clipboard

How to catch server restart event

Open Stefan97dk opened this issue 8 years ago • 8 comments

Hi!

I'm new to Python and Opcua, but I managed to connect to a third party opcua server and read some data. I also added a datachange_notification for some PLC tags and it works fine. When I restart my Opcua server the program execution stops with error. I need to catch the restart event of the server and try connecting again programatically?

Thnx in advance

Stefan97dk avatar Jul 23 '18 09:07 Stefan97dk

I don't remember exactly, but I think automatic reconnect is not implemented. You might need a work around that just tries to reconnect ever 20 seconds or something.

zerox1212 avatar Jul 23 '18 13:07 zerox1212

@zerox1212 thnx alot for ur response. Indeed, that can be a workaround, but I need to test connection status prior to trying reconnect, any hint how to do this test?

Stefan97dk avatar Jul 23 '18 17:07 Stefan97dk

I don't know. Maybe you can use discovery functions. I have never used them.

zerox1212 avatar Jul 23 '18 17:07 zerox1212

Anyone has a hint, would be much appreciated.

Stefan97dk avatar Jul 25 '18 19:07 Stefan97dk

The only solution, and the one used by other clients is to poll the server every second or so, in a thread for example, and disconnect/reconnect if necessary. Do

oroulet avatar Jul 25 '18 19:07 oroulet

@oroulet Thank u very much for the hint. I did try your suggestion by reading a node every second, and I got an exception when I restart the server, and I just catch the exception and try to re-start my application programatically. The issue is that network event datachange_notification, it doesn't give any exception when the server is been restarted, and the application crashes.

Stefan97dk avatar Jul 26 '18 06:07 Stefan97dk

Solved. Try Except Finally!

Stefan97dk avatar Aug 01 '18 08:08 Stefan97dk

Hi @stefan97dk could you please post your working example? thanks

jkbngl avatar Feb 22 '20 09:02 jkbngl