AdsClientExtensions Class
Extension class for AdsClient respective IAdsConnection to provide reactive ADS extensions.
Inheritance Hierarchy
SystemObject
TwinCAT.Ads.ReactiveAdsClientExtensions
Namespace: TwinCAT.Ads.Reactive
Assembly: TwinCAT.Ads.Reactive (in
TwinCAT.Ads.Reactive.dll) Version:
7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470
Syntax
C#
public static class AdsClientExtensionsThe AdsClientExtensions type exposes the following members.
Methods
|
|
Name |
Description |
|---|---|---|
|
|
Gets an observable sequence of AdsStates via Polling. | |
|
|
Gets an observable sequence of AdsStates via Polling. | |
|
|
Gets an observable sequence of ResultReadAdsStates via Polling. | |
|
|
Gets an observable sequence of ResultReadAdsStates via Polling. | |
|
|
PollAdsState2Async(IAdsConnection, IObservableUnit, CancellationToken) |
Gets an observable sequence of AdsStates via Polling. |
|
|
PollAdsState2Async(IAdsConnection, TimeSpan, CancellationToken) |
Gets an observable sequence of ResultReadAdsStates via Polling. |
|
|
PollAdsStateAsync(IAdsConnection, IObservableUnit, CancellationToken) |
Gets an observable sequence of AdsStates via Polling. |
|
|
PollAdsStateAsync(IAdsConnection, TimeSpan, CancellationToken) |
Gets an observable sequence of AdsStates via Polling. |
|
|
Gets an observable sequence of ResultReadDeviceStates via Polling. | |
|
|
Gets an observable sequence of ResultReadDeviceStates via Polling. | |
|
|
PollDeviceStateAsync(IAdsConnection, IObservableUnit, CancellationToken) |
Gets an observable sequence of ResultReadDeviceStates via Polling. |
|
|
PollDeviceStateAsync(IAdsConnection, TimeSpan, CancellationToken) |
Gets an observable sequence of ResultReadDeviceStates via Polling. |
|
|
Gets an observable sequence of AdsStates. | |
|
|
Gets an observable sequence of Notifications. | |
|
|
Gets an observable sequence of Notification objects. | |
|
|
WhenNotification(IAdsConnection, IListISymbol, NotificationSettings) |
Gets an observable sequence of Notification objects. |
|
|
WhenNotification(IAdsConnection, ISymbol, NotificationSettings) |
Gets an observable sequence of SymbolValueNotifications. |
|
|
Gets an observable sequence of SymbolVersion changed counts. | |
|
|
Gets an observable sequence of SymbolVersion changed counts. |
Remarks
Reactive Extensions (Rx) are a 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. The ADS reactive extensions are build on top of this library to enable ADS Symbol and State Observables, seamlessly bound to the reactive extensions. To use the ADS reactive extensions the TwinCAT.Ads.Reactive Nuget package (or the included TwinCAT.Ads.Reactive.dll) must be referenced. (Beckhoff.TwinCAT.Ads.Reactive package on Nuget).
Example
The following sample shows how observe Value changed Notifications with the reactive AdsClientExtensions
Observe changing ADS Symbols with reactive extensions.
// 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));
// Create Symbol information
var symbolLoader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.Default);
int eventCount = 1;
// Reactive Notification Handler
var valueObserver = Observer.Create<SymbolValueNotification>(not =>
{
Console.WriteLine(string.Format("{0} {1:u} {2} = '{3}' ({4})", eventCount++, not.TimeStamp, not.Symbol.InstancePath, not.Value, not.Symbol.DataType));
}
);
// Collect the symbols that are registered as Notification sources for their changed values.
SymbolCollection notificationSymbols = new SymbolCollection();
IArrayInstance taskInfo = (IArrayInstance)symbolLoader.Symbols["TwinCAT_SystemInfoVarList._TaskInfo"];
foreach(ISymbol element in taskInfo.Elements)
{
ISymbol cycleCount = element.SubSymbols["CycleCount"];
ISymbol lastExecTime = element.SubSymbols["LastExecTime"];
notificationSymbols.Add(cycleCount);
notificationSymbols.Add(lastExecTime);
}
// Create a subscription for the first 200 Notifications on Symbol Value changes.
IDisposable subscription = client.WhenNotification(notificationSymbols,NotificationSettings.Default).Take(200).Subscribe(valueObserver);
Console.ReadKey(); // Wait for Key press
subscription.Dispose(); // Dispose the Subscription
}Reference
TwinCAT.Ads.Reactive Namespace AnyTypeExtensions ValueSymbolExtensions
Beckhoff Automation GmbH & Co. KG 2001-2026
- AdsClientExtensions.PollAdsState Method (IAdsConnection, IObservable.Unit.)
- AdsClientExtensions.PollAdsState Method (IAdsConnection, TimeSpan)
- AdsClientExtensions.PollAdsStateAsync Method (IAdsConnection, IObservable.Unit., CancellationToken)
- AdsClientExtensions.PollAdsStateAsync Method (IAdsConnection, TimeSpan, CancellationToken)
- AdsClientExtensions.WhenAdsStateChanges Method
- AdsClientExtensions.WhenNotification Method (IAdsConnection, ISymbol)
- AdsClientExtensions.WhenNotification Method (IAdsConnection, ISymbolCollection)
- AdsClientExtensions.WhenNotification Method (IAdsConnection, ISymbol, NotificationSettings)
- AdsClientExtensions.WhenNotification Method (IAdsConnection, ISymbolCollection, NotificationSettings)
- AdsClientExtensions.WhenSymbolVersionChanges Method (IAdsConnection)
- AdsClientExtensions.WhenSymbolVersionChanges Method (IAdsConnection, IScheduler)
- AdsClientExtensions.PollAdsState2 Method (IAdsConnection, IObservable.Unit.)
- AdsClientExtensions.PollAdsState2 Method (IAdsConnection, TimeSpan)
- AdsClientExtensions.PollAdsState2Async Method (IAdsConnection, IObservable.Unit., CancellationToken)
- AdsClientExtensions.PollAdsState2Async Method (IAdsConnection, TimeSpan, CancellationToken)
- AdsClientExtensions.PollDeviceState Method (IAdsConnection, IObservable.Unit.)
- AdsClientExtensions.PollDeviceState Method (IAdsConnection, TimeSpan)
- AdsClientExtensions.PollDeviceStateAsync Method (IAdsConnection, IObservable.Unit., CancellationToken)
- AdsClientExtensions.PollDeviceStateAsync Method (IAdsConnection, TimeSpan, CancellationToken)
- AdsClientExtensions.WhenNotification Method (IAdsConnection, IList.ISymbol., NotificationSettings)