TwinSharp.Core 1.2.0

dotnet add package TwinSharp.Core --version 1.2.0
                    
NuGet\Install-Package TwinSharp.Core -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TwinSharp.Core" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TwinSharp.Core" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TwinSharp.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TwinSharp.Core --version 1.2.0
                    
#r "nuget: TwinSharp.Core, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TwinSharp.Core@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TwinSharp.Core&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TwinSharp.Core&version=1.2.0
                    
Install as a Cake Tool

TwinSharp

TwinSharp is a free open source library for .NET that makes it easy to represent and control TwinCAT objects in C#. It communicates with ADS to a TwinCAT XAR system running locally or on a remote target.

TwinSharp connects to all TwinCAT 3 systems and does not require any special adaptation or PLC code running on the targeted system.

For example TwinSharp can be used to connect to a remote TwinCAT axis and read its status and settings. Here's a custom user control built using TwinSharp. It mimics the "Axis online" view from TwinCAT but does not require TwinCAT XAE to be installed.

online-view

Here's a list of some major components that can be viewed, altered and controlled with TwinSharp. For a full list, please refer to the documentation or ask 😃

EtherCAT

  • List all EtherCAT masters that exists in a local or remote system.
  • Get information about all configured EtherCAT slaves.
  • Get information about all connected EtherCAT slaves.
  • Get information about the topology of the network.
  • Read abnormal state change count of slaves.
  • CoE read and write to masters and slaves.

To find all EtherCAT masters on a target system, first create a TcSystem and then ues the method ListEtherCatMasters().

var target = AmsNetId.Local;
var tcSystem = new TcSystem(target);
var masters = tcSystem.ListEtherCatMasters();

Realtime system

  • Read and set the number of shared/isolated cores.
  • Read the CPU usage.
  • Read the TwinCAT system CPU latency.

To create a TwinSharp representation of the realtime system, first create a TcSystem object. Then the real time object can be found there.

var target = AmsNetId.Local;
var tcSystem = new TcSystem(target);
var realtime = tcSystem.Realtime;

PLC

  • Start, stop and reset a PLC on the local or remote TwinCAT system.
  • Read the number of "online changes" in the PLC.
  • Read if Windows is in a BSOD.
  • Read if Windows on the TwinCAT system is shutting down.
  • Read the timestamp of when the PLC was compiled.
  • Control if outputs should be zeroed when a breakpoint is hit in the PLC.

Create a representation of a TwinCAT PLC like this:

var plcClient = new AdsClient();
plcClient.Connect(AmsPort.PlcRuntime_851);
var plc = new PLC(plcClient);

NC Motion

  • View all available axes on a TwinCAT system.
  • Command motion to axes.
  • Couple axes.
  • Change axis encoder scaling, on the fly.
  • Set current position.
  • Enable or disable axis monitoring functions.
  • View and change axis settings including those of the encoder and drive.
  • Control axis channels and axis groups.
  • Control, modify and delete NC tables.

Create an NC object that contains all axes, channels, groups and tables on a target like this:

var target = AmsNetId.Local;
var nc = new NC(target);

IPC

The IPC class describes a Beckhoff Industrial PC.

  • Read temperatures of CPU and main board.
  • Read the boot count and current uptime.
  • Read BIOS version.
  • Read fan speed RPM.
  • Control Network cards, IP adresses, DHCP etc.
  • Read status of connected UPS, such as battery capacity, power fail count, fan error etc.
  • Read version of installed TwinCAT version and operating system version.
  • Control screen brightness of connected Beckhoff screens.
  • Disable/enable the Beckhoff security wizard.
  • Control current time and timezone of the TwinCAT system.

To create a TwinSharp representation of a local IPC do like this:

var target = AmsNetId.Local;
var ipc = new IPC(target);

File system

  • Create, delete, rename, view or write files and folders on a TwinCAT system.
  • Search for files.
  • View file properties and attributes.

To create a file system object, first create a TcSystem object. Then the file system object can be found there.

var target = AmsNetId.Local;
var tcSystem = new TcSystem(target);
var fileSystem = tcSystem.FileSystem;

License system

  • Get a list of valid licenses that exists on a remote or local target.
  • Get a list of invalid licenses.

To get the License object which provides access to the TwinCAT system's license information, you first create a TcSystem with your desired AmsNetId.

var target = AmsNetId.Local; 
var tcSystem = new TcSystem(target);
var licenseSystem = tcSystem.License;

Various

TwinSharp can list all AMS routes that exists on the local system. It is a static method in the TcSystem class.

AmsRoute[] routes = TcSystem.ListLocalStaticRoutes();

Installation

Clone/download this project and build with Visual Studio. Or get the NuGet package: https://www.nuget.org/packages/TwinSharp.Core

Additional info

Development has been focused on TwinCAT 3 systems.

Useful resources have been:

This project is not affiliated or endorsed with Beckhoff in any way. I'm simply a guy who love all stuff Beckhoff/EtherCAT and try to make it available to as many as possible.

Beckhoff®, TwinCAT®, TwinCAT/BSD®, TC/BSD®, EtherCAT®, EtherCAT G®, EtherCAT G10®, EtherCAT P®, Safety over EtherCAT®, TwinSAFE®, XFC®, XTS® and XPlanar® are registered trademarks of and licensed by Beckhoff Automation GmbH.

License

TwinSharp is provided under the permissive MIT license and is free to modify and use for any purpose.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 113 3/19/2026
1.1.0 218 8/22/2025
1.0.0 197 1/14/2025