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

how to recover from an intermittent TCP timeout exception #70

Open
tmcolby opened this issue Feb 27, 2017 · 8 comments
Open

how to recover from an intermittent TCP timeout exception #70

tmcolby opened this issue Feb 27, 2017 · 8 comments
Milestone

Comments

@tmcolby
Copy link
Contributor

tmcolby commented Feb 27, 2017

What is the proper way to recover from a snap7 exception ISO : An error occurred during recv TCP : Connection timed out?

If I place a db_read() into a try/except clause to keep the application from aborting on TCP timeout, subsequent db_read() become out of sync. It seems somewhere the calls are queued. Probably in the native snap7 thread.

For example: If I have three locations I am reading from a PLC
3,260,4 contains value 100
3,272,4 contains value 200
1,104,4 contains value 300

-the first db_read(3,260,4) call successfully returns a value 100
-second db_read(3,272,4) call times out with TCP timeout exception
-third db_read(1,104,4) call will return value 200 (Not 300 like you would expect)
..
-a fourth call of db_read(3,260,4) will return the value from the third call above (300)

It seems the method calls get spooled into a queue and for every call that times out, the data returned will be delayed that many calls in the future.

Is there a way to throw away the buffer on a tcp timeout? Or is there some other philosophical approach I should be taking? It seems very dangerous to call a function with specific arguments and get the wrong data back. Thanks for any suggestions.

@gijzelaerr
Copy link
Owner

hm, interesting. To be honest, I don't know. python-snap7 is just a thin wrapper around the snap7 library, I think we need to ask the original snap7 author what the idea behind this is. Can you open an issue on the snap7 bugtracker, and keep this issue updated?

@tmcolby
Copy link
Contributor Author

tmcolby commented Feb 27, 2017 via email

@gijzelaerr gijzelaerr self-assigned this Mar 2, 2017
@tmcolby
Copy link
Contributor Author

tmcolby commented Mar 2, 2017

See the discussion on sourceforge

I duplicated the issue I was having with my python application by replicating it in C. Apparently there are certain types of error's, a TCP timeout being one of them, that require a re connection to the plc. Davide is very responsive. Big thanks for his support.

@gijzelaerr
Copy link
Owner

ok great. So can we close this issue?

@tmcolby tmcolby closed this as completed Mar 3, 2017
@lautarodapin
Copy link
Contributor

See the discussion on sourceforge

I duplicated the issue I was having with my python application by replicating it in C. Apparently there are certain types of error's, a TCP timeout being one of them, that require a re connection to the plc. Davide is very responsive. Big thanks for his support.

Could you replicate the code to handle the error? I'm having hte same issue.

@spreeker
Copy link
Collaborator

We should add some connection checks / handle network errors properly.

void CheckConnection()
{
    while(!ChannelStatus)
    {
        ChannelStatus=CliConnect();
        if (!ChannelStatus)
            SysSleep(1000);         
    }
}

bool TcpError(int Error)
{
    return (Error & 0x0000FFFF)!=0;
}

@spreeker spreeker reopened this Feb 23, 2021
@gijzelaerr gijzelaerr added this to the 1.3 milestone Oct 20, 2021
@gijzelaerr gijzelaerr removed their assignment May 25, 2022
@Momoben3434
Copy link

Do you found a solution for this issue as I have a similar issue . Please advise ?

@gijzelaerr gijzelaerr modified the milestones: 1.3, 1.4 Jan 17, 2023
@jarkowski
Copy link

Same here. I would like to implement something like a timeout that I can pass with the connect.

My skills are limited, but what i have in mind is something like this:

siemens_logo_plc.connect(logo_ip, TSAP_CLIENT, TSAP_SERVER, timeout)

Currently, I wrap the connect in Try,Except. That is working, but not an elegant solution.

@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