Dahlke.TwinCAT.Ads.Testing
0.11.0
dotnet add package Dahlke.TwinCAT.Ads.Testing --version 0.11.0
NuGet\Install-Package Dahlke.TwinCAT.Ads.Testing -Version 0.11.0
<PackageReference Include="Dahlke.TwinCAT.Ads.Testing" Version="0.11.0" />
<PackageVersion Include="Dahlke.TwinCAT.Ads.Testing" Version="0.11.0" />
<PackageReference Include="Dahlke.TwinCAT.Ads.Testing" />
paket add Dahlke.TwinCAT.Ads.Testing --version 0.11.0
#r "nuget: Dahlke.TwinCAT.Ads.Testing, 0.11.0"
#:package Dahlke.TwinCAT.Ads.Testing@0.11.0
#addin nuget:?package=Dahlke.TwinCAT.Ads.Testing&version=0.11.0
#tool nuget:?package=Dahlke.TwinCAT.Ads.Testing&version=0.11.0
Dahlke.TwinCAT.Ads
A .NET library for TwinCAT ADS with durable connections, typed symbol access, simulation mode, and ASP.NET Core integration.
Features
- Typed reads and writes —
ReadValueAsync<T>/WriteValueAsync<T>with widening conversions; PLC structs, function blocks, unions and arrays bind onto records, classes and structs by member name - Typed symbol handles —
PlcSymbol<T>declares a symbol's path and .NET type once instead of at every call site - Stable connection facades — one object per target whose identity never changes; reconnects are invisible; operations wait up to
TimeoutMsfor a connection, then throw — never a false green - Durable subscriptions — survive reconnects automatically, with an optional Rx companion package surfacing them as
IObservable<T>streams - PLC alarm tracking — the optional Alarms package keeps a live set of outstanding alarms from a TwinCAT alarm array, streams transitions, and acknowledges through the PLC's own method over ADS
- Batch operations, RPC and enum metadata — ADS sum commands for single-round-trip batches;
InvokeRpcMethodAsyncandGetEnumMembersAsyncfor method calls and reading enum members by name - Raw ADS channels — address any
(amsNetId, port)by index group and offset for targets the symbol API cannot reach (EtherCAT, the TwinCAT system service) - Per-target simulation and a testing harness — mixed real/simulated fleets, seedable values, and a
TestPlcfixture that records what the code under test wrote; no TwinCAT installation required - Production hosting — health checks, options validation that fails boot with actionable messages, an embedded AMS router with retry, and no-host support for console/WPF/WinForms
Documentation
Long-form documentation lives in docs/:
| Connections | Pool, no-host builder, lookup, keyed injection, state, timeouts |
| Reading and writing values | Typed access, struct binding, batches, RPC, browsing, IEC type mapping |
| Subscriptions | Durable subscriptions and the Rx companion |
| PLC alarms | The Alarms package end to end |
| Raw ADS channels | Index-group/offset access, notifications, simulation store |
| Simulation | Per-target and whole-fleet simulation, seeding |
| Testing | TestPlc, write assertions, hand-written doubles |
| Configuration reference | Every section, every default, every validation rule |
| Troubleshooting | Indexed by the error text you see, likeliest cause first |
The API reference is generated from the XML documentation of every public member.
Installation
dotnet add package Dahlke.TwinCAT.Ads
Every package targets net8.0, net9.0, net10.0 and netstandard2.0 — the last one for the
.NET Framework 4.8 WinForms/WPF HMIs and in-house tooling that TwinCAT shops keep in service for
decades. The CI test suites run on .NET Framework 4.8 against the netstandard2.0 assemblies,
so that target is tested, not merely compiled.
Three optional companions, each depending on the core package:
dotnet add package Dahlke.TwinCAT.Ads.Reactive # IObservable<T> streams — see docs/subscriptions.md
dotnet add package Dahlke.TwinCAT.Ads.Alarms # PLC alarm tracking — see docs/alarms.md
dotnet add package Dahlke.TwinCAT.Ads.Testing # test harness (add to test projects; no test framework dependency)
EtherCAT packages
This repository also ships three EtherCAT packages. They are documented on their own package pages rather than here, because only one of them is about ADS at all:
| Package | What it is |
|---|---|
Dahlke.EtherCAT.Diagnostics |
Master and slave diagnostics over ADS — topology, slave and port state, CRC and frame error counters, sync-unit faults, CoE reads and writes, a decoded CiA-402 drive statusword, and a change-event stream. Built on this library's raw ADS channels, which is the only way to reach an EtherCAT master: there are no PLC symbols for any of it. |
Dahlke.EtherCAT.Esi |
An ESI (EtherCAT Slave Information) device catalogue — parses vendor ESI XML and resolves a vendor/product/revision triple to a device description. Depends on no ADS or TwinCAT package; it is XML, options and logging. Usable on its own with nothing but a folder of ESI files. |
Dahlke.EtherCAT.Cia402 |
CiA-402 (DS402) drive profile decoders — statusword, controlword and modes of operation, as pure functions over integers. Depends on nothing at all, not even Microsoft.Extensions.*, so it decodes a drive word that arrived over CoE, SoE, CANopen or a log file equally well. |
dotnet add package Dahlke.EtherCAT.Diagnostics # pulls Dahlke.TwinCAT.Ads, .Esi and .Cia402
dotnet add package Dahlke.EtherCAT.Esi # standalone
dotnet add package Dahlke.EtherCAT.Cia402 # standalone, zero dependencies
Quick Start
Configuration-first (recommended for server applications)
appsettings.json:
{
"AmsRouter": {
"NetId": "127.0.0.1.1.1"
},
"PlcTargets": {
"plc1": {
"AmsNetId": "192.168.1.10.1.1",
"Port": 851,
"DisplayName": "Main PLC",
"TimeoutMs": 5000
}
}
}
Program.cs:
// Real PLC connections
builder.Services.AddTwinCatAds(builder.Configuration);
// Or: force all targets to simulation mode (no TwinCAT required)
builder.Services.AddTwinCatAdsSimulation(builder.Configuration);
Reading a value:
public class TempService(IAdsConnectionPool pool)
{
public async Task<float> GetTemperatureAsync(CancellationToken ct)
{
var conn = pool.GetConnection("plc1");
return await conn.ReadValueAsync<float>("GVL.Temp", ct);
}
}
Code-first (no IConfiguration required)
builder.Services.AddTwinCatAds(o =>
{
o.Targets["plc1"] = new PlcTargetOptions
{
AmsNetId = "192.168.1.10.1.1",
Port = 851,
DisplayName = "Main PLC",
TimeoutMs = 5000,
};
});
// Simulation mode, code-first:
builder.Services.AddTwinCatAdsSimulation(o =>
{
o.Targets["plc1"] = new PlcTargetOptions
{
DisplayName = "Simulated PLC",
InitialValues = { ["GVL.Temp"] = 21.5f },
};
});
Console, WPF and WinForms — no host required
await using var pool = await AdsConnectionPoolBuilder
.Create()
.AddTarget("plc1", o => { o.AmsNetId = "192.168.1.10.1.1"; o.Port = 851; })
.BuildAndStartAsync();
var conn = pool.GetConnection("plc1");
The same pool, the same registrations, no generic host — see Connections for waiting on a real target, companion packages and shutdown.
Examples
Runnable projects live in examples/ — all work out of the box in simulation mode, no PLC required:
Dahlke.TwinCAT.Ads.Examples.Cli— console app demonstrating typed reads, writes, batch operations, ADS state, and subscriptionsDahlke.TwinCAT.Ads.Examples.MinimalApi— ASP.NET Core minimal API exposing PLC symbols over HTTP with a health endpointDahlke.TwinCAT.Ads.Examples.Reactive— console app demonstrating RxIObservablestreams: typed/untyped value changes with operator composition, and merged connection-state across targetsDahlke.TwinCAT.Ads.Examples.ErrorHandler— console app walking a whole PLC alarm lifecycle: two alarms on one machine, one clearing before it is acknowledged, and an acknowledgement that reaches the PLC through a simulatedAcknowledgeAlarmmethod
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Dahlke.TwinCAT.Ads (>= 0.11.0)
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
-
net10.0
- Dahlke.TwinCAT.Ads (>= 0.11.0)
-
net8.0
- Dahlke.TwinCAT.Ads (>= 0.11.0)
-
net9.0
- Dahlke.TwinCAT.Ads (>= 0.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.