Beckhoff / TF6000_ADS_DOTNET_V5_Samples

Sample code for the Version 6.X series of the TwinCAT ADS .NET Packages
https://infosys.beckhoff.com/content/1033/tc3_ads.net/9407515403.html?id=6770980177009971601
BSD Zero Clause License
39 stars 16 forks source link

Are the Ads Client and Server implementation in the .NET 6 nugets compatible with TwinCAT 3.1.4024.32 router? #42

Closed odalet closed 1 year ago

odalet commented 1 year ago

I'm in the process of porting some ADS client and server code from the legacy v4 to the new v6 nuget packages (exact version is 6.0.216) and... I have issues with ports:

My initial setup (before porting) is:

image

Everything works (and did for years).

Now let's say I've ported my client and server code to use v6 nugets.

When running my server I'm greeted with this error:

Error starting ADS Server (AdsAms Error: None): AmsConnect: Cannot register Port '44496' (Error: ClientPortNotOpen)
TwinCAT.Ads.Server.AdsServerException: AmsConnect: Cannot register Port '44496' (Error: ClientPortNotOpen)

If I change my server port to 25000 (as indicated in Ads Server example code), my server starts, my client connects and everything works again (still using the Twincat 3.1.4024.32 router).

Then I conducted another experiment: I stopped the Twincat 3.1.4024.32 router and instead ran a custom router based on Beckhoff.TwinCAT.Ads.TcpRouter nuget (my code is a copy/paste of the sample found in this reposirory)

With this setup (that is: everything built atop the v6 nugets) both my server and client communicate and what's more I can use either the 25000 or the original 44496 port for my server!

However if I try to use the same client code but compiled against the v4 nuget, things stop working (my write request reaches the server, but it seems the router fails to send the response back to the client...)

Any idea why I'm witnessing all these discrepancies? The ADS/AMS protocol should not have changed or did it? I really wish:

I hope someone can help me on this. Regards.

soberschmidt commented 1 year ago

Unfortunately you have to change the number. Ports >= 32768 (0x8000) are reserved by the system. Custom server ports can be freely choose within the port range of 26000-26999.

odalet commented 1 year ago

I suppose you mean 25000 and not 26000, but still this does not explain the behavior differences.

Using a port > 32768

If ports > 32768 are reserved how do you explain it works in the two first scenarios above? I'm sorry but this makes no sense to me. I don't even understand what part of the code prevents this: clearly the v6-nugets are not checking the port range otherwise the 2nd scenario would not work. And the XAE/XAR router does not either because if it did then the 1st scenario wouldn't work either. I can only think there is a difference in how a server is registered against a router between the v4- and the v6- nugets. Can't you just have the v6 code be consistent with the v4 one?

soberschmidt commented 1 year ago

Port range 25000 - 25999 are reserved for 3th party ADS servers and can be registered at Beckhoff. Port range 26000 - 26999 can be used in private networks

Ports > 32768 are reserved for ADS clients and are handle differently. Even if you had no issue with v4 in the past. This is not a supported scenario and can lead to other side effects. Please use a port in the range of 26000-26999 or register an official port.

odalet commented 1 year ago

Hi and thanks for the detailed explanation. Can you point me to some official documentation explicitly explaining those port ranges? I may have missed something but I found nothing of the sort on the official Beckhoff website.

RalfHeitmann commented 1 year ago

Unfortunately this isn't documented yet (I actually added the information, it will be online in future).