AdsClientExtensions Class

Extension class for AdsClient respective IAdsConnection to provide reactive ADS extensions.

Inheritance Hierarchy

System.Object
  TwinCAT.Ads.Reactive.AdsClientExtensions
Namespace:  TwinCAT.Ads.Reactive
Assembly:  TwinCAT.Ads.Reactive (in TwinCAT.Ads.Reactive.dll) Version: 6.0.328+39e3229

Syntax

C#

public static class AdsClientExtensions

The AdsClientExtensions type exposes the following members.

Methods

 

Name

Description

AdsClientExtensions Class 1:

AdsClientExtensions Class 2:

AdsClientExtensions Class 3:

PollAdsState(IAdsConnection, IObservable.Unit.)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 4:

AdsClientExtensions Class 5:

AdsClientExtensions Class 6:

PollAdsState(IAdsConnection, TimeSpan)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 7:

AdsClientExtensions Class 8:

PollAdsState2(IAdsConnection, IObservable.Unit.)

Gets an observable sequence of ResultReadAdsStates via Polling.

AdsClientExtensions Class 9:

AdsClientExtensions Class 10:

AdsClientExtensions Class 11:

PollAdsState2(IAdsConnection, TimeSpan)

Gets an observable sequence of ResultReadAdsStates via Polling.

AdsClientExtensions Class 12:

AdsClientExtensions Class 13:

PollAdsState2Async(IAdsConnection, IObservable.Unit., CancellationToken)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 14:

AdsClientExtensions Class 15:

PollAdsState2Async(IAdsConnection, TimeSpan, CancellationToken)

Gets an observable sequence of ResultReadAdsStates via Polling.

AdsClientExtensions Class 16:

AdsClientExtensions Class 17:

AdsClientExtensions Class 18:

PollAdsStateAsync(IAdsConnection, IObservable.Unit., CancellationToken)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 19:

AdsClientExtensions Class 20:

AdsClientExtensions Class 21:

PollAdsStateAsync(IAdsConnection, TimeSpan, CancellationToken)

Gets an observable sequence of AdsStates via Polling.

AdsClientExtensions Class 22:

AdsClientExtensions Class 23:

PollDeviceState(IAdsConnection, IObservable.Unit.)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 24:

AdsClientExtensions Class 25:

AdsClientExtensions Class 26:

PollDeviceState(IAdsConnection, TimeSpan)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 27:

AdsClientExtensions Class 28:

AdsClientExtensions Class 29:

PollDeviceStateAsync(IAdsConnection, IObservable.Unit., CancellationToken)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 30:

AdsClientExtensions Class 31:

AdsClientExtensions Class 32:

PollDeviceStateAsync(IAdsConnection, TimeSpan, CancellationToken)

Gets an observable sequence of ResultReadDeviceStates via Polling.

AdsClientExtensions Class 33:

AdsClientExtensions Class 34:

AdsClientExtensions Class 35:

WhenAdsStateChanges

Gets an observable sequence of AdsStates.

AdsClientExtensions Class 36:

AdsClientExtensions Class 37:

WhenNotification(IAdsConnection, ISymbol)

Gets an observable sequence of Notifications.

AdsClientExtensions Class 38:

AdsClientExtensions Class 39:

AdsClientExtensions Class 40:

WhenNotification(IAdsConnection, ISymbolCollection)

Gets an observable sequence of Notification objects.

AdsClientExtensions Class 41:

AdsClientExtensions Class 42:

AdsClientExtensions Class 43:

WhenNotification(IAdsConnection, IList.ISymbol., NotificationSettings)

Gets an observable sequence of Notification objects.

AdsClientExtensions Class 44:

AdsClientExtensions Class 45:

WhenNotification(IAdsConnection, ISymbol, NotificationSettings)

Gets an observable sequence of SymbolValueNotifications.

AdsClientExtensions Class 46:

AdsClientExtensions Class 47:

WhenSymbolVersionChanges(IAdsConnection)

Gets an observable sequence of SymbolVersion changed counts.

AdsClientExtensions Class 48:

AdsClientExtensions Class 49:

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).

Examples

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
}

Examples

The following sample shows how observe AdsState changed Notifications with the reactive AdsClientExtensions

Observe changing ADS states with reactive extensions.

// To Test the observer, Start/Stop the local PLC

using (AdsClient client = new AdsClient())
{
    // Connect to target
    client.Connect(new AmsAddress(AmsNetId.Local, 851));

    // Create Symbol information
    var symbolLoader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.DefaultDynamic);

    // Reactive Notification Handler
    var valueObserver = Observer.Create<IList<AdsState>>(not =>
    {
        // OnNext handler (handling the StateChange)
        AdsState oldValue = not[0];
        AdsState newValue = not[1];
        Console.WriteLine(string.Format("Changed ADSState from '{0}' --> '{1}!", oldValue, newValue));
    },
    ex => Console.WriteLine($"Error: '{ex.Message}'"),   // Error Handling
    () => Console.WriteLine("WhenAdsStateChanges completed!") // Observer has completed
    );

    // Create a subscription for the AdsState change and buffering 2 Values (for oldValue --> newValue output).
    IDisposable subscription = client.WhenAdsStateChanges().Buffer(2,1).Subscribe(valueObserver);

    Console.ReadKey(); // Wait for Key press
    subscription.Dispose(); // Dispose the Subscription
}

Reference

TwinCAT.Ads.Reactive Namespace

TwinCAT.Ads.Reactive.AnyTypeExtensions

TwinCAT.Ads.Reactive.ValueSymbolExtensions