15:54, EEST
September 18, 2017
Hi,
I’m using SDK 3.1.2 and I followed the steps of the client tutorial (chapter 12) to create my first subscription for data changes:
subscription.setPublishingEnabled(true);
subscription.setPublishingInterval(100D);
MonitoredDataItem monItem = new MonitoredDataItem(myExpandedNodeId, UnsignedInteger.getfromBits(13), MonitoringMode.Reporting);
subscription.addItem( monItem, 1 );
uaClient.addSubscription( subscription ); // NullPointerException
And the stack trace of the exception is as follows:
at com.prosysopc.ua.client.MonitoredItem.getNodeId(Unknown source)
at com.prosysopc.ua.client.Subscription.a(Unknown source)
at com.prosysopc.ua.client.Subscription.createMonitoredItems(Unknown source)
at com.prosysopc.ua.client.Subscription.createItems(Unknown source)
at com.prosysopc.ua.client.UaClient.a(Unknown source)
at com.prosysopc.ua.client.UaClient.addSubscription(Unknown source)
Without the SDK’s source code I cannot see what I did wrong here. Some missing initialization?
The node I subscribe is a variable node with a custom defined enumeration as data type.
Kind regards
Thomas Reuther
17:04, EEST
April 3, 2012
Hi,
Is the client connected? How is your myExpandedNodeId constructed? If with a Namespace uri, does the server have a matching entry in the NamespaceArray?
Also if you are subscribing to the Value Attribute, you can use just the MonitoredDataItem constructor that just takes (Expanded)NodeIds. The Attributes class (of package org.opcfoundation.ua.core contains constants for the Attributes).
It might be safer to convert the ExpandedNodeId to NodeId before passing it to the constructor (via UaClient.getNamespaceTable().toNodeId(), note that the client must be connected to the server, as the mapping is read from it).
17:05, EEST
September 18, 2017
I created the expanded nodes ids like this:
When I create MonitoredDataItems using a NodeId instead of a ExpandedNodeId then it works fine!
And yes, my client is connected and the namespace exists.
My new converter is implemented as follows:
return uaClient.getNamespaceTable().toNodeId(expNodeId);
}
With this converter the creation of monitored items is successful. Using expanded node ids instead it fails.
Thank you for your information!!! 🙂
8:55, EEST
September 18, 2017
In SDK ver. 3.1.6 this problem still exists. This time (trying event subscriptions) I found out that the NullPointerException only occurs when I also specify a client handle.
client.addSubscription(subscription); // NullPointerException
But when I omit the client handle, then there is no NullPointerException. But with ExpandedNodeId there is no notification for an event.
10:47, EEST
April 3, 2012
Hi,
That is somewhat an error from the SDK side that the method taking the clientHandle is public, it should be protected instead (I should have noticed this from your orginal post…). SDK uses that internally. That is actually the source of the NPE (well at least one way it can happen) if you call it.
In practice you do not need/cannot to define the handle, SDK takes care of that for you. It generates one (internally in the monitored items constructors) and uses it to link the notifications to the item and informs you the changes via the listeners, setDataChangeListener(MonitoredDataItemListener listener) for MonitoredDataItems and setEventListener(MonitoredEventItemListener listener) for MonitoredEventItem.
Generally speaking the ExpandedNodeIds are a common problem, basically the SDK does internally in the item is:
to change it to a NodeId (as that is what the UA service calls take). Calling the addItem(MonitoredItem item) will set the Subscription to the item, the one taking handle does not -> NPE (SDK will internally call the additem taking the handle as part of the addItem process).
Most Users Ever Online: 1919
Currently Online:
15 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 730
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech KubalaModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1