我需要从一个TwinCAT应用程序启动/关闭C# 3.0。正如在如何从控制台/ TwinCAT程序启动/关闭C#系统?中友好回答的那样,我可以使用TwinCAT自动化接口。在TC2.0中,可以简单地用以下方法实例化自动化接口:
var systemManager = new TcSysManager(); // missing method exception:
// no constructor without parameters defined在TC 3中,它给出了上面的运行时错误。
似乎我需要一个Visual实例,在PC上,我想要使用自动化接口。具有自动化功能的面板PC在一台机器上,没有安装VS。
是否可以使用“自动化接口”,或者以编程方式启动/关闭TC 3.0,而无需在计算机上安装Visual?谢谢。
发布于 2019-05-07 21:17:14
几乎正确,端口必须是AmsPort.SystemService (10000)
然后
若要从配置中重新启动PLC,请使用AdsState.Reset (.Run将无法工作)
在ConfigMode中设置可编程控制器使用AdsState.Reconfig (.Config将不工作)
.Devstate:可能是0或者其他什么的。
检查PLC是否在RunMode或Config中,等等。(一些vb.net代码)
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)发布于 2019-01-17 00:59:23
下面的答案是启动和停止特定的PLC实例。若要在Config和Run之间更改整个TwinCAT运行时,请连接到Service端口(端口10000),并将状态设置为AdsState.Run或AdsState.Config。
所有有效的状态值都可以找到这里。所有的端口值都可以找到这里。
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();
}
}要以编程方式启动或停止TwinCAT运行时,可以使用ADS命令将AdsState更改为运行或停止。贝克霍夫为此提供了C#和C++库。一个C#示例:
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();
}
}来源:net/185266187.html&id=6127144084214800894
下面是一个C++示例:adsdll2/9007199379562763.html&id=8444596171373533137
据我所知,自动化接口至少需要安装。当您使用自动化接口时,您可以看到在后台启动的devenv.exe实例。
https://stackoverflow.com/questions/54094565
复制相似问题