AnyTypeExtensions.WhenNotification.T. Method (IAdsConnection, String, NotificationSettings)

Creates an observable sequence of values that are created by ADS Notifications.

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

Syntax

C#

public static IObservable<T> WhenNotification<T>(
    this IAdsConnection connection,
    string instancePath,
    NotificationSettings settings
)

Parameters

connection

Type: TwinCAT.Ads.IAdsConnection
The connection.

instancePath

Type: System.String
The instance path.

settings

Type: TwinCAT.Ads.NotificationSettings
The settings.

Type Parameters

T

The .NET Type representation of the specified symbols type.

Return Value

Type: IObservable.T.
IObservable<T>.

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

Remarks

The values will be cast to the specified type. The .NET type must fit the Symbol type like all ANYTYPES.

Examples

The following sample shows how to observe Value changed Notifications with the reactive AnyTypeExtensions

Observe changing ADS Symbols with reactive extensions (Extended AdsNotification, ANY_TYPE)

// 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
}

Reference

AnyTypeExtensions Class

WhenNotification Overload

TwinCAT.Ads.Reactive Namespace