Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_connected returns true if the connection is lost #111

Open
EnricGarrigo opened this issue Jul 12, 2018 · 7 comments
Open

get_connected returns true if the connection is lost #111

EnricGarrigo opened this issue Jul 12, 2018 · 7 comments
Milestone

Comments

@EnricGarrigo
Copy link

EnricGarrigo commented Jul 12, 2018

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 EnricGarrigo changed the title get_connected returns true if the connection is broke get_connected returns true if the connection is lost Jul 12, 2018
@Steven1408
Copy link

Steven1408 commented Aug 1, 2018

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
Copy link
Owner

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
Copy link
Collaborator

spreeker commented Aug 2, 2018 via email

@gijzelaerr
Copy link
Owner

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
Copy link
Collaborator

spreeker commented Aug 2, 2018 via email

@DasLukas
Copy link

DasLukas commented Nov 6, 2022

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

I wonder where to place @N3mesisXS workaround?

@MountainKing91
Copy link

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

@gijzelaerr gijzelaerr modified the milestones: 1.3, 1.4 Jan 17, 2023
@gijzelaerr gijzelaerr modified the milestones: 1.4, 1.5 Oct 24, 2023
@gijzelaerr gijzelaerr modified the milestones: 1.5, 2.1 Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants