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: 6.0.328+39e3229

Syntax

C#

public static IDisposable WriteValues(
    this IValueSymbol symbol,
    IObservable<Object> valueObservable
)

Parameters

symbol

Type: TwinCAT.TypeSystem.IValueSymbol
The symbol.

valueObservable

Type: System.IObservable.Object.
Observable of Values.

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 (AdsClient client = new AdsClient())
{
    // 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
}

Reference

ValueSymbolExtensions Class

WriteValues Overload

TwinCAT.Ads.Reactive Namespace