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 AdsClientExtensions

The AdsClientExtensions type exposes the following members.

Methods

 

Name

Description

AdsClientExtensions Class 1:

PollAdsState(IAdsConnection, IObservableUnit)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 2:

PollAdsState(IAdsConnection, TimeSpan)

Gets an observable sequence of AdsStates via Polling.

PollAdsState2(IAdsConnection, IObservableUnit)

Gets an observable sequence of ResultReadAdsStates via Polling.

AdsClientExtensions Class 3:

PollAdsState2(IAdsConnection, TimeSpan)

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.

AdsClientExtensions Class 4:

PollAdsStateAsync(IAdsConnection, IObservableUnit, CancellationToken)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 5:

PollAdsStateAsync(IAdsConnection, TimeSpan, CancellationToken)

Gets an observable sequence of AdsStates via Polling.

PollDeviceState(IAdsConnection, IObservableUnit)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 6:

PollDeviceState(IAdsConnection, TimeSpan)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 7:

PollDeviceStateAsync(IAdsConnection, IObservableUnit, CancellationToken)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 8:

PollDeviceStateAsync(IAdsConnection, TimeSpan, CancellationToken)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 9:

WhenAdsStateChanges

Gets an observable sequence of AdsStates.

WhenNotification(IAdsConnection, ISymbol)

Gets an observable sequence of Notifications.

AdsClientExtensions Class 10:

WhenNotification(IAdsConnection, ISymbolCollection)

Gets an observable sequence of Notification objects.

AdsClientExtensions Class 11:

WhenNotification(IAdsConnection, IListISymbol, NotificationSettings)

Gets an observable sequence of Notification objects.

WhenNotification(IAdsConnection, ISymbol, NotificationSettings)

Gets an observable sequence of SymbolValueNotifications.

WhenSymbolVersionChanges(IAdsConnection)

Gets an observable sequence of SymbolVersion changed counts.

WhenSymbolVersionChanges(IAdsConnection, IScheduler)

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