ENH: proof-of-concept for opening a local port #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
This is a proof-of-concept for allowing ADS clients to talk to localhost by way of requesting a unique AMS/ADS port from the ADS router itself.
Preliminary success
Paired with pcdshub/twincat-ads#12 and ads-ioc, these changes allowed for an unmodified rhel7-x86_64 (Linux) ads-ioc binary, running on TwinCAT BSD with the LinuxEmu layer enabled, to successfully communicate with localhost and serve PVs. 🎆
Sample PLC project and IOC used to verify this:
Note
Note that we (at PCDS) are way behind the upstream Beckhoff/ADS. As the upstream has significantly diverged from our fork, this effort would need to be redone entirely were we to ever sync/upgrade.
Changes
A few changes were necessary:
AdsPortOpenLocalEx
was added to perform this request. It needs to be called prior to any other ADS calls when the client recognizes that it is talking to localhost.Prior to this PR
Prior to this PR, the ADS library picks a port on its own and continues with it.
AdsPortOpenEx()
) merely reserves an integer AMS port ID locally and uses that for future communication ("request port ID, use that port ID to talk to AMS Net ID 8.8.8.8.1.1 port PLC_TC3 and read data from it").ADS/AdsLib/AmsRouter.cpp
Lines 86 to 96 in 743a15a
Beyond a prototype
A few things to move this out of the prototype stage would include:
Recv()
startup delay and replace it with some better thread-safe mechanism to only wait when necessary (or perhaps build the "wait for local port packet" into theAmsConnection
class somehow)local
AmsPort
bool because I didn't end up using itAdsPortOpenEx()
: port XAdsPortOpenLocalEx()
is called to communicate with localhost, and this port number is identical to that from the previous step (somewhere around a probability of 1/65535....)