首页 > 解决方案 > 通过 ModelCompiler 获取编译输出到 .NET OPC-UA Server

问题描述

我使用 [1] 中的 ModelCompiler 来编译我的信息模型。现在,我正在寻找一种将信息模型导入我的 .NET 服务器(基于 [2] 中的 .NET Core 服务器示例)的方法,包括将 .NET OPC-UA 堆栈作为 NuGet 包 [3]。

Boiler、MemoryBuffer 和 TestData 样本使用专用的节点管理器(继承自 SampleNodeManager)。我的第一个想法是为我的信息模型编写这样一个专用的节点管理器(它继承自 CustomNodeManager2),但这似乎很复杂。

似乎有比编写节点管理器更简单的方法(参见 node.js 服务器的 [4])。.NET 实现提供了一些方法来解析包含预定义节点 [5] 或 NodeSet2 文件 [6] 到 NodeStateCollection 的文件。解析的 NodeStateCollection 需要哪些步骤才能使 .NET 服务器知道节点?

[1] https://github.com/OPCFoundation/UA-ModelCompiler
[2] https://github.com/OPCFoundation/UA-.NETStandard
[3] https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua/
[4] https://stackoverflow.com/questions/40866428/how-can-i-generate-a-server-addressspace-from-a-xml-nodeset-file/
[5] https://stackoverflow.com/questions/49983225/populating-opcua-address-space-with-nodes-from-an-xml-schema/
[6] https://stackoverflow.com/questions/43944903/free-opc-ua-server-with-model-import-feature/

标签: c#.netopc-ua

解决方案


你是对的,你必须写一个自己的Server(继承自StandardServer)和一个自己的NodeManager(继承自CustomNodeManager2),但这并不是很多努力......

  • 将 Opc.Ua.ModelCompiler.exe 的所有输出文件作为类文件或嵌入资源添加到您的解决方案中
  • 实现服务器以通过反射加载您的类型
server.Factory.AddEncodeableTypes(this.GetType().Assembly);
  • 实现节点管理器
SetNamespaces(MyNamespace.Namespaces.DataTypes);
//...
NodeStateCollection predefinedNodes = new NodeStateCollection();
predefinedNodes.LoadFromBinaryResource(context,"MyNamespace.DataTypes.Types.PredefinedNodes.uanodes", this.GetType().Assemly, true);

有关完整示例,请查看:


推荐阅读