AnyTypeExtensions Class

Extension class for TcAdsClient respective IAdsConnection to provide reactive ADS extensions (accessing symbol value sequences with the ANY_TYPE concept)

Inheritance Hierarchy

System.Object
  TwinCAT.Ads.Reactive.AnyTypeExtensions
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 class AnyTypeExtensions

VB

<ExtensionAttribute>
Public NotInheritable Class AnyTypeExtensions

Methods

 

Name

Description

AnyTypeExtensions Class 1:

AnyTypeExtensions Class 2:

PollValues(IAdsConnection, String, Type, IObservable.Unit.)

Polls the symbol values on timepoints where the polling observable streams data / triggers

AnyTypeExtensions Class 3:

AnyTypeExtensions Class 4:

PollValues(IAdsConnection, String, Type, TimeSpan)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 5:

AnyTypeExtensions Class 6:

PollValues(IAdsConnection, String, Type, .Int32., TimeSpan)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 7:

AnyTypeExtensions Class 8:

PollValues(IAdsConnection, String, Type, IObservable.Unit., Func.Exception, Object.)

Polls the symbol values on timepoints where the polling observable streams data / triggers

AnyTypeExtensions Class 9:

AnyTypeExtensions Class 10:

PollValues(IAdsConnection, String, Type, TimeSpan, Func.Exception, Object.)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 11:

AnyTypeExtensions Class 12:

PollValues(IAdsConnection, String, Type, .Int32., IObservable.Unit., Func.Exception, Object.)

Polls the symbol values on time points where the polling observable streams data / triggers

AnyTypeExtensions Class 13:

AnyTypeExtensions Class 14:

PollValues(IAdsConnection, String, Type, .Int32., TimeSpan, Func.Exception, Object.)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 15:

AnyTypeExtensions Class 16:

PollValues.T.(IAdsConnection, String, IObservable.Unit.)

Polls the symbol values on timepoints where the polling observable streams data / triggers

AnyTypeExtensions Class 17:

AnyTypeExtensions Class 18:

PollValues.T.(IAdsConnection, String, TimeSpan)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 19:

AnyTypeExtensions Class 20:

PollValues.T.(IAdsConnection, String, .Int32., IObservable.Unit.)

Polls the symbol values on time points where the polling observable streams data / triggers

AnyTypeExtensions Class 21:

AnyTypeExtensions Class 22:

AnyTypeExtensions Class 23:

PollValues.T.(IAdsConnection, String, .Int32., TimeSpan)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 24:

AnyTypeExtensions Class 25:

PollValues.T.(IAdsConnection, String, IObservable.Unit., Func.Exception, T.)

Polls the symbol values on timepoints where the polling observable streams data / triggers

AnyTypeExtensions Class 26:

AnyTypeExtensions Class 27:

PollValues.T.(IAdsConnection, String, TimeSpan, Func.Exception, T.)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 28:

AnyTypeExtensions Class 29:

PollValues.T.(IAdsConnection, String, .Int32., IObservable.Unit., Func.Exception, T.)

Polls the symbol values on timepoints where the polling observable streams data / triggers

AnyTypeExtensions Class 30:

AnyTypeExtensions Class 31:

AnyTypeExtensions Class 32:

PollValues.T.(IAdsConnection, String, .Int32., TimeSpan, Func.Exception, T.)

Polls the symbol as value sequence of object values with a specified period time.

AnyTypeExtensions Class 33:

AnyTypeExtensions Class 34:

AnyTypeExtensions Class 35:

WriteValues.T.(IAdsConnection, String, IObservable.T.)

Writes the sequence of values to the symbol specified by the instance path.

AnyTypeExtensions Class 36:

AnyTypeExtensions Class 37:

AnyTypeExtensions Class 38:

WriteValues.T.(IAdsConnection, String, IObservable.T., Action.Exception.)

Writes the sequence of values to the symbol specified by the instance path.

Remarks

Reactive Extensions (Rx) are a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Using Rx, developers represent asynchronous data streams with Observables, query asynchronous data streams using LINQ operators, and parameterize the concurrency in the asynchronous data streams using Schedulers. Simply put, Rx = Observables + LINQ + Schedulers. The ADS reactive extensions are build on top of this library to enable ADS Symbol and State Observables, seamlessly bound to the reactive extensions. To use the ADS reactive extensions the TwinCAT.Ads.Reactive Nuget package (or the included TwinCAT.Ads.Reactive.dll) must be referenced. (Beckhoff.TwinCAT.Ads.Reactive package on Nuget).

Examples

Example1: Observe Value changed Notifications with the reactive AnyTypeExtensions

Observe a single changing ADS Symbols (Extended AdsNotifications, ANY_TYPE)

// To Test the Observer run a project on the local PLC System (Port 851)
using (TcAdsClient client = new TcAdsClient())
{
    // Connect to target
    client.Connect(new AmsAddress(AmsNetId.Local, 851));

    // Reactive Notification Handler
    var valueObserver = Observer.Create<ushort>(val =>
    {
    Console.WriteLine(string.Format("Value: {0}", val.ToString()));
    }
    );

    // Turning ADS Notifications into sequences of Value Objects (Taking 20 Values)
    // and subscribe to them.
    IDisposable subscription = client.WhenNotification<ushort>("TwinCAT_SystemInfoVarList._TaskInfo.CycleCount", NotificationSettings.Default).Take(20).Subscribe(valueObserver);

    Console.ReadKey(); // Wait for Key press
    subscription.Dispose(); // Dispose the Subscription
}

Examples

Example2: Polling ANY_TYPE values.

Observe changing ADS Symbols by polling (Read Polling) (ANY_TYPE)

// To Test the Observer run a project on the local PLC System (Port 851)
using (TcAdsClient client = new TcAdsClient())
{
    // 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"];

    // Reactive Notification Handler
    var valueObserver = Observer.Create<object>(val =>
    {
    Console.WriteLine(string.Format("Instance: {0}, Value: {1}", cycleCount.InstancePath, val.ToString()));
    }
    );

    // Take 20 Values in an Interval of 500ms
    IDisposable subscription = cycleCount.PollValues(TimeSpan.FromMilliseconds(500)).Take(20).Subscribe(valueObserver);

    Console.ReadKey(); // Wait for Key press
    subscription.Dispose(); // Dispose the Subscription
}

Examples

Write values sequentially.

Write sequences of values to the target (ANY_TYPE)

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 gvlIntSymbol = (IValueSymbol)symbolLoader.Symbols["GVL.i"];

    // Produces object (short) 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 = gvlIntSymbol.WriteValues(timerObservable.Take(10));

    Console.ReadKey(); // Wait for Key press
    dispose.Dispose(); // Dispose the Subscription
}

Reference

TwinCAT.Ads.Reactive Namespace

TwinCAT.Ads.Reactive.AdsClientExtensions

TwinCAT.Ads.Reactive.ValueSymbolExtensions