【问题标题】:What do I need to create simple C# app which uses OPC?创建使用 OPC 的简单 C# 应用程序需要什么?
【发布时间】:2023-03-06 14:35:01
【问题描述】:

我需要编写一个简单的 c# 应用程序,通过 OPC 与 Siemens S7 进行通信。它只需要查询单个输入并设置单个输出。

我需要做什么?我需要来自 OPCFoundation 的 Xi 之类的东西吗?

【问题讨论】:

    标签: c# opc siemens


    【解决方案1】:

    作为更通用的 OPC 解决方案,http://www.codeproject.com/KB/COM/opcdotnet.aspx 可能值得一看 - 它是一个免费的 OPC DLL,带有完整的源代码。虽然它非常基本,但代码就在那里,因此您可以在需要时轻松更新它,但从您的需求来看,它可能是理想的。

    【讨论】:

    • 感谢您的链接,加文。看到日期我有点惊讶 - 2001 年!
    • 它可能是旧的,但它仍然有效! DLL 中的某些代码可能会被重写以利用 .NET 中可用的新功能,但如果它没有损坏...
    【解决方案2】:

    您可能会查看 www.quickopc.com,它提供了 .NET 和 OPC 服务器之间的完美包装。 www.opcfoundation.com 上还有很多关于 OPC 服务器的信息,您自己已经找到了。

    如果您不使用 QuickOPC 等库,则必须创建自己的类来将二进制数据转换为可读的 .NET 代码(这必须是一项任务本身)。这是完全可行的,主要缺点是每个设备/制造商都有自己的协议,这意味着您最终可以为每个唯一设备使用一个包装器。

    【讨论】:

    • 同意关于向 OPC 基金会注册的评论。那里有很多信息,包括参考文档和示例代码。
    【解决方案3】:

    听起来您可能已经拥有适用于 Siemens S7 的 OPC Server。 Kepware、Simatic Net 和许多其他公司都支持 OPC UA。

    您可以使用这些免费工具在 C# 中构建一个简单的 HMI 应用程序:

    1. Microsoft Visual Studio Express 2013 for Windows Desktop 可从:http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-windows-desktop 获得。

    2. 本站最新出处: http://web.archive.org/web/20140219181837/http://opcuaservicesforwpf.codeplex.com/

    使用此套件,您可以: 直接从 Visual Studio IDE 浏览 OPC UA 服务器。拖放变量节点以创建数据订阅。使用绑定根据订阅的数据值为 UI 控件的属性设置动画。

    查看示例应用程序“工作站”。

    【讨论】:

      【解决方案4】:
      【解决方案5】:

      另一种可能性是使用 Siemens SAPI-S7 接口(这是本机 Siemens 协议,OPC 也使用它)。 SoftwareOption GmbH 有一个带有 C# 示例的 S7 .NET 编程接口。 您可以下载包含 C# 演示程序的源代码。 见http://www.softwareoption.de/siemens-produkte_e.htm

      【讨论】:

        【解决方案6】:

        我现在正在经历这个过程,我发现他很有用:http://www.opcti.com/Download-OPC-Xi-source-code.aspx

        【讨论】:

          【解决方案7】:

          使用任何中间 dll,例如 opcdaauto.dll、clientAce、MXIO.NET。

          使用 C# 开始编码。C# 提供了与 OPC Server 通信的灵活性。

          西门子使用 C# 的示例: 在 App.config 中:

              Tag1 value="SERVER:\DiagnosticsSummary\CumulatedSubscriptionCount"
              Tag2 value="SERVER:\Capabilities\MinSupportedUpdateRate"
              ServerId value="opcda://localhost/OPC.SimaticNET.1/{B6EACB30-42D5-11D0-9517-0020AFAA4B3C}"/>
          

          --享受编码-- 参考:http://www.revanayya.blogspot.com

          【讨论】:

            【解决方案8】:

            只是用替代解决方案填写列表: 如果您只想从 Siemens S7 读取/写入一些数据/输入/输出/标记,则不必使用 OPC。多年来,我一直在使用 libnodave 没有任何问题。只要您在 plc 的硬件配置中启用 put/get 访问并访问“未优化”数据块,就可以正常工作。 Libnodave 声明它适用于 S7-200,300,400。但我们也将它与 1200 和 1500 一起使用。 网上有几个来源,例如http://libnodave.sourceforge.net/

            【讨论】:

              【解决方案9】:
              #region Variable Declaration
               public static Kepware.ClientAce.OpcDaClient.DaServerMgt ObjDaServerMgt = new Kepware.ClientAce.OpcDaClient.DaServerMgt();
                          public static Kepware.ClientAce.OpcDaClient.ConnectInfo ObjConnectInfo = new Kepware.ClientAce.OpcDaClient.ConnectInfo();
                          public static Kepware.ClientAce.OpcDaClient.ReturnCode ObjReturnCode = new Kepware.ClientAce.OpcDaClient.ReturnCode();
                          public static Kepware.ClientAce.OpcDaClient.ItemIdentifier[] ObjItemIdentifiers = new Kepware.ClientAce.OpcDaClient.ItemIdentifier[2];
              #endregion
              
              
              public void Connect()
              {
              
                          string OPC_url_Simatic = ConfigurationManager.AppSettings["ServerId"].ToString();
              
              
                              ObjConnectInfo.LocalId = "en";
                              ObjConnectInfo.KeepAliveTime = 5000;
                              ObjConnectInfo.RetryAfterConnectionError = true;
                              ObjConnectInfo.RetryInitialConnection = true;
                              bool connectFailed = false;
              
                              ///define a client handle
                              int clientHandle = 1;
              
                              //Try to connect with the API connect method:
                              try
                              {
                                  ObjDaServerMgt.Connect(OPC_url_Simatic, clientHandle, ref ObjConnectInfo, out connectFailed);
                              }
                              catch (Exception ex)
                              {
                                 // MessageBox.Show("Handled Connect exception. Reason: " + ex.Message);.
                                  log.Error(ex.ToString());
                                  // Make sure following code knows connection failed:
                                  connectFailed = true;
                              }
                              // Handle result:
                              if (connectFailed)
                              {
                                  // Tell user connection attempt failed:
                                  //MessageBox.Show("Connect failed");
                                  log.Error("Connection Failed");
                              }
              }
              

              注册一些事件处理程序并完成工作。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多