ValueSymbolExtensionsWriteValues(IValueSymbol, IObservableObject) Method

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: 7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470

Syntax

C#

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

Parameters

symbol  IValueSymbol

The symbol.

valueObservable  IObservableObject

Observable of Values.

Return Value

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).

Example

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

Beckhoff Automation GmbH & Co. KG 2001-2026