Files
lmxopcua/docs/drivers/evidence/twincat-z35474-testconnect-2026-11-11.md
T

5.1 KiB
Raw Blame History

TwinCAT Test Connect on a real ADS target: Z35474, 2026-11-11

Gitea #755 item: "Driver probe (Test Connect) happy path on a real ADS target".

Result: the item cannot be ticked. On real hardware the probe returns a false RED. The ADS target is healthy and reachable through the router, but TwinCATDriverProbe never gets to its ADS handshake: its TCP preflight dials the wrong endpoint.

Target and scope

Press Z35474 (Elma cleaner), production
IP 10.201.23.227 (reached over the VPN)
AmsNetId / port 5.118.56.93.1.1 : 851 (TC3 PLC runtime 1)
Route used the existing press-side route otopcua-mac-20261111 → 10.181.201.5.1.1 (no AddRoute sent)
Scope read-only: ReadState, ReadDeviceInfo, symbol upload (Flat), two scalar reads. No writes, no WriteControl, no notifications, no route-table change. One session at a time, a few seconds per run.

Harness

This is a scratch console app outside the repo. It has a ProjectReference to src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT and hosts Beckhoff.TwinCAT.Ads.TcpRouter 7.0.172 in process. The router's local NetId is 10.181.201.5.1.1, with one route Z35474 → 10.201.23.227 / 5.118.56.93.1.1. The package's sample StaticRoutes.xml is excluded, so the router loads no other routes. The Beckhoff ADS client is 7.0.172, the same version the driver uses.

The harness drives the probe the way AdminUI does:

  • RawTreeService.LoadMergedProbeConfigAsync builds the config through DriverDeviceConfigMerger.Merge("{}", [DeviceRow("Z35474", {"hostAddress":"ads://5.118.56.93.1.1:851"})], []).
  • AdminOperationsActor.ProbeAsync calls new TwinCATDriverProbe().ProbeAsync(merged, 10 s, cts(10 s)). The 10 s budget is TestConnectBudget's TwinCAT default.

The merged config the probe received:

{"hostAddress":"ads://5.118.56.93.1.1:851","Devices":[{"hostAddress":"ads://5.118.56.93.1.1:851","DeviceName":"Z35474"}],"RawTags":[]}

Observed (two runs, identical)

[probe]  Ok=False Message="Probe timed out after 10s." Latency=- wall=10003ms
[phase2] ReadState Succeeded=True Err=Succeeded AdsState=Run DeviceState=0 189ms   (2nd run 109ms)
[phase2] DeviceInfo Succeeded=True Name="Plc30 App" Version=3.1.1940
[browse] roots=3384                                  (Flat symbol upload)
[read]   .actualOperationMode : INT = 2
[read]   .CFG_NUM_CDA_MAX     : INT = 5

[phase2] is not the probe. It reproduces the probe's own Phase 2 (AdsClient.Connect(netId, 851) + ReadStateAsync, Timeout = 10 s) in the same process through the same router. It shows that the handshake the probe would have done succeeds: Run state in about 0.1–0.2 s.

Device: "Plc30 App", ADS version 3.1.1940, AdsState Run, DeviceState 0. The browse found 3,384 Flat roots, which matches the 2026-10-08 count.

Defect: the Phase 1 TCP preflight targets (NetId[0..4]):(AMS port)

TwinCATDriverProbe.ExtractTarget builds the preflight target as the first four octets of the AmsNetId plus the AMS port. It then runs Socket.ConnectAsync(host, port) before it tries ADS. That target is wrong in two separate ways:

  1. The AmsNetId is not the IP. For Z35474 the preflight dialled 5.118.56.93:851. That is a public internet address unrelated to the press; on this Mac it routes out of the LAN gateway, not the VPN. It black-holes, so the probe spends its whole 10 s budget and returns "Probe timed out after 10s." The press is at 10.201.23.227. The driver config has no IP field, so the probe cannot know it. Only the AMS router knows it.
  2. 851 is an AMS port, not a TCP port. ADS/TCP is 48898. On a press where the NetId happens to equal the IP (for example Z33856 10.201.45.236.1.1), the preflight would dial 10.201.45.236:801/851. That should be refused and return "Connect failed: ConnectionRefused", also a RED. I inferred this from the code and did not run it against that press.

Consequence: Test Connect cannot go green against a real TwinCAT runtime. It stops at Phase 1 before the ADS handshake, which works. The unit tests (TwinCATDriverProbeTests) pin the current behaviour: they open a loopback TcpListener on the "AMS port" and use ads://127.0.0.1.1.1:{port}, so the mismatch never shows up there. The probe also sends a TCP SYN to whatever internet host the NetId's first four octets name.

The fix is not made here: tracked source was left unedited, as the task asked. The fix direction is to drop the remote preflight, or point it at the local AMS router (127.0.0.1:48898), which is the only TCP endpoint the ADS client actually uses. Phase 2's ReadStateAsync, bounded by the timeout, then becomes the real reachability check. The unit tests would need to change with it.

#755 status

  • "Test Connect happy path on a real ADS target": not tickable. The ADS path works (router, route, ReadState = Run, device info, browse, reads), but the probe as AdminUI runs it returns a false RED. Re-run this gate after the preflight fix.
  • The harness lives in session scratch, not in the repo: scratchpad/twincat/probeharness/ (Program.cs, modes probe | read).