task-galaxy-e2e branch — non-FOCAS work-in-progress snapshot

Catch-all commit for pending work on the task-galaxy-e2e branch that
wasn't part of the FOCAS migration. Grouping by topic so future per-topic
commits can be cherry-picked if needed.

TwinCAT
- src/.../Driver.TwinCAT/AdsTwinCATClient.cs + TwinCATDriverFactoryExtensions.cs:
  factory-registration extensions + ADS client refinements.
- src/.../Driver.TwinCAT.Cli/Commands/BrowseCommand.cs: new browse command
  for the TwinCAT test-client CLI.
- tests/.../Driver.TwinCAT.IntegrationTests/TwinCAT3SmokeTests.cs + TwinCatProject/:
  fixture scaffold with a minimal POU + README pointing at the TCBSD/ESXi
  VM for e2e.
- docs/Driver.TwinCAT.Cli.md + docs/drivers/TwinCAT-Test-Fixture.md:
  documentation for the above.
- docs/v3/twincat-backlog.md: forward-looking backlog seed.

Admin UI + fleet status
- src/.../Admin/Components/Pages/Clusters/DriversTab.razor + Hosts.razor:
  UI refresh for fleet-status rendering.
- src/.../Admin/Hubs/FleetStatusHub.cs + FleetStatusPoller.cs +
  Admin/Program.cs: SignalR hub + poller plumbing for live fleet data.
- tests/.../Admin.Tests/FleetStatusPollerTests.cs: poller coverage.

Server + redundancy runtime (Phase 6.3 follow-ups)
- src/.../Server/Hosting/RedundancyPublisherHostedService.cs: HostedService
  that owns the RedundancyStatePublisher lifecycle + wires peer reachability.
- src/.../Server/Redundancy/ServerRedundancyNodeWriter.cs: OPC UA
  variable-node writer binding ServiceLevel + ServerUriArray to the
  publisher's events.
- src/.../Server/Program.cs + Server.csproj: hosted-service registration.
- tests/.../Server.Tests/ServerRedundancyNodeWriterTests.cs +
  Server.Tests.csproj: coverage for the above.

Configuration
- src/.../Configuration/Validation/DraftValidator.cs +
  tests/.../Configuration.Tests/DraftValidatorTests.cs: draft-validation
  refinements.

E2E scripts (shared infrastructure)
- scripts/e2e/README.md + _common.ps1 + test-all.ps1: shared helpers + the
  all-drivers test-all runner.
- scripts/e2e/test-opcuaclient.ps1: OPC UA Client e2e runner.

Docs
- docs/v2/implementation/phase-6-{1,2,3,4}*.md + exit-gate-phase-{3,7}.md:
  phase-gate + implementation doc updates.
- docs/v2/plan.md: top-level plan refresh.
- docs/v2/redundancy-interop-playbook.md: client interop playbook for the
  Phase 6.3 redundancy-runtime work.

Two orphan FOCAS docs remain on disk but deliberately unstaged —
docs/v2/focas-deployment.md and docs/v2/implementation/focas-simulator-plan.md
describe the now-retired Tier-C topology and should either be rewritten
or deleted in a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-04-24 14:12:19 -04:00
parent 4b0664bd55
commit 69e0d02c72
58 changed files with 3070 additions and 247 deletions

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="E_AxisState" Id="{ff675b51-fdf4-4a20-9755-d3a962aa226c}">
<Declaration><![CDATA[TYPE E_AxisState :
(
Idle := 0,
Homing := 1,
Moving := 2,
Stopped := 3,
Faulted := 99
) DINT;
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="E_Severity" Id="{00ec5016-5d26-4d67-bac9-3fc28b1c92ce}">
<Declaration><![CDATA[TYPE E_Severity :
(
Info := 0,
Warning := 1,
Critical := 2,
Fatal := 3
) INT;
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Alarm" Id="{d6459f8b-1fda-4bad-b787-c0e7e49fd8ec}">
<Declaration><![CDATA[TYPE ST_Alarm :
STRUCT
Active : BOOL;
Acknowledged : BOOL;
Code : DINT;
Severity : E_Severity;
RaisedAt : DT;
ClearedAt : DT;
Message : STRING(80);
Source : STRING(40);
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Axis" Id="{2e150fb3-4694-4853-bb73-754d225c082a}">
<Declaration><![CDATA[TYPE ST_Axis :
STRUCT
Name : STRING(32);
State : E_AxisState;
PositionMm : LREAL;
VelocityMps : T_MeterPerSec;
Accel : REAL;
Motor : ST_Motor;
Encoder : ST_Encoder;
Commands : ST_AxisCommands;
TravelLog : ARRAY[1..8] OF LREAL;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_AxisCommands" Id="{0aaff3fd-5525-495b-9759-4de792f6e615}">
<Declaration><![CDATA[TYPE ST_AxisCommands :
STRUCT
Enable : BOOL;
Home : BOOL;
Jog : BOOL;
Stop : BOOL;
TargetPos : LREAL;
TargetVel : T_MeterPerSec;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Encoder" Id="{87f1e7c2-2359-4db5-acf3-46a1dd518acb}">
<Declaration><![CDATA[TYPE ST_Encoder :
STRUCT
RawCounts : DINT;
PositionMm : LREAL;
VelocityMmPerS : T_MeterPerSec;
Homed : BOOL;
LastHomedAt : DT;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Line" Id="{3eaaae0a-31e2-43d6-b77c-5065a55c7d07}">
<Declaration><![CDATA[TYPE ST_Line :
STRUCT
Name : STRING(32);
Running : BOOL;
Stations : ARRAY[1..3] OF ST_Station;
Recipe : ST_Recipe;
Stats : ST_Stats;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Motor" Id="{9354c15d-7882-42bb-8bce-017f74e49cca}">
<Declaration><![CDATA[TYPE ST_Motor :
STRUCT
Current : REAL;
Voltage : REAL;
Temperature : T_Temperature;
Rpm : DINT;
Running : BOOL;
Faulted : BOOL;
SerialNo : STRING(24);
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Recipe" Id="{723636a8-1265-46a5-88b3-fa1a3d77e594}">
<Declaration><![CDATA[TYPE ST_Recipe :
STRUCT
Name : STRING(40);
Description : WSTRING(120);
Version : UINT;
LoadedAt : DT;
Steps : ARRAY[1..10] OF ST_RecipeStep;
SupportedSkus: ARRAY[1..4] OF STRING(16);
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_RecipeStep" Id="{64d61cc8-2aba-4adb-9cf1-9345fc6f95b8}">
<Declaration><![CDATA[TYPE ST_RecipeStep :
STRUCT
Enabled : BOOL;
StepName : STRING(32);
Duration : TIME;
Setpoint : LREAL;
Tolerance : REAL;
Retries : USINT;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Station" Id="{ab0c22da-aee2-42de-be7f-05b8a8c27083}">
<Declaration><![CDATA[TYPE ST_Station :
STRUCT
Name : STRING(32);
Online : BOOL;
Axes : ARRAY[1..4] OF ST_Axis;
IO : ST_StationIO;
Alarms : ARRAY[1..16] OF ST_Alarm;
Heartbeat: UDINT;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_StationIO" Id="{f71903d5-b9ea-4b75-9ca7-977b8374c11a}">
<Declaration><![CDATA[TYPE ST_StationIO :
STRUCT
DigitalInputs : ARRAY[0..31] OF BOOL;
DigitalOutputs : ARRAY[0..31] OF BOOL;
AnalogInputs : ARRAY[0..7] OF REAL;
AnalogOutputs : ARRAY[0..7] OF REAL;
CycleCounter : UDINT;
LastInputMask : DWORD;
LastOutputMask : DWORD;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="ST_Stats" Id="{23dffb59-ae06-4ac7-8c98-cba78dddf81d}">
<Declaration><![CDATA[TYPE ST_Stats :
STRUCT
UnitsProduced : UDINT;
UnitsRejected : UDINT;
UpTimeSeconds : UDINT;
LastRejectAt : DT;
LastProducedAt : DT;
RejectReasons : ARRAY[1..5] OF UDINT;
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="T_MeterPerSec" Id="{bddf08a2-da6c-4076-9719-13806a9e2438}">
<Declaration><![CDATA[TYPE T_MeterPerSec : LREAL;
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<DUT Name="T_Temperature" Id="{5e81fac6-ab58-4311-b798-907495f9ead9}">
<Declaration><![CDATA[TYPE T_Temperature : LREAL;
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<GVL Name="GVL_Arrays" Id="{6d45cf94-641a-40eb-a780-4fb3a1f8984f}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL
// 1-D arrays of primitives.
aBool1D : ARRAY[0..9] OF BOOL;
aInt1D : ARRAY[0..9] OF INT := [10(0)];
aDInt1D : ARRAY[1..16] OF DINT;
aReal1D : ARRAY[0..31] OF REAL;
aLReal1D : ARRAY[0..7] OF LREAL;
aString1D : ARRAY[1..4] OF STRING(32);
// 2-D and 3-D arrays.
aReal2D : ARRAY[1..4, 1..4] OF REAL;
aDInt3D : ARRAY[0..2, 0..2, 0..2] OF DINT;
// Array-of-UDT (exercises per-element browse of nested structs).
aAxisSnapshots : ARRAY[1..4] OF ST_Axis;
END_VAR
]]></Declaration>
</GVL>
</TcPlcObject>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<GVL Name="GVL_Enums" Id="{a0e45f27-3675-4b6f-bc09-ded0723b7029}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL
// Enum + alias coverage — standalone globals so OPC UA browse can assert
// on EnumStrings / DataTypeDefinition rendering without walking into the
// plant hierarchy.
currentAxisState : E_AxisState := E_AxisState.Idle;
currentSeverity : E_Severity := E_Severity.Info;
severityLog : ARRAY[1..8] OF E_Severity;
cabinetTemperature : T_Temperature := 22.5;
conveyorSpeed : T_MeterPerSec := 1.5;
END_VAR
]]></Declaration>
</GVL>
</TcPlcObject>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<GVL Name="GVL_Fixture" Id="{cdbd99aa-f3c6-48ad-a068-d31a9e1a3b21}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL
// Monotonic counter — MAIN increments every cycle. Seed 1234 is the
// floor the smoke tests assert against.
nCounter : DINT := 1234;
// Scratch REAL for write-then-read round-trip.
rSetpoint : REAL := 0.0;
// Reserved for discovery / browse tests.
bFlag : BOOL := TRUE;
END_VAR
]]></Declaration>
</GVL>
</TcPlcObject>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<GVL Name="GVL_Plant" Id="{00c8ed35-95d3-494a-92d8-db5f2c8ab6d9}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL
// Top-level plant hierarchy exposed to OPC UA browse:
// GVL_Plant.Line1.Stations[1..3].Axes[1..4].Motor/Encoder/Commands
// .IO
// .Alarms[1..16]
// .Recipe.Steps[1..10]
// .Stats
Line1 : ST_Line := (
Name := 'Assembly-01',
Running := TRUE
);
END_VAR
]]></Declaration>
</GVL>
</TcPlcObject>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<GVL Name="GVL_Primitives" Id="{2f721507-9717-45cf-bf40-02a9691bb5b4}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL
// One of every primitive ADS type. Exercises the full
// TwinCATDataType → OPC UA NodeId mapping.
vBool : BOOL := TRUE;
vByte : BYTE := 16#A5;
vWord : WORD := 16#BEEF;
vDWord : DWORD := 16#DEADBEEF;
vLWord : LWORD := 16#0123456789ABCDEF;
vSInt : SINT := -42;
vUSInt : USINT := 250;
vInt : INT := -12345;
vUInt : UINT := 54321;
vDInt : DINT := -1234567;
vUDInt : UDINT := 4000000000;
vLInt : LINT := -1234567890123;
vULInt : ULINT := 12345678901234567;
vReal : REAL := 3.14159;
vLReal : LREAL := 2.7182818284590452;
vString : STRING(80) := 'Hello from TC3';
vWString : WSTRING(80) := "unicode ✓";
vTime : TIME := T#2h34m17s500ms;
vTimeOfDay : TOD := TOD#08:30:00;
vDate : DATE := D#2026-04-22;
vDateTime : DT := DT#2026-04-22-08:30:00;
END_VAR
]]></Declaration>
</GVL>
</TcPlcObject>

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<POU Name="FB_AxisSim" Id="{5b3e4e46-5ace-4e6c-a0dc-d55113a89212}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK FB_AxisSim
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_IN_OUT
Axis : ST_Axis;
END_VAR
VAR
tick : UDINT;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[IF NOT Enable THEN
Axis.State := E_AxisState.Idle;
RETURN;
END_IF
tick := tick + 1;
// Ramp position + derive velocity so a subscription sees LREAL churn.
Axis.PositionMm := Axis.PositionMm + 0.5;
Axis.VelocityMps := 0.5 * SIN(UDINT_TO_LREAL(tick) * 0.05);
Axis.Accel := LREAL_TO_REAL(0.1 * COS(UDINT_TO_LREAL(tick) * 0.05));
Axis.State := E_AxisState.Moving;
// Motor block — keep values sane but moving.
Axis.Motor.Current := 2.5 + LREAL_TO_REAL(0.5 * SIN(UDINT_TO_LREAL(tick) * 0.1));
Axis.Motor.Voltage := 24.0;
Axis.Motor.Temperature:= 35.0 + 5.0 * SIN(UDINT_TO_LREAL(tick) * 0.01);
Axis.Motor.Rpm := 1500 + LREAL_TO_DINT(200.0 * SIN(UDINT_TO_LREAL(tick) * 0.05));
Axis.Motor.Running := TRUE;
// Encoder
Axis.Encoder.RawCounts := Axis.Encoder.RawCounts + 12;
Axis.Encoder.PositionMm := Axis.PositionMm;
Axis.Encoder.VelocityMmPerS := Axis.VelocityMps;
Axis.Encoder.Homed := TRUE;
// Travel log — rolling window of last 8 positions.
Axis.TravelLog[1] := Axis.TravelLog[2];
Axis.TravelLog[2] := Axis.TravelLog[3];
Axis.TravelLog[3] := Axis.TravelLog[4];
Axis.TravelLog[4] := Axis.TravelLog[5];
Axis.TravelLog[5] := Axis.TravelLog[6];
Axis.TravelLog[6] := Axis.TravelLog[7];
Axis.TravelLog[7] := Axis.TravelLog[8];
Axis.TravelLog[8] := Axis.PositionMm;
]]></ST>
</Implementation>
</POU>
</TcPlcObject>

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<POU Name="FB_LineSim" Id="{83bd0d62-650e-4191-9410-a31c2eb07c02}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK FB_LineSim
VAR_IN_OUT
Line : ST_Line;
END_VAR
VAR
tick : UDINT;
axisSim : ARRAY[1..3, 1..4] OF FB_AxisSim;
iStation : INT;
iAxis : INT;
iAlarm : INT;
rotatorBits : DWORD;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[tick := tick + 1;
FOR iStation := 1 TO 3 DO
Line.Stations[iStation].Online := TRUE;
Line.Stations[iStation].Heartbeat := tick;
// Axes — delegate to FB_AxisSim for per-cycle motion.
FOR iAxis := 1 TO 4 DO
axisSim[iStation, iAxis](
Enable := Line.Running,
Axis := Line.Stations[iStation].Axes[iAxis]
);
END_FOR
// Rolling I/O patterns to give subscribers something to watch.
rotatorBits := SHL(DWORD#1, (tick MOD 32));
Line.Stations[iStation].IO.LastInputMask := rotatorBits;
Line.Stations[iStation].IO.LastOutputMask := NOT rotatorBits;
Line.Stations[iStation].IO.CycleCounter := tick;
// Flip a couple of DI/DOs so BOOL arrays see changes.
Line.Stations[iStation].IO.DigitalInputs[(tick MOD 32)] := NOT Line.Stations[iStation].IO.DigitalInputs[(tick MOD 32)];
Line.Stations[iStation].IO.DigitalOutputs[(tick MOD 32)] := Line.Stations[iStation].IO.DigitalInputs[(tick MOD 32)];
// Walk an analog channel through a sine.
Line.Stations[iStation].IO.AnalogInputs[0] := LREAL_TO_REAL(10.0 + 5.0 * SIN(UDINT_TO_LREAL(tick + UDINT#100 * UINT_TO_UDINT(INT_TO_UINT(iStation))) * 0.05));
Line.Stations[iStation].IO.AnalogOutputs[0] := Line.Stations[iStation].IO.AnalogInputs[0] * 2.0;
// Rotate one alarm per station so IAlarmSource has state transitions.
iAlarm := INT_TO_USINT(1 + (DINT_TO_INT(UDINT_TO_DINT(tick)) MOD 16));
Line.Stations[iStation].Alarms[iAlarm].Active := (tick MOD 32) >= 16;
Line.Stations[iStation].Alarms[iAlarm].Severity := E_Severity.Warning;
Line.Stations[iStation].Alarms[iAlarm].Code := 1000 + DINT(iAlarm);
Line.Stations[iStation].Alarms[iAlarm].Message := CONCAT('alarm-', TO_STRING(iAlarm));
Line.Stations[iStation].Alarms[iAlarm].Source := CONCAT('Station-', TO_STRING(iStation));
END_FOR
// Stats — monotonic production counters.
Line.Stats.UnitsProduced := Line.Stats.UnitsProduced + 1;
IF (tick MOD 100) = 0 THEN
Line.Stats.UnitsRejected := Line.Stats.UnitsRejected + 1;
Line.Stats.RejectReasons[1 + ((DINT_TO_INT(UDINT_TO_DINT(tick / 100))) MOD 5)] :=
Line.Stats.RejectReasons[1 + ((DINT_TO_INT(UDINT_TO_DINT(tick / 100))) MOD 5)] + 1;
END_IF
Line.Stats.UpTimeSeconds := tick / 100; // 10 ms task tick -> approx seconds
]]></ST>
</Implementation>
</POU>
</TcPlcObject>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<POU Name="MAIN" Id="{eaceb1e4-5544-4368-a12f-3e05dd0be17a}" SpecialFunc="None">
<Declaration><![CDATA[PROGRAM MAIN
VAR
lineSim : FB_LineSim;
i : INT;
j : INT;
k : INT;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[// Smoke-test contract: monotonic counter on GVL_Fixture.nCounter.
// See TwinCAT3SmokeTests.cs (Driver_reads_seeded_DINT_through_real_ADS +
// Driver_subscribe_receives_native_ADS_notifications_on_counter_changes).
GVL_Fixture.nCounter := GVL_Fixture.nCounter + 1;
// Drive the complex fixture.
lineSim(Line := GVL_Plant.Line1);
// Keep the standalone enum / alias globals churning so browse + subscribe
// tests against GVL_Enums see changes without reaching into GVL_Plant.
IF (GVL_Fixture.nCounter MOD 10) = 0 THEN
GVL_Enums.currentAxisState := GVL_Plant.Line1.Stations[1].Axes[1].State;
GVL_Enums.currentSeverity := E_Severity.Info;
GVL_Enums.cabinetTemperature := GVL_Plant.Line1.Stations[1].Axes[1].Motor.Temperature;
GVL_Enums.conveyorSpeed := GVL_Plant.Line1.Stations[1].Axes[1].VelocityMps;
END_IF
// Stir a 2-D / 3-D array entry so multi-rank subscribes see value churn.
i := 1 + (GVL_Fixture.nCounter MOD 4);
j := 1 + ((GVL_Fixture.nCounter / 4) MOD 4);
GVL_Arrays.aReal2D[i, j] := LREAL_TO_REAL(SIN(DINT_TO_LREAL(GVL_Fixture.nCounter) * 0.01));
k := GVL_Fixture.nCounter MOD 3;
GVL_Arrays.aDInt3D[k, k, k] := GVL_Fixture.nCounter;
GVL_Arrays.aInt1D[GVL_Fixture.nCounter MOD 10] := DINT_TO_INT(GVL_Fixture.nCounter MOD 10000);
]]></ST>
</Implementation>
</POU>
</TcPlcObject>

View File

@@ -1,12 +1,15 @@
# TwinCAT XAR fixture project
This folder holds the TwinCAT 3 XAE project that the XAR VM runs for the
integration-tests suite (`tests/.../TwinCAT.IntegrationTests/*.cs`).
This folder holds the TwinCAT 3 XAE project that the XAR VM (or TCBSD
target) runs for the integration-tests suite and the broader browse /
UDT / array / enum coverage exercised by the OPC UA driver.
**Status today**: stub. The `.tsproj` isn't committed yet; once the XAR
VM is up + a project with the required state exists, export via
File → Export + drop it here as `OtOpcUaTwinCatFixture.tsproj` + its
PLC `.library` / `.plcproj` companions.
**Status today**: the `.sln` / `.tsproj` / `.plcproj` wrappers still get
generated per-workstation in XAE (GUIDs are install-specific), but every
PLC object is committed as a standalone `.TcGVL` / `.TcDUT` / `.TcPOU`
under `PLC/{GVLs,DUTs,POUs}/`. Reconstruction is "Add Existing Item" of
each file into a fresh XAE project — see **Importing the committed PLC
objects** below.
## Why `.tsproj`, not the binary bootproject
@@ -30,41 +33,89 @@ Reconstruction workflow on the VM:
## Required project state
The smoke tests in `TwinCAT3SmokeTests.cs` depend on this exact GVL +
PLC setup. Missing or renamed symbols surface as ADS `DeviceSymbolNotFound`
or wrong-type read failures, not silent skips.
`TwinCAT3SmokeTests.cs` ships 14 `[TwinCATFact]` methods plus a 16-case
`[TwinCATTheory]` — the tests depend on the exact shapes below. Missing
or renamed symbols surface as ADS `DeviceSymbolNotFound` or wrong-type
read failures, not silent skips. Changed seed values will flip specific
assertions — the load-bearing ones are called out inline.
### Global Variable List: `GVL_Fixture`
### Integration-test contract
```st
VAR_GLOBAL
// Monotonically-increasing counter; MAIN increments each cycle.
// Seed value 1234 picked so the smoke test can assert ">= 1234" without
// synchronising with the initial cycle.
nCounter : DINT := 1234;
The dependency surface spans `GVL_Fixture`, `GVL_Primitives`, `GVL_Arrays`,
`GVL_Enums`, `GVL_Plant`, and `MAIN`.
// Scratch REAL for write-then-read round-trip test. Smoke test writes
// 42.5 + reads back.
rSetpoint : REAL := 0.0;
**`GVL_Fixture`** (source: [`PLC/GVLs/GVL_Fixture.TcGVL`](PLC/GVLs/GVL_Fixture.TcGVL))
holds exactly three variables — `nCounter : DINT := 1234`,
`rSetpoint : REAL := 0.0`, `bFlag : BOOL := TRUE`. `MAIN`
(source: [`PLC/POUs/MAIN.TcPOU`](PLC/POUs/MAIN.TcPOU)) increments
`nCounter` every cycle so the native-notification test sees monotonic
change without writing. Seeded values aren't reliable — PlcTask
watchdog restarts reset them — so the read test only asserts a
non-negative DINT.
// Readable boolean with seed value TRUE. Reserved for future
// expansion (e.g. discovery / symbol-browse tests).
bFlag : BOOL := TRUE;
END_VAR
**`GVL_Primitives.vWord := 16#BEEF`** — the bit-indexed BOOL test pins
to bit 3 (set in `0xBEEF`) and bit 4 (clear). Changing the seed flips
that test.
**`GVL_Primitives` numeric seeds** — the primitive-type theory reads
each of `vSInt, vUSInt, vInt, vUInt, vDInt, vUDInt, vLInt, vULInt,
vReal, vLReal, vString` and asserts the exact seed value. Matches
the declarations in [`PLC/GVLs/GVL_Primitives.TcGVL`](PLC/GVLs/GVL_Primitives.TcGVL).
**`GVL_Arrays.aReal1D[5]`** — the array round-trip test writes + reads
element index 5. The array must be writable; don't apply read-only
attributes.
**`GVL_Plant.Line1.Stations[1].Axes[1].Motor.{Temperature, Running}`** —
the nested-UDT test reads both (LREAL + BOOL). `FB_LineSim` must be
driving the hierarchy (see `MAIN`) so values are alive.
**`GVL_Enums.currentAxisState`** — the browse test asserts this symbol
surfaces by name.
### Complex hierarchy (for browse / UDT / array / enum coverage)
All sources in [`PLC/`](PLC/). Commits are split
one-object-per-file so XAE can "Add Existing Item" each into a fresh
project (the `.plcproj` wrapper is environment-specific and not
committed).
**Type coverage**`GVL_Primitives` has one of every ADS primitive:
`BOOL, BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, UDINT,
LINT, ULINT, REAL, LREAL, STRING(80), WSTRING(80), TIME, TOD, DATE, DT`.
**Array coverage**`GVL_Arrays` has 1-D primitives, `ARRAY[1..4,1..4]
OF REAL`, `ARRAY[0..2,0..2,0..2] OF DINT`, plus `ARRAY[1..4] OF ST_Axis`
for per-element nested-struct browse.
**Enum + alias coverage**`E_AxisState : DINT`, `E_Severity : INT`,
`T_Temperature : LREAL`, `T_MeterPerSec : LREAL`. `GVL_Enums` exposes
each at the root so tests can assert `EnumStrings` /
`DataTypeDefinition` rendering without walking the plant hierarchy.
**5-level plant hierarchy** — rooted at `GVL_Plant.Line1 : ST_Line`:
```
GVL_Plant.Line1 (ST_Line)
.Stations[1..3] (ARRAY OF ST_Station)
.Axes[1..4] (ARRAY OF ST_Axis)
.Motor (ST_Motor)
.Encoder (ST_Encoder)
.Commands (ST_AxisCommands)
.TravelLog[1..8] (ARRAY OF LREAL)
.IO (ST_StationIO — 32x DI/DO, 8x AI/AO)
.Alarms[1..16] (ARRAY OF ST_Alarm)
.Recipe (ST_Recipe)
.Steps[1..10] (ARRAY OF ST_RecipeStep)
.SupportedSkus[1..4] (ARRAY OF STRING)
.Stats (ST_Stats)
```
### PLC program: `MAIN`
```st
PROGRAM MAIN
VAR
END_VAR
// One-line program: increment the fixture counter every cycle.
// The native-notification smoke test subscribes to GVL_Fixture.nCounter
// + observes the monotonic changes without a write path.
GVL_Fixture.nCounter := GVL_Fixture.nCounter + 1;
```
**Live value churn**`FB_LineSim` + `FB_AxisSim` are called from
`MAIN` every cycle: axes ramp position + derive velocity/accel, motor
current/temperature track a sine, IO masks rotate, one alarm per station
toggles each 32 cycles, stats counters increment. Subscription tests
see real data-change notifications without an external writer.
### Task
@@ -77,6 +128,30 @@ GVL_Fixture.nCounter := GVL_Fixture.nCounter + 1;
to this. Use runtime 2 / port `852` only if the single runtime is
already taken by another project on the same VM.
## Importing the committed PLC objects
On a machine with a working TcXaeShell (or Visual Studio with the TC3
XAE integration):
1. File → New → Project → **TwinCAT XAE Project** → name
`OtOpcUaTwinCatFixture`. This lays down the `.sln` + `.tsproj`
scaffolding.
2. In the Solution Explorer, right-click the `PLC` node →
**Add New Item → Standard PLC Project** → name `PLC`. Delete the
auto-generated stub `MAIN` — the committed one will replace it.
3. Right-click the PLC project's `DUTs` folder → **Add → Existing Item
…** → multi-select every file under [`PLC/DUTs/`](PLC/DUTs/) and
**Add As Link** (so the repo stays the source of truth). Repeat for
`GVLs/` → [`PLC/GVLs/`](PLC/GVLs/) and `POUs/`
[`PLC/POUs/`](PLC/POUs/).
4. Assign `MAIN` to `PlcTask` (cyclic, 10 ms, priority 20).
5. Set the target system to the TCBSD / XAR VM via the AMS route, then
**Build → Build Solution** + **Activate Configuration → Run Mode**.
If XAE complains about missing references while importing, add the DUTs
before the GVLs (the structs are referenced by the plant GVL) and the
enums/aliases first within DUTs.
## XAR VM setup (one-time)
Full bootstrap lives in `docs/v2/dev-environment.md`. The TwinCAT-specific
@@ -126,14 +201,17 @@ Options to eliminate the manual step:
On the dev box:
```powershell
$env:TWINCAT_TARGET_HOST = '10.0.0.42' # replace with the VM IP
$env:TWINCAT_TARGET_NETID = '5.23.91.23.1.1' # replace with the VM AmsNetId
# $env:TWINCAT_TARGET_PORT = '852' # only if not using PLC runtime 1
$env:TWINCAT_TARGET_NETID = '5.23.91.23.1.1' # replace with the VM AmsNetId — REQUIRED
$env:TWINCAT_TARGET_HOST = '10.0.0.42' # replace with the VM IP (defaults to localhost)
# $env:TWINCAT_TARGET_PORT = '852' # only if not using PLC runtime 1 (default 851)
dotnet test tests\ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.IntegrationTests
```
With any of those env vars unset, all three smoke tests skip cleanly via
`[TwinCATFact]`; unit suite (`TwinCAT.Tests`) runs unchanged.
Only `TWINCAT_TARGET_NETID` is required — fixture gates on it specifically.
`TWINCAT_TARGET_HOST` defaults to `localhost` when unset; `TWINCAT_TARGET_PORT`
defaults to `851`. With the NetID unset, the whole integration suite
(~28 cases, both `[TwinCATFact]` and `[TwinCATTheory]`) skips cleanly;
unit suite (`TwinCAT.Tests`) runs unchanged.
## See also