ValueSymbolExtensions.PollValues2.S. Method (ISumRead2.S., TimeSpan)
Polls a series of symbols via a ISumRead2.S. command. The SumCommand will read all contained values with every trigger.
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,
TimeSpan period
)
Parameters
sumRead |
Type: TwinCAT.Ads.SumCommand.ISumRead2.S. |
period |
Type: System.TimeSpan |
Type Parameters
S |
The source specifier, this could be an ISymbol or an InstancePath for example to reference the symbol. |
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:
- Usage of one trigger (could be a Background thread resource) for all values
- Getting the values of all values in one ADS roundtrip
- Values inside the SumRead are more consistant dependant of target realtime task configuration.
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
}