![]() |
VOOZH | about |
dotnet add package CP.TwinCATRx --version 2.1.69
NuGet\Install-Package CP.TwinCATRx -Version 2.1.69
<PackageReference Include="CP.TwinCATRx" Version="2.1.69" />
<PackageVersion Include="CP.TwinCATRx" Version="2.1.69" />Directory.Packages.props
<PackageReference Include="CP.TwinCATRx" />Project file
paket add CP.TwinCATRx --version 2.1.69
#r "nuget: CP.TwinCATRx, 2.1.69"
#:package CP.TwinCATRx@2.1.69
#addin nuget:?package=CP.TwinCATRx&version=2.1.69Install as a Cake Addin
#tool nuget:?package=CP.TwinCATRx&version=2.1.69Install as a Cake Tool
👁 License
👁 Build
👁 Nuget
👁 NuGet
A reactive, cross-platform wrapper for Beckhoff TwinCAT ADS built on System.Reactive (Rx). It lets you observe PLC variables as IObservable<T>, write values, and work with structured tags using a HashTable-like API.
# Main package
dotnet add package CP.TwinCATRx
# Optional low-level helpers (usually not required directly)
dotnet add package CP.TwinCATRx.Core
using CP.TwinCatRx;
using CP.TwinCatRx.Core;
// Create client and settings
var client = new RxTcAdsClient();
var settings = new Settings { AdsAddress = "5.35.59.10.1.1", Port = 801, SettingsId = "Default" };
// Register tags to observe (notifications) and write
settings.AddNotification(".Tag1"); // structure
settings.AddNotification(".AString", arraySize: 80); // string length required for string
settings.AddNotification(".AInt");
settings.AddWriteVariable(".ArrInt", 11); // arrays require a length
client.Connect(settings);
// Wait for PLC to be ready
client.InitializeComplete.Subscribe(_ =>
{
// One-shot reads of simple types
client.Read(".AString");
client.Read(".AInt");
// Write a value
client.Write(".AInt", 42);
});
// Observe tag changes as streams
client.Observe<string>(".AString").Subscribe(v => Console.WriteLine($"AString: {v}"));
client.Observe<short>(".AInt").Subscribe(v => Console.WriteLine($"AInt: {v}"));
// Observe arrays (triggered by reads)
client.Observe<short[]>(".ArrInt").Subscribe(arr => Console.WriteLine($"ArrInt[{arr.Length}]: {string.Join(",", arr)}"));
IRxTcAdsClient API
client.Observe<bool>(".ABool").Subscribe(v => Console.WriteLine($"ABool: {v}"));
client.Observe<int>(".ADInt").Subscribe(v => Console.WriteLine($"ADInt: {v}"));
// With correlation id
client.Observe<int>(".AInt", id: "R1").Subscribe(v => Console.WriteLine($"AInt[R1]: {v}"));
// Simple types
client.Read(".ALReal");
client.Write(".ABool", true);
// Arrays
// For arrays registered via AddWriteVariable(".ArrInt", 11) you can read with the configured length
client.Read(".ArrInt");
// Or supply a length for arrays not registered as write variables
client.Read(".ArrInt", arrayLength: 11);
TwinCatRxExtensions provides helpers to work with structured PLC tags using CP.Collections.HashTableRx.
// Create a live structure wrapper for a tag (structure or UDT)
var tag1 = client.CreateStruct(".Tag1");
// Wait until the first payload is received
await tag1!.StructureReady();
// Stream inner fields
tag1.Observe<bool>("ABool").Subscribe(v => Console.WriteLine($"Tag1.ABool: {v}"));
tag1.Observe<short>("AInt").Subscribe(v => Console.WriteLine($"Tag1.AInt: {v}"));
// Clone, set values, and write back atomically
var ok = tag1.WriteValues(ht =>
{
var current = ht.Value<short>("AInt");
ht.Value("AInt", (short)(current + 10));
ht.Value("AString", $"Int Value {current + 10}");
});
// Async write with a pause window
var okAsync = await tag1.WriteValuesAsync(ht =>
{
ht.Value("AInt", 100);
ht.Value("AString", "Updated");
}, TimeSpan.FromMilliseconds(300));
var settings = new Settings
{
AdsAddress = "5.35.59.10.1.1", // or leave null/empty to use local port-only Connect
Port = 801,
SettingsId = "Default"
};
// Notifications (observed tags)
settings.AddNotification(".Tag1"); // structure
settings.AddNotification(".AString", arraySize: 80); // strings require a size
settings.AddNotification(".AInt");
// Write variables (readable and writable)
settings.AddWriteVariable(".ArrInt", 11); // arrays require a length
using CP.TwinCatRx.Core;
// Retry forever
source.OnErrorRetry();
// Retry with handler
source.OnErrorRetry<SomeType, TimeoutException>(ex => Log(ex));
// Retry with delay and count
source.OnErrorRetry<SomeType, Exception>(ex => Log(ex), retryCount: 5, delay: TimeSpan.FromSeconds(1));
using CP.TwinCatRx.Core;
using TwinCAT.Ads;
var ads = new AdsClient();
ads.Connect(801);
// State changed events
ads.AdsStateChangedObserver().Subscribe(e => Console.WriteLine($"ADS state changed: {e.State}"));
// Polling observer for StateInfo
ads.AdsStateObserver().Subscribe(si => Console.WriteLine($"ADS: {si.AdsState}"));
TwinCATRx can generate types for complex structures at runtime to simplify marshaling. This is handled internally, but you can hook into emitted content via IRxTcAdsClient.Code. Dynamic emit/reflective APIs carry AOT/trimming caveats and are annotated accordingly.
Available on Windows-targeted TFMs.
using CP.TwinCatRx;
ObservableServiceController.GetServices()
.Where(s => s.DisplayName is "TwinCAT System Service" or "TwinCAT3 System Service")
.Subscribe(s =>
{
Console.WriteLine($"{s.DisplayName}: {s.Status}");
s.StatusObserver.Subscribe(st => Console.WriteLine($"Status: {st}"));
if (s.Status != ServiceControllerStatus.Running) s.Start();
});
client.ErrorReceived.Subscribe(ex => Console.WriteLine($"Error: {ex}"));
client.OnWrite.Subscribe(msg => Console.WriteLine($"Write: {msg}"));
This project is licensed under the MIT License - see the file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
TwinCATRx - Empowering Industrial Automation with Reactive Technology ⚡🏭
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net8.0-windows10.0.19041 net8.0-windows10.0.19041 is compatible. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net9.0-windows10.0.19041 net9.0-windows10.0.19041 is compatible. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. net10.0-windows10.0.19041 net10.0-windows10.0.19041 is compatible. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 is compatible. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 1 NuGet packages that depend on CP.TwinCATRx:
| Package | Downloads |
|---|---|
|
MQTTnet.Rx.TwinCAT
Reactive extensions for MQTTnet Broker |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.69 | 324 | 3/11/2026 |
| 2.1.49 | 284 | 1/19/2026 |
| 2.1.19 | 368 | 10/17/2025 |
| 2.1.15 | 293 | 10/4/2025 |
| 2.1.2 | 290 | 9/9/2025 |
| 2.0.4 | 269 | 8/20/2025 |
| 1.6.4 | 298 | 7/11/2025 |
| 1.6.3 | 326 | 6/24/2025 |
| 1.6.2 | 278 | 4/19/2025 |
| 1.6.1 | 307 | 2/2/2025 |
| 1.6.0 | 231 | 1/15/2025 |
| 1.5.0 | 270 | 12/20/2024 |
| 1.4.3 | 297 | 11/4/2024 |
| 1.4.2 | 248 | 10/28/2024 |
| 1.4.1 | 493 | 9/9/2024 |
| 1.4.0 | 439 | 8/20/2024 |
| 1.3.1 | 352 | 8/6/2024 |
| 1.3.0 | 291 | 6/5/2024 |
Compatability with Net 8, Net 9, Net 10 and netstandard2.0