ValueSymbolExtensions.WriteValues Method (IValueSymbol, IObservable.Object.)
Subscribes the IValueSymbol to an observable sequence of values and writes them to the IValueSymbol.
Namespace: TwinCAT.Ads.Reactive
Assembly: TwinCAT.Ads.Reactive (in
TwinCAT.Ads.Reactive.dll) Version: 4.3.0.0 (4.3.7.0)
Syntax
C#
public static IDisposable WriteValues(
this IValueSymbol symbol,
IObservable<Object> valueObservable
)
VB
<ExtensionAttribute>
Public Shared Function WriteValues (
symbol As IValueSymbol,
valueObservable As IObservable(Of Object)
) As IDisposable
Parameters
symbol |
Type: TwinCAT.TypeSystem.IValueSymbol |
valueObservable |
Type: System.IObservable.Object. |
Return Value
Type: IDisposable
IDisposable.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IValueSymbol. 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).
Examples
In the following example it is demonstrated how to write Values sequentially to a IValueSymbol with the help of the reactive extensions.
Write sequences of values to the target
using (TcAdsClient client = new TcAdsClient())
{
// Connect to target
client.Connect(new AmsAddress(AmsNetId.Local, 851));
// Create Symbol information (Symbol 'i : INT' in PLC Global Variables list.
var symbolLoader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.Default);
IValueSymbol cycleCount = (IValueSymbol)symbolLoader.Symbols["GVL.i"];
// Produces object Values 0,1,2,3 ... in seconds period
IObservable<object> timerObservable = Observable.Interval(TimeSpan.FromSeconds(1.0)).Select(i => (object)(short)i);
// Take 10 Values (0..9) and write them to GVL.i
IDisposable dispose = cycleCount.WriteValues(timerObservable.Take(10));
Console.ReadKey(); // Wait for Key press
dispose.Dispose(); // Dispose the Subscription
}