ValueSymbolExtensions.PollValues Method (IValueSymbol, TimeSpan, Boolean)

Polls the symbol as value sequence of object values with a specified period time.

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

Syntax

C#

public static IObservable<Object?> PollValues(
    this IValueSymbol symbol,
    TimeSpan period,
    bool ignoreErrors
)

Parameters

symbol

Type: TwinCAT.TypeSystem.IValueSymbol
The symbol.

period

Type: System.TimeSpan
The period.

ignoreErrors

Type: System.Boolean
Ignore errors (NULL values will be returned)

Return Value

Type: IObservable.Object.
IObservable<System.Object>.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IValueSymbol. 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

If ignoreErrors is not set and ReadRequest errors occur, the observable will be closed with error (AdsException)./> If errors are ignored, the observable will return NULL values on erroneous requests.

Examples

Here, the values are polled in a specific time period and sequential Reads are triggered (in opposite to ADS Notification in the latter example)

Observe changing ADS Symbols (Read Polling)

// 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);
    IValueSymbol cycleCount = (IValueSymbol)symbolLoader.Symbols["TwinCAT_SystemInfoVarList._TaskInfo[1].CycleCount"];

    // Reactive Notification Handler
    var valueObserver = Observer.Create<object>(val =>
    {
    Console.WriteLine(string.Format("Instance: {0}, Value: {1}", cycleCount.InstancePath, val.ToString()));
    }
    );

    // Take 20 Values in an Interval of 500ms
    IDisposable subscription = cycleCount.PollValues(TimeSpan.FromMilliseconds(500)).Take(20).Subscribe(valueObserver);

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

Reference

ValueSymbolExtensions Class

PollValues Overload

TwinCAT.Ads.Reactive Namespace

ValueSymbolExtensions.PollValues(IValueSymbol, IObservable.Unit., Boolean)

ValueSymbolExtensions.PollValues(IValueSymbol, TimeSpan)