ValueSymbolExtensionsPollValues(ISumRead, TimeSpan) Method

Polls a series of symbols via a ISumRead2S command. The SumCommand will read all contained values with every trigger in one roundtrip.


Namespace: TwinCAT.Ads.Reactive
Assembly: TwinCAT.Ads.Reactive (in TwinCAT.Ads.Reactive.dll) Version: 7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470

Syntax

C#

public static IObservable<ResultSumValues> PollValues(
    this ISumRead sumRead,
    TimeSpan period
)

Parameters

sumRead  ISumRead

The SumRead command.

period  TimeSpan

The time period for polling values.

Return Value

IObservable ResultSumValues
IObservable<ResultSumValues>.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type ISumRead. 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 characteristic of this overload is that more than one values can be read with one trigger signal. Each trigger produces only one Read call to the SumRead. Dependent on the configuration of the SumRead this could mean only one ADS Roundtrip (Request/Response). So the advantages are:

Example

Demonstration of polling values efficiently via SumRead command.

Observe multiple ADS Symbols via Polling of SumCommand

// 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"];
    IValueSymbol lastExecTime = (IValueSymbol)symbolLoader.Symbols["TwinCAT_SystemInfoVarList._TaskInfo.LastExecTime"];
    List<ISymbol> symbols = new List<ISymbol>() { cycleCount, lastExecTime };

    //Create the SumCommand
    SumSymbolRead sumRead = new SumSymbolRead(client, symbols);

    // Reactive Notification Handler
    var sumCommandObserver = Observer.Create<ResultSumValues>(result =>
    {
    Console.WriteLine($"SumCommand Succeeded: {result.OverallSucceeded}, CycleCount: {result.Values[0]}, LastExecTime: {result.Values[1]}");
    }
    );

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

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

Reference

ValueSymbolExtensions Class PollValues Overload TwinCAT.Ads.Reactive Namespace ISumRead PollValues2S(ISumRead2S, TimeSpan)

Beckhoff Automation GmbH & Co. KG 2001-2026