创建使用 OPC 的简单 C# 应用程序需要什么?

发布于 2024-10-18 13:30:46 字数 117 浏览 4 评论 0原文

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

我需要做什么才能做到这一点?我需要 OPCFoundation 的 Xi 这样的东西吗?

I need to write a simple c# app which communicates with a Siemens S7 via OPC. It just needs to query single inputs and set single outputs.

What do I need to do this? Do I need stuff like Xi from OPCFoundation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

佼人 2024-10-25 13:30:46

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

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

You would probably check www.quickopc.com which deliver a perfectly wrapper between .NET and OPC Servers. There are also a lot of information for OPC Servers by www.opcfoundation.com, which you already find out yourself.

If you don't use libraries such as QuickOPC you have to deal with creating own classes to translate binary data to readable .NET codes (which have to be a task itself). This is fully doable, the major drawback is that every each device/manufacturer have thier own protocol, which means you can end up with a single wrapper per each unique device.

聊慰 2024-10-25 13:30:46

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

As a more general OPC solution, it may be worth looking at http://www.codeproject.com/KB/COM/opcdotnet.aspx - its a free OPC DLL complete with source code. While it is quite basic, the code is there, so you could easily update it if required, but from the sounds of your requirements it may be ideal.

后来的我们 2024-10-25 13:30:46

听起来您可能已经有一个用于西门子 S7 的 OPC 服务器。 Kepware、Simatic Net 和许多其他公司都支持 OPC UA。

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

  1. 适用于 Windows 桌面的 Microsoft Visual Studio Express 2013,可从以下位置获取: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 控件的属性进行动画处理。

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

Sounds like you may already have an OPC Server for Siemens S7. Kepware, Simatic Net, and many others support OPC UA.

You can build a simple HMI app in C# using these free tools:

  1. Microsoft Visual Studio Express 2013 for Windows Desktop available from: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-windows-desktop.

  2. The latest source from this site:
    http://web.archive.org/web/20140219181837/http://opcuaservicesforwpf.codeplex.com/

With this kit you can:
Browse OPC UA servers directly from the Visual Studio IDE. Drag and drop the variable nodes to create a data subscription. Use bindings to animate your UI control's properties from the subscription's data values.

Check out the sample application 'Workstation'.

泼猴你往哪里跑 2024-10-25 13:30:46

西门子网站上有包含文档和源代码的示例,对您很有用。看看它们:

There are samples with documentation and source code on Siemens' website which can be useful for you. Take a look at them:

友欢 2024-10-25 13:30:46

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

Another possibility would be using Siemens SAPI-S7 interface (which is the native Siemens protocol and which is used by OPC also).
SoftwareOption GmbH has a S7 .NET programming interface with C# sample.
You can download a C# demo program inclusive source code.
See http://www.softwareoption.de/siemens-produkte_e.htm.

命比纸薄 2024-10-25 13:30:46

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

I'm going through this process at the moment, I found his very useful: http://www.opcti.com/Download-OPC-Xi-source-code.aspx

白云悠悠 2024-10-25 13:30:46

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

使用C#开始编码。C#提供与OPC服务器通信的灵活性。

使用 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

Use any intermediate dll like opcdaauto.dll, clientAce,MXIO.NET.

Start coding using C#.C# provides flexible in communicating with OPC Server.

Example with Siemens using C# :
In App.config :

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

--Enjoy the Coding--
Refer : http://www.revanayya.blogspot.com

夜清冷一曲。 2024-10-25 13:30:46

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

Just to fill the list with an alternative solution:
If you just want to read/write some data/inputs/outputs/markers to/from the Siemens S7 you don't have to use OPC. I have been using libnodave without any issues for many years. Works fine as long as you enable put/get access in the hardware configuration of the plc and access "not optimized" datablocks.
Libnodave states that it works with S7-200,300,400. But we have used it with 1200 and 1500 as well.
Several sources on the net, see e.g. http://libnodave.sourceforge.net/

素衣风尘叹 2024-10-25 13:30:46
#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");
                }
}

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

#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");
                }
}

Register for some event handlers and get work done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文