C#读取OPC UA电液控数据

  • 前言
  • 一、读取数据前的确认事项
  • 二、具体步骤
    • 1.与服务器连接
    • 2.读取所有节点
    • 获取指定节点下的引用
    • 读取数据
  • 总结

前言

OPC UA与OPC DA协议常见于工业生产中使用,例如煤矿的综采支架电液控系统。OPC UA 是OPC 的后继标准,只是后面增加了UA ,意指”统一架构”(Unified Architecture).它的主要目的是摆脱windows! 实现与平台无关的OPC.从OPC 演进到OPC UA,它的目的并没有改变,依然是为了实现分布式控制系统中的分布式对象技术.但是它的方式变成了与平台无关.面向了开放系统.这也就意味着我们可以在一个Arm /linux平台上实现OPC 的server,或者在云端linux平台上实现Client 程序.

一、读取数据前的确认事项

目前,大部分OPC UA协议都会使用Kepserver EX6作为服务器端,当我们作为客户端去读取服务器端的数据时,必须确保服务器与客户端配置的匹配。
1: 服务器端与客户端必须保持网络通畅,这是最基本的要求。
2:确认服务器的IP地址与开放的端口号。
3:确认服务器端的安全策略,是否需要密码等。

二、具体步骤

1.与服务器连接

代码如下(C#为例):

try{// Create the configuration.     ApplicationConfiguration configuration = Helpers.CreateClientConfiguration();// Create the endpoint configuration (use the application configuration to provide default values).EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(configuration);// The default timeout for a requests sent using the channel.endpointConfiguration.OperationTimeout = 300000;// Use the pure binary encoding on the wire.endpointConfiguration.UseBinaryEncoding = true;// Create the endpoint.ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);// Create the binding factory.BindingFactory bindingFactory = BindingFactory.Create(configuration);X509Certificate2 clientCertificate = configuration.SecurityConfiguration.ApplicationCertificate.Find();// Set up a callback to handle certificate validation errors.configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);// Initialize the channel which will be created with the server.SessionChannel channel = SessionChannel.Create(configuration,endpointDescription,endpointConfiguration,bindingFactory,clientCertificate,null);// Wrap the channel with the session object.// This call will fail if the server does not trust the client certificate.m_Session = new Session(channel, configuration, endpoint);m_Session.ReturnDiagnostics = DiagnosticsMasks.All;// Register keep alive callback.m_Session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);UserIdentity identity = new UserIdentity();// Create the session. This actually connects to the server.// Passing null for the user identity will create an anonymous session.m_Session.Open("OPC UA client", identity);return m_Session;}catch (Exception e){throw e;}

2.读取所有节点

代码如下(示例):

public ReferenceDescriptionCollection BrowseNodes(NodeId sourceId){m_Session = this.MySession;if (m_Session == null){return null;}// fetch references from the server.// find all of the components of the node.BrowseDescription nodeToBrowse1 = new BrowseDescription();nodeToBrowse1.NodeId = sourceId;nodeToBrowse1.BrowseDirection = BrowseDirection.Forward;//nodeToBrowse1.ReferenceTypeId = ReferenceTypeIds.Aggregates;nodeToBrowse1.ReferenceTypeId = ReferenceTypeIds.HasChild;nodeToBrowse1.IncludeSubtypes = false;//nodeToBrowse1.NodeClassMask = (uint)(NodeClass.Object | NodeClass.Variable);nodeToBrowse1.NodeClassMask = (uint)(NodeClass.Variable);nodeToBrowse1.ResultMask = (uint)BrowseResultMask.All;Browser bro = new Browser(m_Session);ReferenceDescriptionCollection references = bro.Browse(sourceId);return references;}

获取指定节点下的引用

private ReferenceDescriptionCollection getTargetItemList(ReferenceDescriptionCollection references, string targetStr){ReferenceDescriptionCollection retrunRef = new ReferenceDescriptionCollection();foreach (ReferenceDescription rf in references){if (!targetStr.Equals("item")){if (!rf.DisplayName.ToString().StartsWith(@"_") && targetStr.Equals(rf.DisplayName.ToString()) && rf.BrowseName.ToString() != "FolderType"){retrunRef = BrowseNodes((NodeId)rf.NodeId);break;}}else{if (!rf.DisplayName.ToString().StartsWith(@"_") && rf.DisplayName.ToString() != "FolderType"){retrunRef.Add(rf);}}}return retrunRef;}

读取数据

public ResponseHeader ReadValues(NodeIdCollection nodesToRead,out DataValueCollection results){ResponseHeader response = null;results = null;DiagnosticInfoCollection diagnosticInfos;// build list of attributes to read.ReadValueIdCollection valueIdsToRead = new ReadValueIdCollection();try{for (int i = 0; i < nodesToRead.Count; i++){ReadValueId attributeToRead = new ReadValueId();attributeToRead.NodeId = nodesToRead[i];attributeToRead.AttributeId = Attributes.Value;attributeToRead.Handle = attributeIdToString(Attributes.Value);valueIdsToRead.Add(attributeToRead);}response = m_Session.Read(null,0,TimestampsToReturn.Both,valueIdsToRead,out results,out diagnosticInfos);}catch (Exception e){throw e;}return response;}

总结

当我们作为客户端去读取服务器端的数据时,更多的还是要遵循服务器端的配置结构,比如,server、channel、group、item各个结构之间的组成关系。利用上面几个关键的方法,可以顺利的读取各中接口的OPC UA数据。

【OPC UA】使用C#读取OPC UA电液控数据相关推荐

  1. OPC UA客户端工具Softing OPC Client使用_推荐使用

    OPC UA客户端工具Softing OPC Client使用_推荐使用 Softing OPC Client工具介绍 Softing OPC Client工具是德国Softing公司出品的标准OPC ...

  2. java读取OPC DA数据---Utgard

    java读取OPC DA数据-Utgard Utgard库已经过时,原作者早已删除库,建议使用OPC UA,兼容OPC DA. 下面讲解Utgard使用 C#和C++都不用配置DCOM,直接调用函数 ...

  3. mess系统可以读取opc服务器,C3. Messages

    数据字段 !Time Data Data Data Data Data Data Data Data !Time Data Data Data Data Data Data Data Data !Ti ...

  4. opc读取ab的plc数据_使用OPC的模式去连接PLC进行AB SLC-5_04数据的采集

    使用OPC的方式去连接PLC进行AB SLC-5_04数据的采集 1.  必备软件 Rslinx classic 2.57 .net framework 2.0 VS2013 OS: win7 ent ...

  5. java opc连接测试,java连接opc读取数据实例及文档

    [实例简介] 在已有java web工程里添加读取opc的接口类.附有详细说明操作步骤. [实例截图] [核心代码] f9c60785-5c7a-42c8-a6ff-67244cf5c251 ├── ...

  6. opc服务器是硬件吗,opc是什么(一文彻底搞懂什么是OPC)

    原标题:(opc是什么(一文彻底搞懂什么是OPC)) opc是什么(一文完全搞懂什么是OPC)从2000年终以来,我们就一直在运用OPC软件互操纵性范例,而那些正准备踏入和想要踏入工业自动化范畴的人们 ...

  7. OPC是什么意思?OPC Server 和OPC Client又有什么区别呢?

    自从OPC标准出现之后,很多人都在使用,但是对于一些刚接触的人来说还是比较懵的.本篇文章主要介绍OPC Server 和OPC Client的区别.现在就跟着小编来了解一下文章内容吧~ 说到OPC S ...

  8. opc服务器上层传输协议,OPC服务器 (OPC Server) 之间数据传递的桥梁 — OPC Data Manager (ODM)...

    MatrikonOPC Data Manager MatrikonOPC Data Manager就像OPC服务器 (OPC Server) 之间传递数据的桥梁,将它们紧密地连结在一起. Matrik ...

  9. step与matlab的opc,wincc与matlab通过OPC通讯

    wincc作为OPC服务器而matlab作为OPC客户端 matlab有OPC tool,但是wincc需要配置DCOM. 先按步骤来找东西: ---------------------------- ...

最新文章

  1. Petshop3.0学习笔记(二)Global.asax文档分析
  2. exportfs命令和FTP服务
  3. PyTorch 读取图像图片数据
  4. 《阿里巴巴Java开发规约》插件使用详细指南
  5. Learning from Imbalanced Classes
  6. 面试基础算法、及编程 第一弹
  7. [JavaScript]项目优化总结
  8. 高手过招,精彩纷呈:PostgreSQL数据库人才与业务生态应用论坛圆满落幕
  9. UVA - 1588 Kickdown
  10. python爬取genek视频_【Python】爬虫(Xpath):批量爬取站长免费简历
  11. mysql安装包5.7.17.0_mysql-5.7.17-winx64压缩版的安装包下载和安装配置
  12. 中国移动重置服务密码方法
  13. delphi BMP与jpg互转
  14. 前端框架vue3的node安装及项目构建的4种方法
  15. 资料员培训建筑八大员培训建筑工程施工资料管理中存在的问题
  16. JavaScript实现二级联动下拉菜单
  17. 计算机考试excel统计图怎么做,excel表格取数据做统计图-Excel如何制作统计数据...
  18. 猿辅导编程python_猿辅导旗下品牌猿编程,宣布成立少儿编程研究院
  19. 盘点!网络安全厂商都有哪些?
  20. Android P系统设置之默认打开定位开关(默认使用位置服务)

热门文章

  1. 逆战班-- 初识react 01
  2. SAC#1 - 萌数
  3. 美食节--------发布菜谱
  4. ()逻辑与、()按位与运算、(||)逻辑或、(|)按位或运算
  5. 机器学习之K-means原理详解、公式推导、简单实例(python实现,sklearn调包)
  6. 显卡、GPU和CUDA关系
  7. JAVAJSPjavaweb企业员工考勤管理系统企业考勤管理(ssm企业人事管理系统)企业人事考勤系
  8. ZZULIOJ1011-1020
  9. 音频编码-speex库的使用方法
  10. 一台服务器的黑道生涯之二 喜结良缘