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

Run ADS Client on WSL through localhost #190

Open
captain-yoshi opened this issue Feb 22, 2023 · 3 comments
Open

Run ADS Client on WSL through localhost #190

captain-yoshi opened this issue Feb 22, 2023 · 3 comments

Comments

@captain-yoshi
Copy link

captain-yoshi commented Feb 22, 2023

Is it possible to run the ADS Client on a windows subsystem linux (WSL) which communicates through the localhost ? FYI it works when installing the client on a remote PC using the same linux distribution as the WSL (Ubuntu 20.04).

Maybe related to #93 and #141.

ADS Route

image

Client Config

static void runExample(std::ostream& out)
{
    static const AmsNetId remoteNetId { 192, 168, 0, 193, 1, 1 };
    static const char remoteIpV4[] = "192.168.0.193";

    // uncomment and adjust if automatic AmsNetId deduction is not working as expected
    // Tried with and without this line below
    // bhf::ads::SetLocalAddress({192, 168, 0, 193, 1, 1});
    ...
}

Running the Client Example

~$ ./example/build/example
# Nothing for 5 seconds and then :
2023-02-22T15:04:20-0500 Info: connection closed by remote
Error: 1861
AdsException message: Ads operation failed with error code 1861.

Wireshark Debug (loopback adapter)
wireshark-capture.zip

image

@pbruenn
Copy link
Member

pbruenn commented Feb 28, 2023

TwinCAT doesn't expect TCP connections from localhost. Especially, when you use the same AMS NetId as Target and Sender address. So at least you have to use different AMS NetIds for the TwinCAT server (in outside Windows) and your ADS Client (inside WSL). Then it depends on WSL networking, which I have no clue about. If on the TwiNCAT side the connections looks like a normal remote host, then it should work as soon as you configured the AMS route correctly. If TwinCAT receives a TCP connection attempt from an IP it is listening itself I doubt it will work.

@captain-yoshi
Copy link
Author

captain-yoshi commented Mar 1, 2023

No luck with different AMS NetId... WSL networking has it's own considerations.

I think WSL1 gives you a localhost network only. WSL2 gives you a virtual network that you can configure but needs Hyper-V which is not compatible with TwinCAT in run-mode.

I did not try changing my TwinCAT Local NetId to localhost... Maybe that would work.

It works through VirtualBox and remotly, so really not a big issue for me.
Thanks for the library ! Very handy 👍

@klauer
Copy link

klauer commented Oct 13, 2023

I think the author of a nodejs ADS client figured out what's necessary for localhost communication - reservation of a port on the router. This has since been at least partially propagated to the rust client ads-rs (though I'm not sure if it cleared the reserved port after use). It should work for WSL1 with localhost networking, though WSL2 is a different story as you've noted.

Since this is technically possible over ADS, I wonder if it's something that might be accepted for Beckhoff's open source library here. Even some official acknowledgment/documentation of the underlying mechanism would be nice, too.

Links:

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

3 participants