Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Unable to read node value using OPC UA client code
June 20, 2022
8:59, EEST
Avatar
milindkaklij
Member
Members
Forum Posts: 7
Member Since:
May 9, 2022
sp_UserOfflineSmall Offline

Hi Team,
We are using ‘prosys-opc-ua-sdk-for-java-4.5.0-1291-client-server’ bundle for setting up OPC UA client server communication.
Mine OPC UA server is running at ‘opc.tcp://imx8mmevk-1:52520/OPCUA/SampleConsoleServer’ and we are trying to read node id values based on provided namespaceindex and identifire value but getting below exception.

“com.prosysopc.ua.StatusException: Bad_NodeIdUnknown (0x80340000) “The node id refers to a node that does not exist in the server address space.” StatusCode=Bad_NodeIdUnknown (0x80340000) “The node id refers to a node that does not exist in the server address space.” “

Client code for reading value after successful connection :

nodeId = new NodeId(3, “85/0:Simulation”);
UnsignedInteger attributeId = readAttributeId();
DataValue value = client.readAttribute(nodeId, attributeId);
logger.info(“Final Value is :: ” + dataValueToString(nodeId, attributeId, value));

I have 2 questions in same context :

1. How to add new node using command line interface based on provided options ?
2. Could any one please provide valid reference to do read and write operation with OPC UA server?

Hoping for quick help from experts.

Thanks.

June 20, 2022
9:59, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

The Client code shows that you’re attempting to read the value of some Attribute of Node with the specified NodeId (ns=3,85/0:Simulation). If the Server you’re testing with is the SampleConsoleServer sample application and not some other Server using that similar connection address, then there won’t be a Node with such NodeId in its AddressSpace and the read operation will fail with StatusCode Bad_NodeIdUnkown.

1) For SampleConsoleServer, you can add a Node by entering “a” to command line interface and then deciding a name that will be used as the new Node’s DisplayName and BrowseName. The created Node is added under MyObjects folder and it will be a Property Variable Node. Its NodeId will be of GUID type and the identifier is generated by the application automatically when the Node is created.

If you need the command line interface to support more options when adding Nodes, you will have to implement that yourself. You can use MyNodeManager’s addNode(String name) method as an example of how to add Nodes to the AddressSpace.

2) For sample code on reading and writing, see the read(NodeId nodeId) and write(NodeId nodeId) methods of the SampleConsoleClient sample application found in samples folder of the SDK distribution.

June 20, 2022
14:52, EEST
Avatar
milindkaklij
Member
Members
Forum Posts: 7
Member Since:
May 9, 2022
sp_UserOfflineSmall Offline

@Matti Siponen ,Thank you so much for your quick reply.

Based on your below input ,I got expected responses .

Input :
“The created Node is added under MyObjects folder and it will be a Property Variable Node. Its NodeId will be of GUID type and the identifier is generated by the application automatically when the Node is created.”

Response :
– Mine node name : counter2

*** Current Node: MyObjects: FolderType (ID: ns=2;s=MyObjectsFolder)

0 – MyDevice: MyDeviceType (ReferenceType=HasComponent, BrowseName=2:MyDevice)
1 – MyDevice: MyDeviceType (ReferenceType=HasNotifier, BrowseName=2:MyDevice)
2 – counter2: PropertyType (ReferenceType=HasComponent, BrowseName=2:counter2)
3 – NodeVersion: PropertyType (ReferenceType=HasProperty, BrowseName=NodeVersion)
——————————————————-
– Enter node number to browse into that
– Enter a to show/hide all references
– Enter u to browse up to the ‘parent’ node
– Enter r to browse back to the root node
– Enter t to translate a BrowsePath to NodeId
– Enter x to select the current node and return to previous menu
——————————————————-
2
*** Current Node: counter2: PropertyType (ID: ns=2;g=26de07cb-ab71-480f-b0ec-6c31eb1595bf)

Based on this i have coded my client code ‘nodeId = new NodeId(2, “26de07cb-ab71-480f-b0ec-6c31eb1595bf”);’ instead ‘nodeId = Identifiers.RootFolder;’

Still i am getting same exception ‘No such NodeId in its AddressSpace and the read operation will fail with StatusCode Bad_NodeIdUnkown’.

1. Could you please help me what attribute value shall i enter on client console to read value added nodeID ?

Select the node attribute.
1 – NodeId
2 – NodeClass
3 – BrowseName
4 – DisplayName
5 – Description
6 – WriteMask
7 – UserWriteMask
8 – IsAbstract
9 – Symmetric
10 – InverseName
11 – ContainsNoLoops
12 – EventNotifier
13 – Value
14 – DataType
15 – ValueRank
16 – ArrayDimensions
17 – AccessLevel
18 – UserAccessLevel
19 – MinimumSamplingInterval
20 – Historizing
21 – Executable

2. Will there be default value for added node or i have to write it?

Experts ,Kindly provide input on this so i can progress on same.

Thanks for your support team.

June 20, 2022
15:25, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

The GUID for the created Node is generated when the Node is created. If you restart the SampleConsoleServer application and create the Node again, it will have a different NodeId as a new GUID is generated. What exactly are you trying to do by adding new Nodes to SampleConsoleServer?

1) I’m not sure what you mean with “read value added nodeID” but you can read the NodeId Attribute of the added Node by entering 1 and the Value Attribute by entering 13.

2) Newly added Nodes will not have any initial Values. The DataType of the Node is BaseDataType so any Value can be written to the Node.

June 21, 2022
8:30, EEST
Avatar
milindkaklij
Member
Members
Forum Posts: 7
Member Since:
May 9, 2022
sp_UserOfflineSmall Offline

Matti Siponen,Thank for the reply.

I am just trying to write and read OPC UA server values for different nodes using java SDK client.

After selection of 13 on console client i am getting below exception after entering numeric value :

13
attribute: Value
Writing to node ns=2;g=152e0a76-e1e6-42e2-89fa-3fadc032a4bb – counter21
DataType: BaseDataType
Enter the value to write: 21
java.lang.IllegalArgumentException: No Javaclass corresponding to dataType BaseDataType

Whats syntax to enter value of BaseDataType so my java client can read it?
is there any exact reference OR specification of java console client to read and write those values?

Experts ,Kindly provide input on this so i can progress on same.

Thanks for your support .

June 21, 2022
9:11, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

The DataType of the created Node is BaseDataType. This is the abstract “root” DataType which means that the Node will accept a Value of any DataType. However, SampleConsoleClient is attempting to convert the String entered via the command line to a proper Java class, which is failing since there is no Java class that corresponds to BaseDataType.

To write a Value to such Node, you must call writeAttribute(NodeId nodeId, UnsignedInteger attributeId, Object value, boolean autoConvert) method of UaClient class in write(NodeId nodeId) method of SampleConsoleClient with autoConvert set to false instead of true. On the other hand, autoConvert must be true if you’re attempting to write Values to Variables with other DataTypes and the method needs to convert Strings entered via the command line to proper Java classes.

Though, in a real Client you would probably be using proper Java classes for the values instead of using only Strings. SampleConsoleClient and SampleConsoleServer are just simplified samples that don’t consider all real world scenarios that might require more specific handling.

But why are you testing your Client with a created Node when there already are plenty of Nodes with non-abstract DataTypes in the SampleConsoleServer’s AddressSpace?

June 22, 2022
10:51, EEST
Avatar
milindkaklij
Member
Members
Forum Posts: 7
Member Since:
May 9, 2022
sp_UserOfflineSmall Offline

Thanks @Matti Siponen for reply.

Yes there are plenty of Nodes with non-abstract DataTypes in the SampleConsoleServer’s AddressSpace but trying with few custom node just to fulfil our real useacase as well confirming level of control that at our level.

We are using ‘prosys-opc-ua-sdk-for-java-4.5.0-1291-client-server-pubsub-source’ bundle for understanding the prosys OPC UA client and server functionality.
As per your input we dont find autoConvert flag in console server source except its javadocs.Kindly help us on same.

Kindly guide us exact list of supported node data types whom which we can do read/write operations using java console client ?
How can we do monitoring few opc variables using java console client?any exising relavant source code reference?

Thanks.

June 22, 2022
13:07, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

AutoConvert is not a flag, it is a parameter of writeAttribute(NodeId nodeId, UnsignedInteger attributeId, Object value, boolean autoConvert) method of UaClient class. See write(NodeId nodeId) method of SampleConsoleClient class for an example of using this method with autoConvert parameter set to true:

boolean status = client.writeAttribute(nodeId, attributeId, value, true);

Variables with DataTypes that support conversion from String to the matching JavaClass can be written to using SampleConsoleClient. We do not have an exact list of such DataTypes so you will have to see for yourself which Variables support reading and writing. And as I said before, a proper Client application wouldn’t be working with only Strings since converting them to Structures or Arrays would be very inconvenient. The writing mechanism of SampleConsoleClient is simply intended to demonstrate how writing is done in OPC UA.

For monitoring Variables for data changes with Subscriptions and MonitoredItems, see subscribe(NodeId nodeId) method of SampleConsoleClient class. For more information, see the Client tutorial in tutorial folder of the SDK distribution.

June 23, 2022
8:52, EEST
Avatar
milindkaklij
Member
Members
Forum Posts: 7
Member Since:
May 9, 2022
sp_UserOfflineSmall Offline

Thanks for your input @Matti Siponen.

June 23, 2022
14:27, EEST
Avatar
milindkaklij
Member
Members
Forum Posts: 7
Member Since:
May 9, 2022
sp_UserOfflineSmall Offline

Hi Team,

Here I am trying to get nodeclass value is either object or variable .

————————————————————————————————
long attributeIndex=2 ; // for node class attribute value is 2
UnsignedInteger attributeId = readAttributeId(attributeIndex);
DataValue nodeValue= client.readAttribute(nodeId, attributeId);
// Here i am getting nodeValue is either 1 [Object] OR 2 [Variable].
————————————————————————————————

After that i am unable to compair it as its type is variant.

logger.info(nodeValue.equals(2) + ” –> “+ nodeValue.equals(“2″) + ” –>” + nodeValue.getValue().equals(“2”)) —-> All are getting false.

I just want to make decision to differentiate node class type so how can compair it and get its result as true?

Kindly help me to get cast and convert for accurate comparison?

Thanks

June 23, 2022
14:57, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

DataValue nodeValue = client.readAttribute(nodeId, attributeId) returns a DataValue, which can’t be compared to an int representing a NodeClass. You must first nodeValue.getValue() to get the value of the DataValue as a Variant. You must then call getValue() again for the Variant to get its value as an Object, which in this case will be an int that you can compare to 2 to check if the Node is a Variable. In short nodeValue.getValue().getValue().equals(2) will be true for Variable Nodes.

Due to the number of questions you have and how they’re related to basic use cases of the SDK API, I must ask you to contact uajava-support@prosysopc.com and provide the serial number of your Prosys OPC UA SDK for Java license.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
27 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

TimK: 41

Member Stats:

Guest Posters: 0

Members: 681

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1