使用C#从wincc中读取

时间:2015-06-08 06:44:02

标签: c# plc opc

我需要开发一个通过wincc界面读取PLC中的某些值的应用程序,我已经环顾四周,但我发现所有使用第三方软件的示例。我需要的功能是非常基本的:我只需要读取PLC中的值,而无需进一步的通信。有一种简单的方法可以做到这一点吗?

3 个答案:

答案 0 :(得分:1)

通过Wincc读取PLC值:

初看起来,我建议使用OPC,TCP电报或某些第三方库(如libnodave)直接通过PLC读取。它使用起来更加高效和优雅。

现在回到你的问题,你需要wincc来为你的应用程序提供价值。我会建议如下:

  1. 创建.net控件或全局脚本。
  2. 创建wcf服务或数据库连接接口(取决于您的应用程序)。
  3. 在wincc控件中连接plc发送值的标记,并通过wcf或数据库接口填充它。
  4. 我认为这种方式从wincc获取值而不影响wincc更清晰。 另一方面,您也可以使用wincc作为opc服务器。

答案 1 :(得分:0)

Your question is a bit vague. The description you gave is a basic WinCC functionality. To read out a value from the PLC (called a tag) and display it in WinCC. I think that is not the question.

Do you mean to read out a tag (internel or external) from WinCC to your own application? That can be done with the ODK option in WinCC. But that is, like every development kit in Scada/DCS, not available for free.

Or you want to read out a value from the PLC that is also used in WinCC, you need a S7 connection or a open communication. S7 requires a connection resource and configuration in the PLC. Open Communication (done via TCP/IP) needs programming in the PLC.

答案 2 :(得分:0)

以下是使用WinCC的程序标识符的示例:

System.Type oType = System.Type.GetTypeFromProgID("WinCC-Runtime-Project");
object wincc = System.Activator.CreateInstance(oType);

//Read the name of the runtime database (the @-Prefix identifies WinCC-System-Tags)
object catalog = oType.InvokeMember("GetValue", System.Reflection.BindingFlags.InvokeMethod, null, wincc, new object[] { "@DatasourceNameRT" });

//Read the computer name
object serverName = oType.InvokeMember("GetValue", System.Reflection.BindingFlags.InvokeMethod, null, wincc, new object[] { "@ServerName" });

//Read a WinCC-Tag with the name "MyTag"
object myTag = oType.InvokeMember("GetValue", System.Reflection.BindingFlags.InvokeMethod, null, wincc, new object[] { "MyTag" });
相关问题