Beckhoff.TwinCAT.Ads.Reactive 5.0.0-preview7

Reactive extensions for Beckhoff.TwinCAT.AdsClient
Extends the AdsClient object with Reactive Interfaces for ADS Notifications to support observable Streams of
value changes.

This is a prerelease version of Beckhoff.TwinCAT.Ads.Reactive.
There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package Beckhoff.TwinCAT.Ads.Reactive -Version 5.0.0-preview7
dotnet add package Beckhoff.TwinCAT.Ads.Reactive --version 5.0.0-preview7
<PackageReference Include="Beckhoff.TwinCAT.Ads.Reactive" Version="5.0.0-preview7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Beckhoff.TwinCAT.Ads.Reactive --version 5.0.0-preview7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Description

The package 'Beckhoff.TwinCAT.Ads.Reactive' implements reactive extensions for the TwinCAT.Ads.AdsClient class included in the
'Beckhoff.TwinCAT.Ads' package.

Reactive Extensions (Rx) is a .NET 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.

In ADS terms, not only the reading and writing data or symbol values can be put into reactive data streams, also ADS Notifications or polling of values are a perfect
fit for reactive code.
With the help of this package not only data binding to reactive frameworks (e.g. reactive UI) is simplified but also enhanced data manipulation via synchronous and asynchronous
observers.
Multithreaded and parallelized code paths that support multiple CPU cores can be written very easily without the burden of deadlock and synchronization issues.

Requirements

  • .NET Core 3.0, .NET Framework 4.61 or .NET Standard 2.0 compatible SDK or later
  • A TwinCAT 3.1.4024 Build (XAE, XAR or ADS Setup) or alternatively the Beckhoff.TwinCAT.AdsRouterConsole Application
  • Installed Nuget package manager (for systems without Visual Studio installation)

Installation

System with TwinCAT System Service (TCP Loopback enabled, Versions 4024.0 and 4025.5)

  1. Running TwinCAT 3.1.4024 Installation

  2. Stop TwinCAT System Service

  3. Enable TCP Loopback for TwinCAT 3.1.4024.0 or 3.1.4024.4 via regkey:
    32-Bit Windows Operating System:

     HKEY_LOCAL_MACHINE\SOFTWARE\Beckhoff\TwinCAT3\System\EnableAmsTcpLoopbackDWORD (1)
    

    64-Bit Windows Operating System:

     HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Beckhoff\TwinCAT3\System\EnableAmsTcpLoopback	DWORD(1)
    

    Systems >= 3.1.4024.5 support TCPLoopback out of the box. No registry changes necessary

  4. Restart TwinCAT System Service

First Steps

The following code instantiates an AdsClient object, connects to the local PLC System Port 851 and subscribes fir the first 20 change notifications
of the Task cycle count and writes the value to the Console.

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

Description

The package 'Beckhoff.TwinCAT.Ads.Reactive' implements reactive extensions for the TwinCAT.Ads.AdsClient class included in the
'Beckhoff.TwinCAT.Ads' package.

Reactive Extensions (Rx) is a .NET 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.

In ADS terms, not only the reading and writing data or symbol values can be put into reactive data streams, also ADS Notifications or polling of values are a perfect
fit for reactive code.
With the help of this package not only data binding to reactive frameworks (e.g. reactive UI) is simplified but also enhanced data manipulation via synchronous and asynchronous
observers.
Multithreaded and parallelized code paths that support multiple CPU cores can be written very easily without the burden of deadlock and synchronization issues.

Requirements

  • .NET Core 3.0, .NET Framework 4.61 or .NET Standard 2.0 compatible SDK or later
  • A TwinCAT 3.1.4024 Build (XAE, XAR or ADS Setup) or alternatively the Beckhoff.TwinCAT.AdsRouterConsole Application
  • Installed Nuget package manager (for systems without Visual Studio installation)

Installation

System with TwinCAT System Service (TCP Loopback enabled, Versions 4024.0 and 4025.5)

  1. Running TwinCAT 3.1.4024 Installation

  2. Stop TwinCAT System Service

  3. Enable TCP Loopback for TwinCAT 3.1.4024.0 or 3.1.4024.4 via regkey:
    32-Bit Windows Operating System:

     HKEY_LOCAL_MACHINE\SOFTWARE\Beckhoff\TwinCAT3\System\EnableAmsTcpLoopbackDWORD (1)
    

    64-Bit Windows Operating System:

     HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Beckhoff\TwinCAT3\System\EnableAmsTcpLoopback	DWORD(1)
    

    Systems >= 3.1.4024.5 support TCPLoopback out of the box. No registry changes necessary

  4. Restart TwinCAT System Service

First Steps

The following code instantiates an AdsClient object, connects to the local PLC System Port 851 and subscribes fir the first 20 change notifications
of the Task cycle count and writes the value to the Console.

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

Release Notes

Preview version of the Beckhoff.TwinCAT.Ads 5.0.0 Version branch. Don't use for productive code.

GitHub repositories (0)

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.0.0-preview8 82 6/5/2020
5.0.0-preview7 89 5/29/2020
4.4.6 155 5/29/2020
4.4.5 109 4/30/2020
4.4.4 183 4/7/2020
4.3.14 119 4/7/2020