birkenfeld / ads-rs

Rust crate to access PLCs via the Beckhoff ADS protocol
https://crates.io/crates/ads
Apache License 2.0
40 stars 8 forks source link

Trouble connecting to remote PLC #14

Closed LB767 closed 1 year ago

LB767 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

birkenfeld commented 1 year ago

Ok, thanks for the feedback!

LB767 commented 1 year ago

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?