Beckhoff.TwinCAT.Ads 5.0.0-preview4

The Beckhoff.TwinCAT.Ads package includes everything to develop own .NET applications (e.g. visualization, scientific automation) for communication with TwinCAT devices (e.g. PLC, NC or IO-devices).
Root object is the AdsClient to communicate to all variants of local and remote ADS servers and devices.

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

Description

The package 'Beckhoff.TwinCAT.Ads' contains a client implementation for the ADS Communication protocol used by .NET Core and .NET Full Framework.
It includes everything to develop own .NET applications (e.g. HMI, Datalogger) to communicate with TwinCAT devices (e.g. PLC, NC or IO-devices).

The Root object is the TwinCAT.Ads.AdsClient to communicate to all variants of local and remote ADS servers and devices or the AdsSession object.

Requirements

  • .NET Core 2.0, .NET Framework 4.61 or .NET Standard 2.0 compatible SDK or later
    For ADS clients on TwinCAT systems
  • A TwinCAT 3.1.4024 Build (XAE, XAR or ADS Setup) or alternatively the Beckhoff.TwinCAT.AdsRouterConsole Application
    For ADS clients on Non-TwinCAT systems
  • Nuget package 'Beckhoff.TwinCAT.Ads.AdsRouterConsole'. to route ADS communication

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

System without TwinCAT System Service

Install the 'Beckhoff.TwinCAT.Ads.AdsRouterConsole' package from Nuget.org:
PS> nuget install Beckhoff.TwinCAT.Ads.AdsRouterConsole

To enable ADS Communication via the AdsRouteConsole, the following settings have to be made:

  • Select the local unique AmsNetId and the route name of the system in the local "StaticRoutes.xml" beside of the AdsRouteConsole
  • Add remote connections to the local "StaticRoutes.xml".
  • Add the "Backroute" from the remote system linking to the your system (via AmsNeTId) running the AdsRouteConsole. This can be done
    within of a TwinCAT Project or via the TwinCAT System Tray icon.

An example of the local "StaticRoutes.xml" is given here:

<?xml version="1.0" encoding="utf-8"?>
<TcConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\TwinCAT3\Config\TcConfig.xsd">
  <Local>
      <Name>MyLocalSystem</Name>
      <NetId>192.168.1.22.1.1</NetId>
  </Local>
  <RemoteConnections>
    <Route>
      <Name>MyRemoteSystem</Name>
      <Address>RemoteSytem</Address> <!-- HostName -->
      <!--<Address>192.168.1.21</Address>  --> <!--IPAddress -->
      <NetId>192.168.1.21.1.1</NetId>
      <Type>TCP_IP</Type>
    </Route>
  </RemoteConnections>
</TcConfig>

First Steps

The following code instantiates an AdsClient object, connects to a target device (here the local System Service)
and reads the ADS state asynchronously.

using System;
using System.Threading.Tasks;
using System.Threading;
using TwinCAT.Ads;

namespace AdsAsyncTest
{
    class Program
    {
        static async Task Main(string[] args)
        {
            AdsClient myClient = new AdsClient();
            try
            {
                // Connect to local TwinCAT System Service
                myClient.Connect(AmsNetId.Local, 10000);
                ResultReadDeviceState result = await myClient.ReadStateAsync(CancellationToken.None);
                Console.WriteLine("State: " + result.State.AdsState);
                Console.WriteLine("Press key to exit...");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            finally
            {
                myClient.Dispose();
            }
        }
    }
}

Please be aware, that the AdsRouteConsole doesn't provide the AmsPort 10000, due to the missing TwinCAT System Service. Therefore the AmsNetId of the connection
must be changed to a registered remote system.

Hints

There are a few breaking changes in the new version to enable asynchronous programming, reducing the memory footprint and enhancement of the performance.
Nevertheless the usage the TwinCAT.Ads.AdsClient is very similar to the documented 4.3.0 Version of the class TwinCAT.Ads.TcAdsClient.

The Link to the Version 4.3.0 API documentation is:

https://infosys.beckhoff.com/content/1031/tcadsnetref/6358291723.html?id=8100459743587155746

Please use this documentation as long as the 'official' Version for ADS 5.0.0 is not released.

The main issues you will have with 'legacy' code:

  • Renaming the TcAdsClient class to AdsClient
  • Changing synchronous code to 'async'. The new asynchronous methods are indicated with “MethodNameAsync” and could be used very similar to their synchronous counterparts.
  • For using .NET Core more efficiently, all the AdsStream class appearances in method interfaces are replaced by the new more efficient Span<byte> and Memory[byte] classes.
  • AdsBinaryReader and AdsBinaryWriter should be replaced by using the standard BinaryReader and/or System.Buffers.Binary.BinaryPrimitives Methods.

VersionHistory

5.0.0-preview4

Breaking Change: Changing Parameterset of AddDeviceNotification, TryAddDeviceNotification and AddDeviceNotificationAsync methods.
The Memory&lt;byte&gt; parameter is replaced by the dataLength argument to reduce array copy operations (enhanced Performance) and for simplyfied use.

Fix: Corrections of text messages in 'Obsolete-warnings' where IndexGroup/IndexOffset is not used with the uint overload
Fix: Gap year correction (year 2400) for PlcOpen DataTypes DT and DATE.
Fix: Wrong implementation of the IsPersistant Datatype Flag (AdsDataTypeFlags.Persistent)
Enh: Pointer support for InvokeRpcMethod in parameters.
Fix: AdsNotifications are not received when size of data changes (e.g in Broadcast search)

5.0.0-preview3

Enh: Framework dependency for full framework changed (Net48 --> Net461)
Enh: Adding Framework target netcoreapp2.0
Enh: Optimizing Nuget Package dependencies
Enh: Consequently using DateTimeOffset instead of DateTime in interfaces and for ADS data marshalling

5.0.0-preview2

BreakingChange: Renaming AdsClient/AdsSession/IAdsSymbolicAccess Members
| OldName | NewName |
| ------------------- | --------------- |
| ReadSymbol | ReadValue |
| TryReadSymbol | TryReadValue |
| ReadSymbolAsync | ReadValueAsync |
| WriteSymbol | WriteValue |
| TryWriteSymbol | TryWriteValue |
| WriteSymbolAsync | WriteValueAsync |
| ReadSymbolInfo | ReadSymbol |
| TryReadSymbolInfo | TryReadSymbol |
| ReadSymbolInfoAsync | ReadSymbolAsync |

Fix: Asynchronity (Race-Conditions) with ADS Notifications.
Enh: Refactoring internal synchronous code paths. Keeping Sync paths synchronous reduce mixing of sync/async code.
Enh: Faster delivery of ADS Notifications

5.0.0-preview1

Description

The package 'Beckhoff.TwinCAT.Ads' contains a client implementation for the ADS Communication protocol used by .NET Core and .NET Full Framework.
It includes everything to develop own .NET applications (e.g. HMI, Datalogger) to communicate with TwinCAT devices (e.g. PLC, NC or IO-devices).

The Root object is the TwinCAT.Ads.AdsClient to communicate to all variants of local and remote ADS servers and devices or the AdsSession object.

Requirements

  • .NET Core 2.0, .NET Framework 4.61 or .NET Standard 2.0 compatible SDK or later
    For ADS clients on TwinCAT systems
  • A TwinCAT 3.1.4024 Build (XAE, XAR or ADS Setup) or alternatively the Beckhoff.TwinCAT.AdsRouterConsole Application
    For ADS clients on Non-TwinCAT systems
  • Nuget package 'Beckhoff.TwinCAT.Ads.AdsRouterConsole'. to route ADS communication

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

System without TwinCAT System Service

Install the 'Beckhoff.TwinCAT.Ads.AdsRouterConsole' package from Nuget.org:
PS> nuget install Beckhoff.TwinCAT.Ads.AdsRouterConsole

To enable ADS Communication via the AdsRouteConsole, the following settings have to be made:

  • Select the local unique AmsNetId and the route name of the system in the local "StaticRoutes.xml" beside of the AdsRouteConsole
  • Add remote connections to the local "StaticRoutes.xml".
  • Add the "Backroute" from the remote system linking to the your system (via AmsNeTId) running the AdsRouteConsole. This can be done
    within of a TwinCAT Project or via the TwinCAT System Tray icon.

An example of the local "StaticRoutes.xml" is given here:

<?xml version="1.0" encoding="utf-8"?>
<TcConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\TwinCAT3\Config\TcConfig.xsd">
  <Local>
      <Name>MyLocalSystem</Name>
      <NetId>192.168.1.22.1.1</NetId>
  </Local>
  <RemoteConnections>
    <Route>
      <Name>MyRemoteSystem</Name>
      <Address>RemoteSytem</Address> <!-- HostName -->
      <!--<Address>192.168.1.21</Address>  --> <!--IPAddress -->
      <NetId>192.168.1.21.1.1</NetId>
      <Type>TCP_IP</Type>
    </Route>
  </RemoteConnections>
</TcConfig>

First Steps

The following code instantiates an AdsClient object, connects to a target device (here the local System Service)
and reads the ADS state asynchronously.

using System;
using System.Threading.Tasks;
using System.Threading;
using TwinCAT.Ads;

namespace AdsAsyncTest
{
    class Program
    {
        static async Task Main(string[] args)
        {
            AdsClient myClient = new AdsClient();
            try
            {
                // Connect to local TwinCAT System Service
                myClient.Connect(AmsNetId.Local, 10000);
                ResultReadDeviceState result = await myClient.ReadStateAsync(CancellationToken.None);
                Console.WriteLine("State: " + result.State.AdsState);
                Console.WriteLine("Press key to exit...");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            finally
            {
                myClient.Dispose();
            }
        }
    }
}

Please be aware, that the AdsRouteConsole doesn't provide the AmsPort 10000, due to the missing TwinCAT System Service. Therefore the AmsNetId of the connection
must be changed to a registered remote system.

Hints

There are a few breaking changes in the new version to enable asynchronous programming, reducing the memory footprint and enhancement of the performance.
Nevertheless the usage the TwinCAT.Ads.AdsClient is very similar to the documented 4.3.0 Version of the class TwinCAT.Ads.TcAdsClient.

The Link to the Version 4.3.0 API documentation is:

https://infosys.beckhoff.com/content/1031/tcadsnetref/6358291723.html?id=8100459743587155746

Please use this documentation as long as the 'official' Version for ADS 5.0.0 is not released.

The main issues you will have with 'legacy' code:

  • Renaming the TcAdsClient class to AdsClient
  • Changing synchronous code to 'async'. The new asynchronous methods are indicated with “MethodNameAsync” and could be used very similar to their synchronous counterparts.
  • For using .NET Core more efficiently, all the AdsStream class appearances in method interfaces are replaced by the new more efficient Span<byte> and Memory[byte] classes.
  • AdsBinaryReader and AdsBinaryWriter should be replaced by using the standard BinaryReader and/or System.Buffers.Binary.BinaryPrimitives Methods.

VersionHistory

5.0.0-preview4

Breaking Change: Changing Parameterset of AddDeviceNotification, TryAddDeviceNotification and AddDeviceNotificationAsync methods.
The Memory&lt;byte&gt; parameter is replaced by the dataLength argument to reduce array copy operations (enhanced Performance) and for simplyfied use.

Fix: Corrections of text messages in 'Obsolete-warnings' where IndexGroup/IndexOffset is not used with the uint overload
Fix: Gap year correction (year 2400) for PlcOpen DataTypes DT and DATE.
Fix: Wrong implementation of the IsPersistant Datatype Flag (AdsDataTypeFlags.Persistent)
Enh: Pointer support for InvokeRpcMethod in parameters.
Fix: AdsNotifications are not received when size of data changes (e.g in Broadcast search)

5.0.0-preview3

Enh: Framework dependency for full framework changed (Net48 --> Net461)
Enh: Adding Framework target netcoreapp2.0
Enh: Optimizing Nuget Package dependencies
Enh: Consequently using DateTimeOffset instead of DateTime in interfaces and for ADS data marshalling

5.0.0-preview2

BreakingChange: Renaming AdsClient/AdsSession/IAdsSymbolicAccess Members
| OldName | NewName |
| ------------------- | --------------- |
| ReadSymbol | ReadValue |
| TryReadSymbol | TryReadValue |
| ReadSymbolAsync | ReadValueAsync |
| WriteSymbol | WriteValue |
| TryWriteSymbol | TryWriteValue |
| WriteSymbolAsync | WriteValueAsync |
| ReadSymbolInfo | ReadSymbol |
| TryReadSymbolInfo | TryReadSymbol |
| ReadSymbolInfoAsync | ReadSymbolAsync |

Fix: Asynchronity (Race-Conditions) with ADS Notifications.
Enh: Refactoring internal synchronous code paths. Keeping Sync paths synchronous reduce mixing of sync/async code.
Enh: Faster delivery of ADS Notifications

5.0.0-preview1

Release Notes

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

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.0.0-preview4 900 12/12/2019
4.4.0 244 2/5/2020
4.3.11 1,113 12/17/2019
4.3.10 3,141 10/7/2019
4.3.8 4,196 8/2/2019
4.3.7 3,547 6/27/2019
4.3.5 1,174 6/4/2019
4.3.4 1,074 4/12/2019