ValueSymbolExtensions.PollValues2.S. Method (ISumRead2.S., IObservable.Unit.)

Polls a series of symbols via a ISumRead2.S. 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: 6.0.328+39e3229

Syntax

C#

public static IObservable<ResultSumValues2<S>> PollValues2<S>(
    this ISumRead2<S> sumRead,
    IObservable<Unit> trigger
)

Parameters

sumRead

Type: TwinCAT.Ads.SumCommand.ISumRead2.S.
The SumRead command.

trigger

Type: System.IObservable.Unit.
The Polling trigger.

Type Parameters

S

The source specifier, this could be an ISymbol or InstancePath (string) for example to reference the single values with their source.

Return Value

Type: IObservable.ResultSumValues2.S..
IObservable<ResultSumValues>.

Usage Note

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

Examples

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<ResultSumValues2<ISymbol>>(result =>
    {
        Console.WriteLine($"SumCommand ErrorCode: {result.ErrorCode}");

        if (result.Succeeded)
        {
        Console.WriteLine($"SumCommand OverallSucceeded: {result.OverallSucceeded}");
        foreach (var subResult in result.ValueResults)
        {
            Console.WriteLine($"Source: {subResult.Source}, ErrorCode: {subResult.ErrorCode}, Value: {subResult.Value}");
        }
        }
    }
    );

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

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

Reference

ValueSymbolExtensions Class

PollValues2 Overload

TwinCAT.Ads.Reactive Namespace

TwinCAT.Ads.SumCommand.ISumRead2.S.

ValueSymbolExtensions.PollValues(ISumRead, IObservable.Unit.)