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

Trouble connecting to remote PLC #14

Closed
LB767 opened this issue Apr 26, 2023 · 5 comments
Closed

Trouble connecting to remote PLC #14

LB767 opened this issue Apr 26, 2023 · 5 comments

Comments

@LB767
Copy link

LB767 commented Apr 26, 2023

Hello,

I've been banging my head against a wall having problems connecting to a remote Twincat with ADS.
Just copy pasting the example code always ends up failing at device.get_state() with error Io("receiving reply (route set?)", Kind(UnexpectedEof))'

Here is my code:

let client = ads::Client::new(("138.131.232.36", ads::PORT), ads::Timeouts::none(), ads::Source::Auto).unwrap();
let device = client.device(ads::AmsAddr::new([138, 131, 232, 36, 1, 1].into(), 851));
println!("{:?}", device.get_state().unwrap().0);

For reference, here is the ADS route set on my side (client)
image
and the route on the PLC side
image

I've seemingly tried everything but cannot get it to work, and every time I run the code above the route in TwinCAT stops showing "connected", if that means anything...

Weirdly, this works totally fine with another PLC I have and the only difference I've been able to find is that this one has a fixed IP instead of being set through DHCP.

Any help would be welcome...

@LB767
Copy link
Author

LB767 commented Apr 27, 2023

It seems the connection works fine if I force my laptop to use wifi, if I go through its ethernet card it doesn't work... I have no idea why...

@birkenfeld
Copy link
Owner

Hi, sorry that you got stuck in the TwinCAT routing hell. Been there, done that...

One thing I noticed is that the NetID/address pairs in your two screenshots seem odd. It seems to indicate that the PLC is 138.131.232.36.1.1 (which is also the NetID you use in the code snippet) but at IP 138.131.232. 39 (which is not the IP you use in the code snippet).

@LB767
Copy link
Author

LB767 commented May 2, 2023

Ah yes, it was after a long day of debugging and I guess I typo-ed the IP address in my snipet... Eitherways I tested it with the correct IP or just hostname and it made zero difference.
Considering the connection works just fine through wifi, and connecting to another PLC works fine as well, I can only assume it must be some weird router/firewall blocking going on somewhere.

I'll close the issue for now and report back if I ever find something relevant.

@LB767 LB767 closed this as completed May 2, 2023
@birkenfeld
Copy link
Owner

Ok, thanks for the feedback!

@LB767
Copy link
Author

LB767 commented Jun 9, 2023

I'm still having weird problems with this... the other day I kept having this panic when trying to read a variable after connecting
Io("sending request", Os { code: 10058, kind: Uncategorized, message: "A request to send or receive data was disallowed because the socket had already been shut down in that direction with a previous shutdown call." })'
And seemingly after some time out of nowhere it started working without issue...
Any clue what this error might indicate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants