Subscription有两种模式,一种是Reporting,另一种是Sampling。

如果定义为Sampling,则这个Subscription是一个Triggered Item,即被激发的订阅,需要一个定义为Reporting的Subscription(称为Triggering Item)与它连接。这样当Triggering Item更新时,会激发Triggered Item更新。代码如下:

public class TriggeringExample implements UaClient {

// public static void main(String[] args) throws Exception {
// TriggeringExample example = new TriggeringExample();
//
// new ClientExampleRunner(example).run();
// } private final Logger logger = LoggerFactory.getLogger(getClass()); private final AtomicLong clientHandles = new AtomicLong(1L); @Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get(); // create a subscription @ 1000ms 一个订阅可以包含多个监控item
UaSubscription subscription = client.getSubscriptionManager()
.createSubscription(1000.0)
.get(); // subscribe to a static value that reports
ReadValueId readValueId1 = new ReadValueId(
new NodeId(2, "ch1.d1.tag1"),
AttributeId.Value.uid(),
null,
QualifiedName.NULL_VALUE
); //创建监控item, 第一个为Reporting mode UaMonitoredItem reportingItem = createMonitoredItem(subscription, readValueId1, MonitoringMode.Reporting); //创建第二个监控item, 它是Sampling mode,需要第一个项激发
ReadValueId readValueId2 = new ReadValueId(
new NodeId(2, "ch1.d1.tag2"),
AttributeId.Value.uid(),
null,
QualifiedName.NULL_VALUE
); UaMonitoredItem samplingItem = createMonitoredItem(subscription, readValueId2, MonitoringMode.Sampling); //将Triggering Item与Triggered item(可以有多个)连接起来(注意这里用了异步模式) subscription.addTriggeringLinks(reportingItem, newArrayList(samplingItem)).get(); // trigger reporting of both by writing to the static item and changing its value
//VariableNode node = client.getAddressSpace().createVariableNode(
// new NodeId(2, "ch1.d1.tag1")); //通过改变Triggering Item来激发Triggered item向我发送消息,注意这里writeValue使用了异步模式,如果没有这个get(),只能得到一两次消息更新
for(int i=0; i<10000; i++){
Variant newVal = new Variant(Unsigned.ushort(i));
DataValue va = new DataValue(newVal, null, null);
client.writeValue(new NodeId(2, "ch1.d1.tag1"), va).get(); }
//node.writeValue(va); // client.writeValue(
// new NodeId(2, "ch1.d1.tag1"),
// va
// ).get(); // let the example run for 5 seconds then terminate
Thread.sleep(500000);
future.complete(client);
} private UaMonitoredItem createMonitoredItem(
UaSubscription subscription,
ReadValueId readValueId,
MonitoringMode monitoringMode
) throws ExecutionException, InterruptedException { // important: client handle must be unique per item
UInteger clientHandle = uint(clientHandles.getAndIncrement()); MonitoringParameters parameters = new MonitoringParameters(
clientHandle,
1000.0,
null,
uint(10),
true
); MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(
readValueId,
monitoringMode,
parameters
); BiConsumer<UaMonitoredItem, Integer> onItemCreated =
(item, id) -> item.setValueConsumer(this::onSubscriptionValue); List<UaMonitoredItem> items = subscription.createMonitoredItems(
TimestampsToReturn.Both,
newArrayList(request),
onItemCreated
).get(); return items.get(0);
} private void onSubscriptionValue(UaMonitoredItem item, DataValue value) {
logger.info(
"回调:subscription value received: item={}, value={}",
item.getReadValueId().getNodeId(), value.getValue());
} }

Milo-OPC UA处理Subscription和Triggering的更多相关文章

  1. 关于OPC UA Helper 命名空间中的OpcUaClient 类中的订阅函数的更改

    原函数是opcUaClient.MonitorValue("ns=4;s=MAIN.d", new Action<double, Action>(MonitorTest ...

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

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

  3. 基于open62541的opc ua 服务器开发实现(1)

    关于opcua的介绍这里就不多说了,相信大家大都有了一些了解,open62541是一个开源C(C99)的opc-ua实现,开源代码可在官网或github上下载. 话不多说,首先搭建一个opcua服务器 ...

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

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

  5. OPC UA

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

  6. 从 OPC 到 OPC UA

    [前言]OPC是一个工业标准,所属国际组织是OPC基金会,现有会员已超过220家,包括世界上所有主要的自动化控制系统.仪器仪表及过程控制系统的公司. [经典 OPC]经典OPC规范基于微软Window ...

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

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

  8. C# OPC UA服务器 OPC UA网关 三菱 西门子 欧姆龙 Modbus转OPC UA 服务器 可配置的OPC UA服务器网关 HslSharp软件文档

    前言 本文将使用一个基于开源项目HslCommunication创建的OPC UA网关,方便通过配置创建一个OPC UA的网关中心.具体的操作及支持的设备信息项目参照下面: 开源项目HslCommun ...

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

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

随机推荐

  1. Python 字节码bytecode

    字节码bytecode python把源码文件编译成字节码文件,存放在__pycahe子目录内,用.pyc结尾.之后如果不再修改源码文件,运行时则使用*.pyc文件编译成机器码,这样不但运行速度快,而 ...

  2. vue-cli3 将自己写的组件封装成可引入的js文件

    一.调整项目结构 首先用 vue-cli 创建一个 default 项目 // 顺便安利一篇文章<Vue 爬坑之路(十二)—— vue-cli 3.x 搭建项目> 当前的项目目录是这样的: ...

  3. Web缓存Cache、Application、Session与ViewState

    在ASP.NET中,有很多种保存信息的对象.例如:APPlication,Session,Cookie,ViewState和Cache等,那么它们有什么区别呢?每一种对象应用的环境是什么? 方法 信息 ...

  4. for循环使用后contains方法失去效果

    重写了cartInfo中的equals和hashcode方法 第一种方式:包含是可以的List<CartInfo> cookie = new ArrayList<CartInfo&g ...

  5. [唐胡璐]Selenium技巧- Highlight页面元素

    大家都知道QTP的对象高亮显示功能特别强大, Selenium Webderiver也可以实现此功能。 高亮显示有时候对Debug还是相当有用的。 解决脚本: 调用脚本: 结果显示:

  6. 如何查看JVM的内存

    学过java的人都知道,jvm是解释运行java的,java能够作为跨平台语言,也是因为jvm的存在,合理的使用jvm内存可以帮助程序很好的运行.那么,怎么查看jvm的内存使用情况呢,下面本文介绍一下 ...

  7. C# 任务、线程、同步(五)

    1.数据流使用  TPL Data Flow 类库 class Program { static void Main(string[] args) { // ActionBlock(); // Sou ...

  8. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  9. 005_STM32程序移植之_RC522读卡模块

    1. 测试环境:STM32C8T6 2. 测试模块:RC522读卡模块 3. 测试接口: RC522读卡模块: VCC------------------3.3V GND--------------- ...

  10. pyecharts v1 版本 学习笔记 折线图,面积图

    折线图 折线图 基本demo import pyecharts.options as opts from pyecharts.charts import Line c = ( Line() .add_ ...