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

FIX/ENH: local mode based on nodejs implementation #40

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

klauer
Copy link
Contributor

@klauer klauer commented Jul 28, 2023

Description

Enable client communication with the ADS server running on localhost for TwinCAT BSD systems.

Motivation and Context

(*) If we want to get ads-ioc working on TwinCAT/BSD through linuxemu we're going to have to replicate this there somehow.

How Has This Been Tested?

  • Only briefly on a TcBSD VM

Where Has This Been Documented?

This PR

Screenshots (if appropriate):

[TCBSD: RUN] [Administrator@test-plc-01  ~]$ ~/.local/bin/ads-async --log DEBUG get --our-net-id 127.0.0.1.1.1 --net-id 192.168.2.193.1.1 127.0.0.1  MAIN.iCount
DEBUG:ads_async:main(**{'host': '127.0.0.1', 'symbols': ['MAIN.iCount'], 'net_id': '192.168.2.193.1.1', 'add_route': False, 'our_net_id': '127.0.0.1.1.1', 'our_host': '127.0.0.1', 'timeout': 2.0})
DEBUG:ads_async.protocol:Connecting...
DEBUG:ads_async.protocol:Connected
DEBUG:ads_async.protocol:Reserved local connection settings from router: 192.168.2.193.1.1 (port=15945)
DEBUG:ads_async.protocol:AmsTcpHeader(reserved=0, length=60)
DEBUG:ads_async.protocol:AoEHeader(target=192.168.2.193.1.1:851(R0_PLC_TC3), source=192.168.2.193.1.1:32997, command_id=<AdsCommandId.READ_WRITE: 9>, state_flags=<AoEHeaderFlag.ADS_COMMAND: 4>, length=28, error_code=0, invoke_id=101)
DEBUG:ads_async.protocol:AdsReadWriteRequest(index_group=<AdsIndexGroup.SYM_INFOBYNAMEEX: 61449>, index_offset=0, read_length=798, write_length=12, data=b'MAIN.iCount\x00')
DEBUG:ads_async.protocol:(AoEHeader(target=192.168.2.193.1.1:32997, source=192.168.2.193.1.1:851(R0_PLC_TC3), command_id=<AdsCommandId.READ_WRITE: 9>, state_flags=<AoEHeaderFlag.ADS_COMMAND|RESPONSE: 5>, length=104, error_code=0, invoke_id=101), AoEReadResponse(result=<AdsError.NOERR: 0>, read_length=96, data=b'`\x00\x00\x00@@\x00\x00\xf2\xdf\x05\x00\x02\x00\x00\x00\x02\x00\x00\x00\x08\x10\x00\x00\x0b\x00\x03\x00\x00\x00MAIN.iCount\x00INT\x00\x00\x95\x19\x07\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x01\x00\x05\x13pytmc\x00pv: PLC:TEST:iCount\x00\x00\x00\x00'))
DEBUG:ads_async.protocol:Handling AoEReadResponse(result=<AdsError.NOERR: 0>, read_length=96, data=b'`\x00\x00\x00@@\x00\x00\xf2\xdf\x05\x00\x02\x00\x00\x00\x02\x00\x00\x00\x08\x10\x00\x00\x0b\x00\x03\x00\x00\x00MAIN.iCount\x00INT\x00\x00\x95\x19\x07\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x01\x00\x05\x13pytmc\x00pv: PLC:TEST:iCount\x00\x00\x00\x00')
DEBUG:ads_async.protocol:AmsTcpHeader(reserved=0, length=60)
DEBUG:ads_async.protocol:AoEHeader(target=192.168.2.193.1.1:851(R0_PLC_TC3), source=192.168.2.193.1.1:32997, command_id=<AdsCommandId.READ_WRITE: 9>, state_flags=<AoEHeaderFlag.ADS_COMMAND: 4>, length=28, error_code=0, invoke_id=102)
DEBUG:ads_async.protocol:AdsReadWriteRequest(index_group=<AdsIndexGroup.SYM_HNDBYNAME: 61443>, index_offset=0, read_length=4, write_length=12, data=b'MAIN.iCount\x00')
DEBUG:ads_async.protocol:(AoEHeader(target=192.168.2.193.1.1:32997, source=192.168.2.193.1.1:851(R0_PLC_TC3), command_id=<AdsCommandId.READ_WRITE: 9>, state_flags=<AoEHeaderFlag.ADS_COMMAND|RESPONSE: 5>, length=12, error_code=0, invoke_id=102), AoEReadResponse(result=<AdsError.NOERR: 0>, read_length=4, data=b'\x0e\x00\x00\x01'))
DEBUG:ads_async.protocol:Handling AoEReadResponse(result=<AdsError.NOERR: 0>, read_length=4, data=b'\x0e\x00\x00\x01')
DEBUG:ads_async.protocol:AmsTcpHeader(reserved=0, length=44)
DEBUG:ads_async.protocol:AoEHeader(target=192.168.2.193.1.1:851(R0_PLC_TC3), source=192.168.2.193.1.1:32997, command_id=<AdsCommandId.READ: 2>, state_flags=<AoEHeaderFlag.ADS_COMMAND: 4>, length=12, error_code=0, invoke_id=103)
DEBUG:ads_async.protocol:AdsReadRequest(index_group=<AdsIndexGroup.SYM_VALBYHND: 61445>, index_offset=16777230, length=2)
DEBUG:ads_async.protocol:(AoEHeader(target=192.168.2.193.1.1:32997, source=192.168.2.193.1.1:851(R0_PLC_TC3), command_id=<AdsCommandId.READ: 2>, state_flags=<AoEHeaderFlag.ADS_COMMAND|RESPONSE: 5>, length=10, error_code=0, invoke_id=103), AoEReadResponse(result=<AdsError.NOERR: 0>, read_length=2, data=b'\xc5w'))
DEBUG:ads_async.protocol:Handling AoEReadResponse(result=<AdsError.NOERR: 0>, read_length=2, data=b'\xc5w')
DEBUG:ads_async.protocol:AmsTcpHeader(reserved=0, length=44)
DEBUG:ads_async.protocol:AoEHeader(target=192.168.2.193.1.1:851(R0_PLC_TC3), source=192.168.2.193.1.1:32997, command_id=<AdsCommandId.WRITE: 3>, state_flags=<AoEHeaderFlag.ADS_COMMAND: 4>, length=12, error_code=0, invoke_id=104)
DEBUG:ads_async.protocol:AdsWriteRequest(index_group=<AdsIndexGroup.SYM_RELEASEHND: 61446>, index_offset=16777230, write_length=0, data=b'')
{
    "MAIN.iCount": [
        30661
    ]
}

@klauer
Copy link
Contributor Author

klauer commented Jul 28, 2023

Test suite is hitting into pytmc changes in TMC handling, specifically from this PR:
pcdshub/pytmc#311 (AMSNETID was actually part of the discussion there 😁 )

Looks like ads-async needs to dig down into the base type for AMSNETID and represent it as a string of bytes. My recollection of my implementation here for this is rather hazy though so fixing the test suite may take a bit.

That said, there's still other stuff to be done:

  1. Consider moving these magic numbers into constants
  2. Consider switching to a structure for both of these non-AoE (AMS/ADS over Ethernet) packets
    a. I've never seen (well, my recollection again is fuzzy...) this string of bytes before in ADS comms so I'm not sure what to make of it. It seems like an inline/immediate control channel comm of sorts
  3. Support this on the server end -> implying to move the support into the 'protocol' section of ads-async
  4. Add tests of this to the test suite
  5. Support user-specified "local mode" (instead of checking against the target IP of localhost or 127.0.0.1, let the user toggle it on)
  6. (Fix the test suite as noted above)

@klauer
Copy link
Contributor Author

klauer commented Nov 7, 2023

@ZLLentz @tangkong this is still prototype-grade, but the library is prototype-grade as well. This is probably worth merging and then tagging.

@klauer klauer marked this pull request as ready for review November 10, 2023 18:17
Copy link

@tangkong tangkong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be my least informed green stamp in a while. may prototypes be prototype

@klauer klauer changed the title WIP FIX/ENH: local mode based on nodejs implementation FIX/ENH: local mode based on nodejs implementation Nov 10, 2023
Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful, no reason to let it sit in limbo forever

@ZLLentz
Copy link
Member

ZLLentz commented Nov 10, 2023

I'm going to merge and pretend like I don't care about the CI at all

@ZLLentz ZLLentz merged commit 9f4c805 into pcdshub:master Nov 10, 2023
2 of 9 checks passed
@klauer klauer deleted the enh_fix_local_mode branch November 10, 2023 19:01
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

Successfully merging this pull request may close these issues.

None yet

3 participants