gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
643 stars 245 forks source link

get_connected returns true if the connection is lost #111

Open EnricGarrigo opened 6 years ago

EnricGarrigo commented 6 years ago

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.

Steven1408 commented 6 years ago

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.

gijzelaerr commented 6 years ago

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.

spreeker commented 6 years ago

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 notifications@github.com 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 .

gijzelaerr commented 6 years ago

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.

spreeker commented 6 years ago

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 notifications@github.com 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 .

DasLukas commented 1 year ago

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

I wonder where to place @N3mesisXS workaround?

MountainKing91 commented 1 year ago

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).