Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[milo-dev] 回复: find a milo bug of subscription

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?

On Mon, Apr 10, 2017 at 8:13 PM, george.ray <george.ray@xxxxxxxxxx> wrote:
Hi all,

I Monitor items value with subscription API, In onSubscriptionValue callback, getting the same NodeId for different item.
All NodeId are the last one monitor's. This is the Log:

11:04:27.545 [main] INFO  o.e.m.e.client.ClientExampleRunner - Using endpoint: opc.tcp://192.168.0.4:49320 [None]
11:04:27.883 [main] INFO  o.e.m.e.client.SubscriptionExample - item created for nodeId=NodeId{ns=2, id=ChannelTest.DeviceTest.Tag191}
11:04:27.884 [main] INFO  o.e.m.e.client.SubscriptionExample - item created for nodeId=NodeId{ns=2, id=ChannelTest.DeviceTest.Tag190}
11:04:28.877 [ua-shared-pool-1] INFO  o.e.m.e.client.SubscriptionExample - subscription value received: item=NodeId{ns=2, id=ChannelTest.DeviceTest.Tag190}, value=Variant{value=-15128}
11:04:28.878 [ua-shared-pool-1] INFO  o.e.m.e.client.SubscriptionExample - subscription value received: item=NodeId{ns=2, id=ChannelTest.DeviceTest.Tag190}, value=Variant{value=2500}

_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/milo-dev




Back to the top