ValueSymbolExtensions.PollValues Method (ISumSymbolRead, TimeSpan)
Polls a series of symbols via a ISumSymbolRead 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.116+a71ced3
Syntax
C#
public static IObservable<ResultSumValues> PollValues(
this ISumSymbolRead sumRead,
TimeSpan period
)
Parameters
sumRead |
Type: TwinCAT.Ads.SumCommand.ISumSymbolRead |
period |
Type: System.TimeSpan |
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type ISumSymbolRead. 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 SumSymbolRead. Dependant on the configuration of the SumSymbolRead 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 SumSymbolRead are more consistant dependant of target realtime task configuration.
Examples
Demonstration of polling values efficiently via SumSymbolRead 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
}