AdsClientExtensions.WhenNotification Method (IAdsConnection, IList.ISymbol., NotificationSettings)

Gets an observable sequence of Notification objects.

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

Syntax

C#

public static IObservable<SymbolValueNotification> WhenNotification(
    this IAdsConnection client,
    IList<ISymbol> symbols,
    NotificationSettings settings
)

Parameters

client

Type: TwinCAT.Ads.IAdsConnection
The client.

symbols

Type: System.Collections.Generic.IList.ISymbol.
The symbols to observe.

settings

Type: TwinCAT.Ads.NotificationSettings
The Notification settings.

Return Value

Type: IObservable.SymbolValueNotification.
IObservable<NotificationValue>.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IAdsConnection. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

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
}

Reference

AdsClientExtensions Class

WhenNotification Overload

TwinCAT.Ads.Reactive Namespace