AnyTypeExtensions.WhenNotification Method (IAdsConnection, String, Type, 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<Object> WhenNotification(
    this IAdsConnection connection,
    string instancePath,
    Type type,
    NotificationSettings settings
)

Parameters

connection

Type: TwinCAT.Ads.IAdsConnection
The connection.

instancePath

Type: System.String
The instance path.

type

Type: System.Type
The type.

settings

Type: TwinCAT.Ads.NotificationSettings
The settings.

Return Value

Type: IObservable.Object.
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 be one of the compatible 'ANYTYPES'.

Examples

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

Observe changing ADS Symbols with reactive extensions (Extended AdsNotifications, 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