Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 没有Visual Studio的TwinCAT 3.0自动化界面?_C#_Twincat - Fatal编程技术网

C# 没有Visual Studio的TwinCAT 3.0自动化界面?

C# 没有Visual Studio的TwinCAT 3.0自动化界面?,c#,twincat,C#,Twincat,我需要从C#应用程序启动/关闭TwinCAT 3.0。 如中所述,我可以使用TwinCAT自动化接口。 而在TC 2.0中,可以简单地实例化自动化接口: var systemManager = new TcSysManager(); // missing method exception: // no constructor without parameters defined 在tc3中,它给出了上面的运行时

我需要从C#应用程序启动/关闭TwinCAT 3.0。 如中所述,我可以使用TwinCAT自动化接口。 而在TC 2.0中,可以简单地实例化自动化接口:

var systemManager = new TcSysManager(); // missing method exception: 
                                        //  no constructor without parameters defined
在tc3中,它给出了上面的运行时错误

似乎我需要在PC上安装一个VisualStudio实例,以便使用自动化界面。带有自动化功能的面板式PC位于机器上,未安装VS

是否可以使用自动化界面,或者在计算机上未安装Visual Studio的情况下以编程方式启动/关闭TC 3.0?
谢谢。

下面的答案用于启动和停止特定的PLC实例。要在配置和运行之间更改整个TwinCAT运行时,请连接到系统服务ADS端口(端口10000),并将状态设置为
AdsState.Run
AdsState.Config

可以找到所有有效的状态值。可以找到所有端口值


要以编程方式启动或停止TwinCAT运行时,可以使用ADS命令将AdsState更改为运行或停止。贝克霍夫为此提供了C语言和C++库。一个C#示例:

资料来源:

一个C++例子,这里是:



据我所知,自动化界面至少需要安装VisualStudioShell。使用Automation Interface时,可以看到在后台启动的
devenv.exe
实例

几乎正确,端口必须是AmsPort.SystemService(10000)
然后
要从配置重新启动PLC,请使用AdsState.Reset(.Run将不起作用)
要将PLC设置为配置模式,请使用AdsState.Reconfig(.Config wil not work)

.Devstate:可能是0或其他任何值

检查PLC是否处于运行模式或配置等。。(一些vb.net代码)


非常感谢,但我需要TwinCAT系统启动/重新启动和配置(如工具栏上的那些),而不是PLC运行/停止。@这也可以通过ADS实现。我将更新答案。是的,在端口10000上,我可以重新启动和混淆系统。非常感谢。
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();
        }
    }
static void Main(string[] args)
{
    //Create a new instance of class TcAdsClient
    TcAdsClient tcClient = new TcAdsClient();

    try
    {
        // Connect to local PLC - Runtime 1 - TwinCAT 3 Port=851
        tcClient.Connect(851);

                Console.WriteLine(" PLC Run\t[R]");
                Console.WriteLine(" PLC Stop\t[S]");
                Console.WriteLine("\r\nPlease choose \"Run\" or \"Stop\" and confirm with enter..");
                string sInput = Console.ReadLine().ToLower();

        //Process user input and apply chosen state
        do{
            switch (sInput)
            {
                case "r": tcClient.WriteControl(new StateInfo(AdsState.Run, tcClient.ReadState().DeviceState)); break;
                case "s": tcClient.WriteControl(new StateInfo(AdsState.Stop, tcClient.ReadState().DeviceState)); break;
                default: Console.WriteLine("Please choose \"Run\" or \"Stop\" and confirm with enter.."); sInput = Console.ReadLine().ToLower(); break;
            }
        } while (sInput != "r" && sInput != "s");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.ReadKey();
    }
    finally
    {
        tcClient.Dispose();
    }
}
 Dim tc As New TcAdsClient
 Dim AdsStateInfo as StateInfo
 Try
     tc.Connect("", AmsPort.SystemService) '(AmsPort.SystemService=10000)
     AdsStateInfo = tc.ReadState
  Catch ex As Exception
     AdsStateInfo.AdsState = TwinCAT.Ads.AdsState.Error
     AdsStateInfo.DeviceState = 7 ' Error7 if not found
 End Try
 MsgBox("AdsState: "+ AdsStateInfo.AdsState.ToString)