AdsClientExtensions.WhenAdsStateChanges Method

Gets an observable sequence of AdsStates.

Namespace:  TwinCAT.Ads.Reactive
Assembly:  TwinCAT.Ads.Reactive (in TwinCAT.Ads.Reactive.dll) Version: 4.3.0.0 (4.3.7.0)

Syntax

C#

public static IObservable<AdsState> WhenAdsStateChanges(
    this TcAdsClient client
)

VB

<ExtensionAttribute>
Public Shared Function WhenAdsStateChanges ( 
    client As TcAdsClient
) As IObservable(Of AdsState)

Parameters

client

Type: TwinCAT.Ads.TcAdsClient
The client.

Return Value

Type: IObservable.AdsState.
IObservable<AdsState>.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type TcAdsClient. 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 AdsState changed Notifications with the reactive AdsClientExtensions

Observe changing ADS States with reactive extensions.

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

using (TcAdsClient client = new TcAdsClient())
{
    // 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 =>
    {
        AdsState oldValue = not[0];
        AdsState newValue = not[1];

        Console.WriteLine(string.Format("Changed ADSState from '{0}' --> '{1}!", oldValue, newValue));
    }
    );

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

AdsClientExtensions Class

TwinCAT.Ads.Reactive Namespace

AdsClientExtensions.PollAdsState(IAdsConnection, IObservable.Unit.)