基于OPC UA客户端上位机编写应用心得分享_第1页
基于OPC UA客户端上位机编写应用心得分享_第2页
基于OPC UA客户端上位机编写应用心得分享_第3页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、本文格式为Word版,下载可任意编辑基于OPC UA客户端上位机编写应用心得分享 基于opc UA客户端上位机编写 使用自动化接口进行OPCDA的客户端编写,但是OPCDA是基于COM/DCOM的技术,假如服务器与客户端不在同一台电脑上配置较为简单;基于COM/DCOM的技术有着不行根除的缺点,因此随着技术的进步,以及数据交换各方面需求的提高,OPC基金会在2008年发布了新的规范:OPC UA。OPC UA规范不再是基于COM/DCOM技术,因此OPC UA不仅能在Windows平台上实现,更可以在Linux,以及其他的嵌入式平台中实现。 与传统OPC规范相同,OPC UA同样有着相同的设计

2、目标: 1.功能等价:全部的基于COM的OPC规范中的功能,都映射到了OPC UA中。 2. 多平台支持:支持从嵌入式的微掌握器到基于云的分散式掌握架构。 3.平安:信息加密,互访认证以及平安监听功能。 4.扩展性:不影响现有应用程序的状况下,就可以添加新的功能。 5.丰富的信息建模:可定义简单的信息,而不再是单一的数据。 OPCUA服务器配置 本次OPCUA服务器依旧使用KEPServerEX 6,配置如下: 1、在托盘找到KEPServerEX 6图标,右键弹出菜单,点击OPCUA配置 2、在弹出的配置界面进行如下图的配置: 3、打开KEPServerEX 6主界面,右键点击项目,选择属性

3、,进行配置如下,即完成OPCUA服务器配置; 03 软件编写 1、软件实现节点扫瞄,添加订阅,移除订阅,清空订阅的功能,演示界面如下: 2、本次代码实现主要基于OPC UA的最新官方库二次封装的一个类库:OpcUaHelper.dll,开源地址: Framework版本最低为4.6。打开NuGet管理器,引用OpcUaHelper; 3、代码编写: 1 建立连接 private void button1_Click(object sender, EventArgs e) opcUaClient.UserIdentity = new UserIdentity(new AnonymousIdent

4、ityToken(); opcUaClient.ConnectServer(textBox1.Text); PopulateBranch(ObjectIds.ObjectsFolder, treeView1.Nodes); 2节点扫瞄 private async void PopulateBranch(NodeId sourceId, TreeNodeCollection nodes) odes.Clear(); nodes.Add(new TreeNode("Browsering."); / fetch references from the server. TreeNo

5、de listNode = await Task.Run() = ReferenceDescriptionCollection references = GetReferenceDescriptionCollection(sourceId); ListTreeNode list = new ListTreeNode(); if (references != null) / process results. for (int ii = 0; ii references.Count; ii+) ReferenceDescription target = referencesii; TreeNode

6、 child = new TreeNode(Utils.Format("0", target); child.Tag = target; child.Nodes.Add(new TreeNode(); list.Add(child); return list.ToArray(); ); /更新显示的属性 / DisplayAttributes(sourceId); nodes.Clear(); nodes.AddRange(listNode.ToArray(); private ReferenceDescriptionCollection GetReferenceDescr

7、iptionCollection(NodeId sourceId) /TaskCompletionSourceReferenceDescriptionCollection task = new TaskCompletionSourceReferenceDescriptionCollection(); / 找到全部组件的节点 BrowseDescription nodeToBrowse1 = new BrowseDescription(); nodeToBrowse1.NodeId = sourceId; nodeToBrowse1.BrowseDirection = BrowseDirecti

8、on.Forward; nodeToBrowse1.ReferenceTypeId = ReferenceTypeIds.Aggregates; nodeToBrowse1.IncludeSubtypes = true; nodeToBrowse1.NodeClassMask = (uint)(NodeClass.Object | NodeClass.Variable | NodeClass.Method | NodeClass.ReferenceType | NodeClass.ObjectType | NodeClass.View | NodeClass.VariableType | No

9、deClass.DataType); nodeToBrowse1.ResultMask = (uint)BrowseResultMask.All; / 找到全部节点组织的节点. BrowseDescription nodeToBrowse2 = new BrowseDescription(); nodeToBrowse2.NodeId = sourceId; nodeToBrowse2.BrowseDirection = BrowseDirection.Forward; nodeToBrowse2.ReferenceTypeId = ReferenceTypeIds.Organizes; no

10、deToBrowse2.IncludeSubtypes = true; nodeToBrowse2.NodeClassMask = (uint)(NodeClass.Object | NodeClass.Variable | NodeClass.Method | NodeClass.View | NodeClass.ReferenceType | NodeClass.ObjectType | NodeClass.VariableType | NodeClass.DataType); nodeToBrowse2.ResultMask = (uint)BrowseResultMask.All; B

11、rowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection(); nodesToBrowse.Add(nodeToBrowse1); nodesToBrowse.Add(nodeToBrowse2); / 从服务器猎取引用 ReferenceDescriptionCollection references = FormUtils.Browse(opcUaClient.Session, nodesToBrowse, false); return references; private void treeVi

12、ew1_BeforeExpand(object sender, TreeViewCancelEventArgs e) try / check if node has already been expanded once. if (e.Node.Nodes.Count != 1) return; if (e.Node.Nodes.Count 0) if (e.Node.Nodes0.Text != String.Empty) return; / get the source for the node.得到的源节点 ReferenceDescription reference = e.Node.Tag as ReferenceDescription; if (reference = null | reference.NodeId.IsAbsolute

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论