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 |
---|---|---|
|
Polls the symbol values on timepoints where the polling observable streams data / triggers | |
|
Polls the symbol as value sequence of object values with a specified period time. | |
|
Polls the symbol as value sequence of object values with a specified period time. | |
|
PollValues(IAdsConnection, String, Type, IObservable.Unit., Func.Exception, Object.) |
Polls the symbol values on timepoints where the polling observable streams data / triggers |
|
PollValues(IAdsConnection, String, Type, TimeSpan, Func.Exception, Object.) |
Polls the symbol as value sequence of object values with a specified period time. |
|
PollValues(IAdsConnection, String, Type, .Int32., IObservable.Unit., Func.Exception, Object.) |
Polls the symbol values on time points where the polling observable streams data / triggers |
|
PollValues(IAdsConnection, String, Type, .Int32., TimeSpan, Func.Exception, Object.) |
Polls the symbol as value sequence of object values with a specified period time. |
|
Polls the symbol values on timepoints where the polling observable streams data / triggers | |
|
Polls the symbol as value sequence of object values with a specified period time. | |
|
PollValues.T.(IAdsConnection, String, .Int32., IObservable.Unit.) |
Polls the symbol values on time points where the polling observable streams data / triggers |
|
Polls the symbol as value sequence of object values with a specified period time. | |
|
PollValues.T.(IAdsConnection, String, IObservable.Unit., Func.Exception, T.) |
Polls the symbol values on timepoints where the polling observable streams data / triggers |
|
PollValues.T.(IAdsConnection, String, TimeSpan, Func.Exception, T.) |
Polls the symbol as value sequence of object values with a specified period time. |
|
PollValues.T.(IAdsConnection, String, .Int32., IObservable.Unit., Func.Exception, T.) |
Polls the symbol values on timepoints where the polling observable streams data / triggers |
|
PollValues.T.(IAdsConnection, String, .Int32., TimeSpan, Func.Exception, T.) |
Polls the symbol as value sequence of object values with a specified period time. |
|
Writes the sequence of values to the symbol specified by the instance path. | |
|
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
}