Add attribute support, ADS integration tests and struct serialization fix#21
Open
piratecarrot wants to merge 24 commits into
Open
Add attribute support, ADS integration tests and struct serialization fix#21piratecarrot wants to merge 24 commits into
piratecarrot wants to merge 24 commits into
Conversation
- cmd/main.go: replace hardcoded constants with env vars + CLI flags (ADS_TARGET_NET_ID, ADS_ROUTER_HOST, ADS_ROUTER_PORT, ADS_TIMEOUT) - cmd/cli/cmd_attributes.go: new read_attributes command showing type, value, symbol/type-level pragma attributes and sub-item tree - cmd/cli/cmd_read.go: fix list_symbols - replace broken raw parse with client.UploadSymbols(); add list_data_types command - cmd/cli/commandline.go: add tab completion for new commands - cmd/cli/handlers.go: register new command handlers - cmd/cli/cmd_util.go: add help text for new commands - pkg/ads/ads-symbol/parse.go: fix binary parser bugs - comment is null-terminated (was reading commentLen, not commentLen+1) - parse array info entries into ArrayInfo []ArrayInfoEntry - parse TypeGuid (16 bytes) into TypeGUID string when flag set - use ADSSymbolFlagAttributes constant instead of magic 0x1000 - pkg/ads/ads-symbol/types.go: add ArrayInfoEntry struct; add ArrayInfo and TypeGUID fields to AdsSymbol - pkg/ads/ads-symbol/parse_test.go: fix buildSymbolData helper (comment null terminator); add attribute, TypeGuid and array info test cases - pkg/ads/client_symbols.go: add UploadSymbols and GetDataTypes helpers
…and Programs folders
…oring Exposes startStatePoller() as a public method so callers can resume state polling after re-establishing ADS connectivity without a full TCP reconnect (e.g. after a PLC activation detected via restart-index change). Also fixes the ads-stateinfo import to use an explicit alias for clarity.
Sequential field writes ignored alignment padding inserted by TwinCAT's pack_mode, causing values to land at wrong byte offsets. Allocate a buffer of dataType.Size bytes (zeroed) and copy each serialized field at its reported subItem.Offset, matching the layout Deserialize expects.
PLC project (example3/):
- Deterministic FB: all 21 scalar PLC types driven deterministically from
a seed; flat output vars + struct_var (TestStruct) mirror each other
- TestStruct: struct covering all supported scalar types (L* types
commented out — not supported in TC 4024)
- StructTests FB: drives 4 pack_mode variants (0/2/4/8) of a
BOOL+DWORD+BOOL+LWORD struct from a seed for layout testing
- Main: calls Deterministic and StructTests; holds Go-owned write targets
for all types, TestStruct, arrays, and bare pack_* instances
Integration tests (test/integration/plc_test.go):
- TestStaticSeed: 14 boundary seeds, structural read of TestStruct
- TestReadAllAccessPaths: flat FB vars / struct structural / struct linear
- TestSubscription: on-change notifications via struct_var
- TestWriteAllTypes: flat vars, struct linear, struct structural
(map[string]any), FB control vars, arrays
- TestStructPacking: two-phase
phase 1 (plc_read): PLC fills pack structs from seed, Go reads
structurally and asserts against independently computed values
phase 2 (write_then_linear_read): Go writes struct structurally,
reads each field via its individual linear path — separates
Serialize from Deserialize to avoid circular validation
…o example Move example files into plc/example/src/, rename solution/project, add AdsGo example solution/project, move smallproject contents (GVL, POUs, Tasks, DUTs), and update TESTING.md.
Rename the example PLC global list and sample struct to the GVL_Global/ST_Sample naming scheme and update the example program accordingly. Update CLI read/write/subscription defaults and completions to target the renamed symbols, switch symbol upload info reads to UploadInfo2, and reuse shared ADS constants for client and CLI defaults.
Requesting only 8 bytes caused 'Parameter size not correct' (ADS 0x710) on any PLC using the SymbolUploadInfo2 index group, which always returns a 24-byte response. The CLI tool already used 24; align client_symbols.go to match. Fixes FindLogRingSymbol / FindSymbolByAttribute on real hardware.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What type of PR is this? (check all applicable)
Description
Related Issues
N/A
Testing
Test Environment:
Documentation
Checklist