[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [milo-dev] Alarm/Event Notifications triggers from OPC server
|
I created a device node with ns=2;s=MyDevice with
EventNotifier set to1 in a OPC server which supports alarms and events.I am trying to intercept events from client.The code I used is attached herewith.
I am getting below error on server when I ran the code.It seems a configuration error on the client.
ServiceFault: Bad_InternalError (0x80020000) "An internal error occurred as a result of a programming or configuration error."
Diagnostic Info: java.lang.IllegalArgumentException: addItem called with EventNotifier, use addEventItme instead
at com.prosysopc.ua.server.Subscription.addDataItem(Unknown Source)
at com.prosysopc.ua.server.SubscriptionManager.createMonitoredDataItem(Unknown Source)
at com.prosysopc.ua.server.SubscriptionManager.createMonitoredItem(Unknown Source)
at com.prosysopc.ua.server.SubscriptionServiceHandler.createMonitoredItems(Unknown Source)
at com.prosysopc.ua.server.SubscriptionServiceHandler.onCreateMonitoredItems(Unknown Source)
Can you please see what has gone wrong in the attached client code?
Thanks
Isuru
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();
NodeId n=NodeId.parse("ns=2;s=MyDevice");
// subscribe to the Value attribute of the server's CurrentTime node
ReadValueId readValueId = new ReadValueId(
n,
AttributeId.EventNotifier.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 request = new MonitoredItemCreateRequest(
readValueId, 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.setEventConsumer(this::onEventReceived);
List<UaMonitoredItem> items = subscription.createMonitoredItems(
TimestampsToReturn.Both,
newArrayList(request),
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 5 seconds then terminate
Thread.sleep(5000);
future.complete(client);
}