Reactive extensions for Beckhoff.TwinCAT.AdsClient Extends the AdsClient object with Reactive Interfaces for ADS Notifications to support observable Streams of value changes.
$ dotnet add package Beckhoff.TwinCAT.Ads.ReactiveThe package 'Beckhoff.TwinCAT.Ads.Reactive' implements reactive extensions for the TwinCAT.Ads.AdsClient class included in the 'Beckhoff.TwinCAT.Ads' package.
Reactive Extensions (Rx) is a .NET library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Using Rx, developers represent asynchronous data streams with Observables, query asynchronous data streams using LINQ operators, and parameterize the concurrency in the asynchronous data streams using Schedulers.
Simply put, Rx = Observables + LINQ + Schedulers.
In ADS terms, not only the reading and writing data or symbol values can be put into reactive data streams, also ADS Notifications or polling of values are a perfect fit for reactive code. With the help of this package not only data binding to reactive frameworks (e.g. reactive UI) is simplified but also enhanced data manipulation via synchronous and asynchronous observers. Multithreaded and parallelized code paths that support multiple CPU cores can be written very easily without the burden of deadlock and synchronization issues.
The 'Beckhoff.TwinCAT.Ads.Reactive' depends on the 'Beckhoff.TwinCAT.Ads' packages and inherits the same requirements
| Package | Description | .NET Framework | TwinCAT | Active Support |
|---|---|---|---|---|
| 7.0 | Package basing on .NET 10.0 | net10.0, net8.0, netstandard2.0 | >= 2.11 1 | X |
| 6.2 | Package basing on .NET 8.0/6.0 | net8.0, net6.0, netstandard2.0 |
| >= 3.1.4024.10 1 |
| X |
| 6.1 | Package basing on .NET 7.0/6.02 | net7.0, net6.0, netstandard2.0 | >= 3.1.4024.10 1 |
| 6.0 | Package basing on .NET 6.0 | net6.0, netcoreapp3.1, netstandard2.0, net461 | >= 3.1.4024.10 1 |
| 4.x | Package basing on .NET Framework 4.0 | net4 | All | X |
The following code instantiates an AdsClient object, connects to the local PLC System Port 851 and subscribes fir the first 20 change notifications of the Task cycle count and writes the value to the Console.
// To Test the Observer run a project on the local PLC System (Port 851)
using (AdsClient client = new AdsClient())
{
// Connect to target
client.Connect(new AmsAddress(AmsNetId.Local, 851));
// Reactive Notification Handler
var valueObserver = Observer.Create<ushort>(val =>
{
Console.WriteLine(string.Format("Value: {0}", val.ToString()));
}
);
// Turning ADS Notifications into sequences of Value Objects (Taking 20 Values)
// and subscribe to them.
IDisposable subscription = client.WhenNotification<ushort>("TwinCAT_SystemInfoVarList._TaskInfo.CycleCount", NotificationSettings.Default).Take(20).Subscribe(valueObserver);
Console.ReadKey(); // Wait for Key press
subscription.Dispose(); // Dispose the Subscription
}
The actual version of the documentation is available in the Beckhoff Infosys. Beckhoff Information System