OPC UA

一 、OPC UA简介

OPC UA(OPC Unified Architecture)是下一代OPC统一体系架构,是一种基于服务的、跨越平台的解决方案。

OPC UA具有如下特点:

1)    扩展了OPC的应用平台。兼容Windows、Linux和Unix平台,不受平台限制,不需要进行DCOM安全设置(DA需要)。这使得基于OPC UA的标准产品可以更好地实现工厂级的数据采集和管理;

2)    OPC UA定义了统一数据和服务模型,使数据组织更为灵活,可以实现报警与事件、数据存取、历史数据存取、控制命令、复杂数据的交互通信;

3)    OPC UA比OPC DA更安全。OPC UA传递的数据是可以加密的,并对通信连接和数据本身都可以实现安全控制。新的安全模型保证了数据从原始设备到系统,从本地到远程的各级自动化和信息化系统的可靠传递;

4)    OPC UA的Internet 通讯,可以不用设置防火墙。

想要了解更多,https://www.cnblogs.com/thammer/p/12882468.html

前期准备

准备好开发的IDE,首选Visual Studio2019版本,新建项目,或是在你原有的项目上进行扩展。注意:项目的.NET Framework版本最低为4.6.2

打开NuGet管理器,输入指令

Install-Package UA-.NETStandard

或者

、OPC UA配置管理器

1.OPC UA

其他家OPC配置界面

下面已基金会发布的SDK为基础,开发适合自己的OPC UA。也有基于open62541开发的。

OPCFoundation/UA-.NETStandard

此OPC UA参考实现以.NET Standard规范为目标。

.NET Standard允许开发可在当今可用的所有常见平台上运行的应用程序,包括Linux,iOS,Android(通过Xamarin)和Windows 7/8 / 8.1 / 10(包括嵌入式/ IoT版本),而无需特定于平台的修改。

此项目中的参考实施之一已通过OPC Foundation认证测试实验室的认证,以证明其高质量。自从使用合规性测试工具(CTT)V1.04对认证过程进行了测试并验证了合规性以来的修复和增强功能。

此外,还支持云应用程序和服务(例如ASP.NET,DNX,Azure网站,Azure Webjobs,Azure Nano Server和Azure Service Fabric)。

1)Authentication设置

下图是配置设置界面

  1. 证书验证,OPC Foundation指定路径或者存储在“受信用的根证书颁发机构”

  2.用户名验证

  3.Server可支持匿名Anonymous

 、OPC UA  数据模型

数据里最重要的能够存储信息,还要好查找易维护。看到唯一性,好多方法都是围绕唯一性展开,UA-.NETStandard里NodeId地址标识符,下面的注释,封装在***State类里面

    /// <summary>
/// Stores an identifier for a node in a server's address space.
/// </summary>
/// <remarks>
/// <para>
/// <b>Please refer to OPC Specifications</b>:
/// <list type="bullet">
/// <item><b>Address Space Model</b> setion <b>7.2</b></item>
/// <item><b>Address Space Model</b> setion <b>5.2.2</b></item>
/// </list>
/// </para>
/// <para>
/// Stores the id of a Node, which resides within the server's address space.
/// <br/></para>
/// <para>
/// The NodeId can be either:
/// <list type="bullet">
/// <item><see cref="uint"/></item>
/// <item><see cref="Guid"/></item>
/// <item><see cref="string"/></item>
/// <item><see cref="byte"/>[]</item>
/// </list>
/// <br/></para>
/// <note>
/// <b>Important:</b> Keep in mind that the actual ID's of nodes should be unique such that no two
/// nodes within an address-space share the same ID's.
/// </note>
/// <para>
/// The NodeId can be assigned to a particular namespace index. This index is merely just a number and does
/// not represent some index within a collection that this node has any knowledge of. The assumption is
/// that the host of this object will manage that directly.
/// <br/></para>
/// </remarks>
[DataContract(Namespace = Namespaces.OpcUaXsd)]
public class NodeId : IComparable, IFormattable
A.    初始化自己的节点

OPC UA 里比较重要的是FolderStateNodeState和BaseDataVariableState,里面具体属性,可以自己去了解,这里不说了

    /// <summary>
/// A typed base class for all data variable nodes.
/// </summary>
public class BaseDataVariableState : BaseVariableState
    /// <summary>
/// The base class for all folder nodes.
/// </summary>
public class FolderState : BaseObjectState
    /// <summary>
/// The base class for custom nodes.
/// </summary>
public abstract class NodeState : IDisposable, IFormattable

a)      比较重要的是CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)创建自己地址空间,下图也是提供了很样例,一个根目录字符串路径就可以了,其他数据源数据类型可以不提供。一般地,(Key, Value)值对。

类似二叉树数据结构

b)  二叉树结构体,左为支(Folder)(可再次向下遍历),右为叶(Variable),存储变量信息,如变量完整Full路径,“***.变量组0.变量”,下图是用第三方测试结果

c)      完整代码

 1         public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
2 {
3 lock (Lock)
4 {
5 IList<IReference> references = null;
6
7 if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
8 {
9 externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>();
10 }
11 // 第三方数据源,来自API
12 if ((OpcuaDataPrivade == null || OpcuaDataPrivade.VariableNode == null) || String.IsNullOrEmpty(OpcuaDataPrivade.VariableNode.name))
13 {
14 return;
15 }
16
17 FolderState root = CreateFolder(null, OpcuaDataPrivade.VariableNode.name, OpcuaDataPrivade.VariableNode.name);
18 root.AddReference(ReferenceTypes.Organizes, true, ObjectIds.ObjectsFolder);
19 references.Add(new NodeStateReference(ReferenceTypes.Organizes, false, root.NodeId));
20 root.EventNotifier = EventNotifiers.SubscribeToEvents;
21 AddRootNotifier(root);
22
23 List<BaseDataVariableState> variables = new List<BaseDataVariableState>();
24
25 try
26 {
27 #region Device_Simulation
28
29 BrowseGroup(root, OpcuaDataPrivade.VariableNode);
30
31 m_dynamicNodes_temp = MemCopyList(m_dynamicNodes);
32 #endregion
33
34 }
35 catch (Exception e)
36 {
37 Utils.Trace(e, "Error creating the address space.");
38 }
39
40 AddPredefinedNode(SystemContext, root);
41
42 m_simulationTimer = new Timer(DoSimulation, cts, 1000, 1000);
43
44 System.Threading.Tasks.Task.Factory.StartNew(() =>
45 {
46 WriteProcHandle(cts);
47 });
48 }
49 }

OPC UA 统一架构)(二),讲讲如何读取和修改值。

OPC UA 统一架构) (一)的更多相关文章

  1. OPC UA (统一架构)的优势

    OPC UA OPC统一架构(OPC Unified Architecture)是OPC基金会(OPC Foundation)创建的新技术,更加安全.可靠.中性(与供应商无关),为制造现场到生产计划或 ...

  2. OPC UA 统一架构) (二)

    OPC UA (二) 重头戏,捞取数据,才是该干的事.想获取数据,先有数据源DataPrivade,DataPrivade的数据集合不能和BaseDataVariableState的集合存储同一地址, ...

  3. OPC UA

    OPC UA将来自不同厂商不同设备的数据进行统一格式.统一显示. OPC: originally knowns as “OLE for Process Control”, now “Open Plat ...

  4. OPC协议解析-OPC UA OPC统一架构

    1    什么是OPC UA 为了应对标准化和跨平台的趋势,为了更好的推广OPC,OPC基金会近些年在之前OPC成功应用的基础上推出了一个新的OPC标准-OPC UA.OPC UA接口协议包含了之前的 ...

  5. 转:OPC协议解析-OPC UA OPC统一架构

    1    什么是OPC UA 为了应对标准化和跨平台的趋势,为了更好的推广OPC,OPC基金会近些年在之前OPC成功应用的基础上推出了一个新的OPC标准-OPC UA.OPC UA接口协议包含了之前的 ...

  6. SharpNodeSettings项目,可配置的数据采集,统一的工业数据网关,OPC UA服务器开发,PLC数据发布到自身内存,redis,opc ua,以及数据可视化开发

    本项目隶属于 HslCommunication 项目的SDK套件,如果不清楚HslCommunication组件的话,可以先了解那个项目,源代码地址:https://github.com/dathli ...

  7. C# 读写opc ua服务器,浏览所有节点,读写节点,读历史数据,调用方法,订阅,批量订阅操作

    OPC UA简介 OPC是应用于工业通信的,在windows环境的下一种通讯技术,原有的通信技术难以满足日益复杂的环境,在可扩展性,安全性,跨平台性方面的不足日益明显,所以OPC基金会在几年前提出了面 ...

  8. OPC UA的监控项、订阅、和通知

    MonitoredItem 每个监控项均指明了要监控的项目(item)和用来发送通知的订阅. item可以是一个节点的属性(node attribute). MonitorItem可以监控一个属性,一 ...

  9. C# 实现opc ua服务器的远程连接(转)

    原文转自:https://www.cnblogs.com/dathlin/p/7724834.html OPC UA简介 OPC是应用于工业通信的,在windows环境的下一种通讯技术,原有的通信技术 ...

随机推荐

  1. springboot项目配置数据库

    在pom.xml文件中配置 <!-- mybatis整合springboot起步依赖--> <dependency> <groupId>org.mybatis.sp ...

  2. [LeetCode]231. Power of Two判断是不是2\3\4的幂

    /* 用位操作,乘2相当于左移1位,所以2的幂只有最高位是1 所以问题就是判断你是不是只有最高位是1,怎判断呢 这些数-1后形成的数,除了最高位,后边都是1,如果n&n-1就可以判断了 如果是 ...

  3. CentOS 6或7 启动故障修复及root密码破解

    CentOS 6或7 启动故障修复及root密码破解 目录 CentOS 6或7 启动故障修复及root密码破解 CentOS 6启动流程修复: 实验一:删除initramfs-2.6.32-754. ...

  4. Android stdio使用时遇到的一些问题

    (1)android stdio加载布局时 Exception raised during rendering: com/android/util/PropertiesMap             ...

  5. sh -s用法

    1.基本用法 (1)sh -s 会从标准输入中读取命令,并在子shell中执行 (2)sh -s 后从第一个非 - 开头的参数开始,依次被赋值给子shell的 $1,$2... (3)sh -s 的第 ...

  6. String、StringBuffer 和 StringBuilder 的区别

    面试简答 区别: 1) String 长度大小不可变 2) StringBuffer 和 StringBuilder 长度可变 3) StringBuffer 线程安全 StringBuilder 线 ...

  7. 在md里画流程图

    可以使用名为mermaid的代码块,即 ```mermaid``` 需要md解析器能解析mermaid mermaid使用详情参见

  8. epoll的陷阱实践

    在使用epoll的时候,我们上篇文章epoll的陷阱大体介绍了epoll中会有哪些问题.这篇文章我们就针对必须要了解,也是绕不过去的陷阱进行实验,看看现象是什么,并且如何编写才能达到我们想要的效果. ...

  9. 【Flutter】可滚动组件之CustomScrollView

    前言 CustomScrollView是可以使用Sliver来自定义滚动模型(效果)的组件.它可以包含多种滚动模型,举个例子,假设有一个页面,顶部需要一个GridView,底部需要一个ListView ...

  10. docker 删除和拉取镜像

    删除镜像 # docker rmi -f 镜像id # 删除指定镜像 docker rmi -f 25d5f6s564 # docker rmi -f 镜像id 镜像id # 删除多个镜像 docke ...