问题
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.
回答1:
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();
}
}
回答2:
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
来源:https://stackoverflow.com/questions/54077462/how-to-startup-shutdown-twincat-system-from-console-c-sharp-program