[twincat] TwinCAT — Whole-array reads #344

Merged
dohertj2 merged 1 commits from auto/twincat/1.4 into auto/driver-gaps 2026-04-25 17:38:40 -04:00
Owner

Summary

Whole-array & multi-dim reads for TwinCAT.

  • TwinCATTagDefinition gains int[]? ArrayDimensions (default null = scalar).
  • ITwinCATClient.ReadValueAsync / WriteValueAsync thread an int[]? arrayDimensions parameter.
  • AdsTwinCATClient.ReadValueAsync calls clrType.MakeArrayType() for whole-array reads and per-element-projects IEC TIME/DATE values via a new PostProcessArray.
  • TwinCATDriver.DiscoverAsync surfaces IsArray=true + ArrayDim=product(dims) via new ResolveArrayShape helper. Multi-dim flattens to the product because DriverAttributeInfo.ArrayDim is a single uint? today.
  • Native ADS notification subscribe path skips whole-array tags (per-element callback shape doesn't fit a flat array — read-poll path is fine).
  • FakeTwinCATClient updated for new signatures + a ReadLog tracker.

Whole-array WRITE returns BadNotSupported — read-only PR per the issue scope. Write follow-up tracked separately.

Test plan

  • dotnet buildDriver.TwinCAT + Driver.TwinCAT.Tests + Driver.TwinCAT.Cli + integration tests all clean (0 / 0)
  • dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests143 / 143 passed (8 new in TwinCATArrayReadTests: ResolveArrayShape cases, discovery emits IsArray+ArrayDim for 1-D and 2-D, fake-client read fan-out for single + multi-dim, BadNotSupported write gate)
  • Integration tests — hardware-gated (TWINCAT_TARGET_NETID)

🤖 Auto-generated by the Mode-B execution loop. Closes #308.

Closes #308

## Summary Whole-array & multi-dim reads for TwinCAT. - `TwinCATTagDefinition` gains `int[]? ArrayDimensions` (default `null` = scalar). - `ITwinCATClient.ReadValueAsync` / `WriteValueAsync` thread an `int[]? arrayDimensions` parameter. - `AdsTwinCATClient.ReadValueAsync` calls `clrType.MakeArrayType()` for whole-array reads and per-element-projects IEC TIME/DATE values via a new `PostProcessArray`. - `TwinCATDriver.DiscoverAsync` surfaces `IsArray=true` + `ArrayDim=product(dims)` via new `ResolveArrayShape` helper. Multi-dim flattens to the product because `DriverAttributeInfo.ArrayDim` is a single `uint?` today. - Native ADS notification subscribe path **skips whole-array tags** (per-element callback shape doesn't fit a flat array — read-poll path is fine). - `FakeTwinCATClient` updated for new signatures + a `ReadLog` tracker. > **Whole-array WRITE returns `BadNotSupported`** — read-only PR per the issue scope. Write follow-up tracked separately. ## Test plan - [x] `dotnet build` — `Driver.TwinCAT` + `Driver.TwinCAT.Tests` + `Driver.TwinCAT.Cli` + integration tests all clean (0 / 0) - [x] `dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests` — **143 / 143 passed** (8 new in `TwinCATArrayReadTests`: `ResolveArrayShape` cases, discovery emits `IsArray`+`ArrayDim` for 1-D and 2-D, fake-client read fan-out for single + multi-dim, `BadNotSupported` write gate) - [ ] Integration tests — hardware-gated (TWINCAT_TARGET_NETID) 🤖 Auto-generated by the Mode-B execution loop. Closes #308. Closes #308
dohertj2 added 1 commit 2026-04-25 17:38:36 -04:00
Surface int[]? ArrayDimensions on TwinCATTagDefinition + thread it through
ITwinCATClient.ReadValueAsync / WriteValueAsync. When non-null + non-empty,
AdsTwinCATClient issues a single ADS read against the symbol with
clrType.MakeArrayType() and returns the flat 1-D CLR Array; for IEC TIME /
DATE / DT / TOD element types we project per-element to the native
TimeSpan / DateTime so consumers see consistent types regardless of rank.

DiscoverAsync surfaces IsArray=true + ArrayDim=product(dims) onto
DriverAttributeInfo via a new ResolveArrayShape helper. Multi-dim shapes
flatten to the product on the wire — DriverAttributeInfo.ArrayDim is
single-uint today and the OPC UA layer reflects rank via its own metadata.

Native ADS notification subscriptions skip whole-array tags so the OPC UA
layer falls through to a polled snapshot — the per-element AdsNotificationEx
callback shape doesn't fit a flat array. Whole-array WRITES are out of
scope for this PR — AdsTwinCATClient.WriteValueAsync returns
BadNotSupported when ArrayDimensions is set.

Tests: TwinCATArrayReadTests covers ResolveArrayShape (null / empty /
single-dim / multi-dim flatten / non-positive defensive), DiscoverAsync
emitting IsArray + ArrayDim for declared array tags, single-dim + multi-dim
fake-client read fan-out, and the BadNotSupported gate on whole-array
writes. Existing 137 unit tests still pass — total now 143.

Closes #308
dohertj2 merged commit 448a97d67f into auto/driver-gaps 2026-04-25 17:38:40 -04:00
dohertj2 deleted branch auto/twincat/1.4 2026-04-25 17:38:41 -04:00
Sign in to join this conversation.