use of com.jbm.framework.opcua.event.ValueChanageEvent in project JBM by numen06.
the class OpcUaTemplate method createItemMonitored.
private List<UaMonitoredItem> createItemMonitored(OpcUaClientBean opcUaClientBean, OpcPoint opcPoint) throws ExecutionException, InterruptedException {
int namespace = opcPoint.getNamespace();
String tag = opcPoint.getTagName();
NodeId nodeId = new NodeId(namespace, tag);
// 创建发布间隔1000ms的订阅对象
UaSubscription subscription = this.getSubscription(opcUaClientBean.getOpcUaClient());
MonitoringParameters parameters = new MonitoringParameters(uint(subscription.getMonitoredItems().size() + 1), 1000.0, null, uint(10), true);
List<MonitoredItemCreateRequest> requests = Lists.newArrayList();
ReadValueId readValueId = new ReadValueId(nodeId, AttributeId.Value.uid(), null, null);
// 创建监控item, 第一个为Reporting mode
MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters);
requests.add(request);
List<UaMonitoredItem> items = subscription.createMonitoredItems(TimestampsToReturn.Both, requests, (item, id) -> item.setValueConsumer(new UaMonitoredItem.ValueConsumer() {
@Override
public void onValueArrived(UaMonitoredItem item, DataValue value) {
try {
log.debug("OPC数据变化回调:subscription value received: item={}, value={}", item.getReadValueId().getNodeId(), value.getValue());
ValueChanageEvent valueChanageEvent = opcUaClientBean.getSubscriptionPoints().get(opcPoint.getAlias());
valueChanageEvent.putData(item, value);
applicationContext.publishEvent(valueChanageEvent);
} catch (Exception e) {
}
}
})).get();
log.info("添加监听:[{}]到监听器[{}]监听数量:{}", nodeId, subscription.getSubscriptionId(), subscription.getMonitoredItems().size());
return items;
}
use of com.jbm.framework.opcua.event.ValueChanageEvent in project JBM by numen06.
the class OpcUaTemplate method subscribeItem.
public <T extends ValueChanageEvent> void subscribeItem(String deviceId, String pointName, Class<T> callBackEvent) {
OpcUaClientBean opcUaClientBean = clientMap.get(deviceId);
OpcPoint opcPoint = opcUaClientBean.findPoint(pointName);
ValueChanageEvent valueChanageEvent = ReflectUtil.newInstance(null, null, null);
this.subscribeItem(deviceId, opcPoint, valueChanageEvent);
}
use of com.jbm.framework.opcua.event.ValueChanageEvent in project JBM by numen06.
the class GuardSubscriptionListener method onSubscriptionTransferFailed.
// 重连时 尝试恢复之前的订阅失败时 会调用此方法
public void onSubscriptionTransferFailed(UaSubscription subscription, StatusCode statusCode) {
log.info("设备[{}]订阅失效,开始重新订阅,数量为:{}", opcUaClientBean.getDeviceId(), opcUaClientBean.getSubscriptionPoints().size());
for (String pointCode : opcUaClientBean.getSubscriptionPoints().keySet()) {
OpcPoint opcPoint = opcUaClientBean.getPoints().get(pointCode);
ValueChanageEvent valueChanageEvent = opcUaClientBean.getSubscriptionPoints().get(pointCode);
opcUaTemplate.subscribeItem(opcUaClientBean.getDeviceId(), opcPoint, valueChanageEvent);
}
log.info("设备[{}]重新订阅完成", opcUaClientBean.getDeviceId());
}
Aggregations