ValueSymbolExtensionsWhenValueChanged(IAdsConnection, IEnumerableISymbol) Method
Observable sequence of Values driven by ADS Notifications on the specified symbol.
Namespace: TwinCAT.Ads.Reactive
Assembly: TwinCAT.Ads.Reactive (in
TwinCAT.Ads.Reactive.dll) Version:
7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470
Syntax
C#
public static IObservable<Object> WhenValueChanged(
this IAdsConnection connection,
IEnumerable<ISymbol> symbols
)Parameters
|
connection IAdsConnection |
The ADS connection / ADS Client |
|
symbols IEnumerableISymbol |
The symbols to observe. |
Return Value
IObservable
Object
IObservable<ValueChangedArgs>.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IAdsConnection. 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).
Observe changing ADS Symbols (ADS Notifications)
// 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.CycleCount"]; // UShort Type
IValueSymbol lastExecTime = (IValueSymbol)symbolLoader.Symbols["TwinCAT_SystemInfoVarList._TaskInfo.LastExecTime"]; // UInt Type
SymbolCollection symbols = new SymbolCollection();
symbols.Add(cycleCount);
symbols.Add(lastExecTime);
// Reactive Notification Handler
var valueObserver = Observer.Create<object>(val =>
{
Console.WriteLine(string.Format("Instance: {0}, Value: {1}", cycleCount.InstancePath, val.ToString()));
}
);
cycleCount.NotificationSettings = new NotificationSettings(AdsTransMode.OnChange,500,5000); // optional: Change NotificationSettings on Symbol
// Turning ADS Notifications into sequences of Value Objects (Taking 20 Values)
// and subscribe to them.
IDisposable subscription = client.WhenValueChanged(symbols).Take(20).Subscribe(valueObserver);
Console.ReadKey(); // Wait for Key press
subscription.Dispose(); // Dispose the Subscription
}Reference
ValueSymbolExtensions Class WhenValueChanged Overload TwinCAT.Ads.Reactive Namespace Observable
Beckhoff Automation GmbH & Co. KG 2001-2026