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

get_connected returns true if the connection is lost

Open EnricGarrigo opened this issue 7 years ago • 8 comments

I tested with Python 3.6 and Windows 7 64 bit. I have a 'While True' loop for test the connection continuously. If when the program starts the connection is OK, 'get_connected' returns 'true' and the loop runs. If the connection is broken during execution, 'get_connected' still returns 'true' and db_write crashes.

Does anyone know who avoid this behaviour?

Thanks.

EnricGarrigo avatar Jul 12 '18 07:07 EnricGarrigo

I can confirm, had to use If str(plc.get_cpu_state()) == "S7CpuStatusRun": Works like charm but feels ghetto.

get_Connected() returns False when you run plc.disconnect() but not when disconnected from the Network, still writes True.

Python 2.7, Debian, snap7-1.2.1 and the wrapper.

Steven1408 avatar Aug 01 '18 07:08 Steven1408

since python-snap7 is a thin wrapper around snap7, this is actually a bug in the snap7 lib. So the long-term solution is to report it upstream. The only problem is that last time I checked the project is not really maintained anymore, so that fix might never happen.

I could add @N3mesisXS's suggestion to python-snap7, but I'm not sure if that works correctly for all other users. So @EnricGarrigo, for now, I suggest adding this check to your code and see if that solves the problem.

gijzelaerr avatar Aug 02 '18 08:08 gijzelaerr

davide is doing his best to maintain it right? I think he will fix it if you report it :)

On Thu, Aug 2, 2018 at 10:26 AM, Gijs Molenaar [email protected] wrote:

since python-snap7 is a thin wrapper around snap7, this is actually a bug in the snap7 lib. So the long-term solution is to report it upstream. The only problem is that last time I checked the project is not really maintained anymore, so that fix might never happen.

I could add @N3mesisXS https://github.com/N3mesisXS's suggestion to python-snap7, but I'm not sure if that works correctly for all other users. So @EnricGarrigo https://github.com/EnricGarrigo, for now, I suggest adding this check to your code and see if that solves the problem.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gijzelaerr/python-snap7/issues/111#issuecomment-409848165, or mute the thread https://github.com/notifications/unsubscribe-auth/AADpMbh3HKdMu6I5wUGoMD5v9-WjAeZgks5uMrfBgaJpZM4VMT8l .

spreeker avatar Aug 02 '18 08:08 spreeker

there have been no commits to the repo for more than a year...

@EnricGarrigo if you could report the issue upstream and link back here that would be useful.

gijzelaerr avatar Aug 02 '18 10:08 gijzelaerr

Luckily PLC's are made to run for 25 years or so. :). Interfaces do not change much. They have improved encryption on the newer models which are slowly very slowly being deployed..

On Thu, Aug 2, 2018, 12:11 Gijs Molenaar [email protected] wrote:

there have been no commits to the repo for more than a year...

@EnricGarrigo https://github.com/EnricGarrigo if you could report the issue upstream and link back here that would be useful.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gijzelaerr/python-snap7/issues/111#issuecomment-409877386, or mute the thread https://github.com/notifications/unsubscribe-auth/AADpMZ8V44BpwT-1wLyCyTaAvQmXK4C_ks5uMtBFgaJpZM4VMT8l .

spreeker avatar Aug 02 '18 11:08 spreeker

Hey everyone. Something new here? I need to check if the Logo reachable.

I wonder where to place @N3mesisXS workaround?

DasLukas avatar Nov 06 '22 19:11 DasLukas

My workaround for this situation is to:

  1. in the read loop I check the connection status before reading, if not connected I try to connect
  2. catch the read/write exception and disconnect the client. At that point get_connected will return false, so when checking the connection in the read loop (1) i will know I have to reconnect This is also how Davide does in some examples (not in python).

MountainKing91 avatar Nov 20 '22 13:11 MountainKing91