How could I start/restart/shutdoown TwinCAT System runtime from console or C# application? I need a functionality equivalent to the TwinCAT toolbar buttons System Start/Restart on the lower right. Thanks.
3 Answers
You can use the TwinCAT automation interface, which is accessible by linking the automation interface DLL from a C#/.NET-program.
Specifically, to start/restart TwinCAT you use the ITcSysManager::StartRestartTwinCAT - method

- 1,288
- 7
- 13
-
1Thank you, I have linked the automation interface DLL but when I instance the `systemManager = new TcSysManager();` as seen in the TwnCAT documentation it throws me a runtime error of _missing method exception: no constructor without parameters defined for the object_. But I can neither put a constructor with parameters because it says it does not exist and gives me a compile error. – Beorne Jan 08 '19 at 09:13
This can be accomplished be accomplished using the C# .net ADS library. To change the TwinCAT runtime between Config and Run, connect to the System Service ADS port (port 10000) and set the state to AdsState.Run
or AdsState.Config
.
All valid state values can be found here. All the port values can be found here.
static void Main(string[] args)
{
//Create a new instance of class TcAdsClient
TcAdsClient tcClient = new TcAdsClient();
try
{
// Connect to TwinCAT System Service port 10000
tcClient.Connect(AmsPort.SystemService);
// Send desired state
tcClient.WriteControl(new StateInfo(AdsState.Config, tcClient.ReadState().DeviceState));
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
finally
{
tcClient.Dispose();
}
}

- 338
- 1
- 9
TcXaeMgmt needs to be installed to PS v4.0+ https://www.powershellgallery.com/packages/TcXaeMgmt/3.2.21
Than in Powershell type: Set-AdsState Stop or Set-AdsState Start
Details here: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_ads_ps_tcxaemgmt/4130762891.html&id=4912948515382920501

- 101
- 1
- 3