简体   繁体   English

使用 C# 从 OPC-UA 服务器获取数据,无需 GUI

[英]Get Data From OPC-UA Server using C#, without GUI

We have a background service, which has the single purpose of getting recent data from a server.我们有一个后台服务,其唯一目的是从服务器获取最新数据。

Now the server should be an OPC-UA server.现在服务器应该是 OPC-UA 服务器。 Unfortunaly, the SDKs and examples I found to connect to this are limited/only explained in ways that are heavily integrated with a classic windows forms application.不幸的是,我发现与此相关的 SDK 和示例受到限制/仅以与经典 windows forms 应用程序高度集成的方式进行解释。 Up to the point where its impossible to separate GUI from business logic.直到无法将 GUI 与业务逻辑分开的地步。

At this point I'm wondering if we are misusing the client functionality and should opt for a different way?在这一点上,我想知道我们是否在滥用客户端功能并且应该选择不同的方式?

Ideally I'd like to wrap the whole OPC-UA Logic inside a class library and just call GetData(), is that impossible?理想情况下,我想将整个 OPC-UA 逻辑包装在 class 库中,然后调用 GetData(),这不可能吗?

You are probably referring to the "SDK" provided by the OPC Foundation - but you have not stated that explicitly in your question;您可能指的是 OPC 基金会提供的“SDK”——但您没有在问题中明确说明; in fact, you used the term "SDKs", in plural.实际上,您使用了复数形式的术语“SDK”。 There certainly are also commercial SDKs which might be better in this respect.当然也有商业 SDK 在这方面可能会更好。

Here is one (QuickOPC), together with one-liner example of reading the OPC UA data: https://www.opclabs.com/products/quickopc/opc-specifications/unified-architecture/generic-data .这是一个(QuickOPC),以及读取 OPC UA 数据的单行示例: https://www.opclabs.com/products/quickopc/opc-specifications/unified-architecture/generic-data Disclaimer: This is a self-promotion.免责声明:这是一种自我推销。

You might find Tutorials for Client development , specifically Console Client useful.您可能会发现客户端开发教程,特别是控制台客户端很有用。 This is a much better SDK than the one from the OPC Foundation.这是一个比 OPC 基金会更好的 SDK。 You will find full C# samples including a console client application (no GUI).您将找到完整的 C# 示例,包括控制台客户端应用程序(无 GUI)。

You might want to re-evalute your needs for您可能需要重新评估您的需求

Ideally I'd like to wrap the whole OPC-UA Logic inside a class library and just call GetData(), is that impossible?理想情况下,我想将整个 OPC-UA 逻辑包装在 class 库中,然后调用 GetData(),这不可能吗?

It is totally possible, but with OPC-UA, you have to keep in mind that it is recommended to get data using a subscription model (Monitored Items) instead of performing an explicit Read for a value (unless you just want to read an attribute once).这是完全可能的,但使用 OPC-UA,您必须记住,建议使用订阅 model(监控项)获取数据,而不是执行显式读取值(除非您只想读取属性一次)。 So, I would make sure that however you are building your client-side class makes sense for the needs of your application.因此,我会确保无论您构建客户端 class 对您的应用程序的需求是有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM