如何从控制台/ C#程序启动/关闭TwinCAT系统?

时间:2019-01-07 15:44:57

标签: c# twincat

如何从控制台或C#应用程序启动/重新启动/关闭TwinCAT系统运行时?我需要的功能等同于右下角的TwinCAT工具栏按钮“系统启动/重新启动”。 谢谢。

3 个答案:

答案 0 :(得分:2)

您可以使用TwinCAT automation interfacelinking the automation interface DLL可通过C#/。NET程序进行访问。

具体来说,要启动/重新启动TwinCAT,请使用ITcSysManager::StartRestartTwinCAT-方法

答案 1 :(得分:1)

这可以使用C#.net ADS库来完成。要在配置和运行之间更改TwinCAT运行时,请连接到系统服务ADS端口(端口10000),并将状态设置为AdsState.RunAdsState.Config

可以找到所有有效状态值here。可以在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 :(得分:0)

TcXaeMgmt需要安装到PS v4.0 + https://www.powershellgallery.com/packages/TcXaeMgmt/3.2.21

比在Powershell中输入: Set-AdsState停止 要么 Set-AdsState开始

详细信息在这里: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_ads_ps_tcxaemgmt/4130762891.html&id=4912948515382920501