Hi,
I modified SubscriptionExample.java, This is the code:
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get();
// create a subscription @ 1000ms
UaSubscription subscription = client.getSubscriptionManager().createSubscription(1000.0).get();
List<NodeId> nodeIds190 = ImmutableList.of(new NodeId(2, "ChannelTest.DeviceTest.Tag190"));
List<NodeId> nodeIds191 = ImmutableList.of(new NodeId(2, "ChannelTest.DeviceTest.Tag191"));
// subscribe to the Value attribute of the server's CurrentTime node
ReadValueId readValueId190 = new ReadValueId(
//Identifiers.Server_ServerStatus_CurrentTime,
nodeIds190.get(0),
AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE);
ReadValueId readValueId191 = new ReadValueId(
//Identifiers.Server_ServerStatus_CurrentTime,
nodeIds191.get(0),
AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE);
// important: client handle must be unique per item
UInteger clientHandle = uint(clientHandles.getAndIncrement());
MonitoringParameters parameters = new MonitoringParameters(
clientHandle,
1000.0, // sampling interval
null, // filter, null means use default
uint(10), // queue size
true // discard oldest
);
MonitoredItemCreateRequest request190 = new MonitoredItemCreateRequest(
readValueId190, MonitoringMode.Reporting, parameters);
MonitoredItemCreateRequest request191 = new MonitoredItemCreateRequest(
readValueId191, MonitoringMode.Reporting, parameters);
// when creating items in MonitoringMode.Reporting this callback is where each item needs to have its
// value/event consumer hooked up. The alternative is to create the item in sampling mode, hook up the
// consumer after the creation call completes, and then change the mode for all items to reporting.
BiConsumer<UaMonitoredItem, Integer> _onItemCreated_ =
(item, id) -> item.setValueConsumer(this::onSubscriptionValue);
List<MonitoredItemCreateRequest> requests = new ArrayList<MonitoredItemCreateRequest>();
requests.add(request191);
requests.add(request190);
List<UaMonitoredItem> items = subscription.createMonitoredItems(
TimestampsToReturn.Both,
//newArrayList(request),
requests,
onItemCreated
).get();
for (UaMonitoredItem item : items) {
if (item.getStatusCode().isGood()) {
logger.info("item created for nodeId={}", item.getReadValueId().getNodeId());
} else {
logger.warn(
"failed to create item for nodeId={} (status={})",
item.getReadValueId().getNodeId(), item.getStatusCode());
}
}
// let the example run for 10 seconds then terminate
Thread.sleep(100000);
future.complete(client);
}
private void onSubscriptionValue(UaMonitoredItem item, DataValue value) {
logger.info(
"subscription value received: item={}, value={}",
item.getReadValueId().getNodeId(), value.getValue());
}
------------------------------------------------------------------
发件人:Kevin Herron <kevinherron@xxxxxxxxx>
发送时间:2017年4月11日(星期二) 11:18
收件人:george.ray <george.ray@xxxxxxxxxx>; milo developer discussions <milo-dev@xxxxxxxxxxx>
主 题:Re: [milo-dev] find a milo bug of subscription
Can you provide the code you used to create the subscriptions?