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
Creating a new node using prosys sdk - I got exception "The node id refers to a node that does not exist"
September 22, 2015
11:53, EEST
Avatar
lvboque
Member
Members
Forum Posts: 8
Member Since:
March 20, 2014
sp_UserOfflineSmall Offline

Hello,

I would like to create a new node on an existing opc/ua server …. When I am executing this code, I got an exception complaining that the node doesn’t exists …
What’s wrong?

NodeId nodeId = new NodeId(1, “MyNewNode”);
UaClientNodeFactory nodeFactory = new UaClientNodeFactory(client.getAddressSpace());
UaNode node = nodeFactory.createNode(NodeClass.Object, nodeId, “MyNewNode”, Locale.ENGLISH);
client.getAddressSpace().addNode(node);

client.writeValue(nodeId, 1 ); // this line generate the exception …
System.out.println(“return2= ” + client.readValue(node.getNodeId()));

I got this 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.”
at com.prosysopc.ua.client.UaClient.a(Unknown Source)
at com.prosysopc.ua.client.UaClient.writeAttribute(Unknown Source)
at com.prosysopc.ua.client.UaClient.writeValue(Unknown Source)

Thanks a lot for your support,

September 22, 2015
14:09, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

This is a good question – which means that the answer is not that nice…

It seems that we have two overloads of addNode(), which do different things. The method that you are using, is adding a new UaNode object to the AddressSpace object, but does not request anything to be added to the server. It should be used only internally – and be declared as protected, but since it overrides the respective method of the UaAddressSpace interface, it must be public…

The correct method that you should use is

public NodeId addNode(NodeId parentNodeId, NodeId referenceTypeId,
NodeId newNodeId, QualifiedName browseName, NodeClass nodeClass,
NodeAttributes nodeAttributes, NodeId typeDefinition)
throws ServiceException, EncodingException

This will make the respective service request to the server – it also defines the parentNode under which the node is added (using the defined reference type).

After that you should be able to find the node object with AddressSpace.getNode(). You don’t need to use the NodeFactory for creating the node object yourself.

It seems you are defining the NodeId in namespaceIndex=1; this is reserved for server specific data, such as diagnostic data, so my first thought is that it is not the correct namespace, but of course, it depends on the server.

September 23, 2015
14:47, EEST
Avatar
lvboque
Member
Members
Forum Posts: 8
Member Since:
March 20, 2014
sp_UserOfflineSmall Offline

Thanks Jouni,

But I still got problems to add a node …. We are using ignition as OPC server!
Any idea how to solve this issue?

package test.opc;
import org.opcfoundation.ua.builtintypes.NodeId;
import org.opcfoundation.ua.transport.security.SecurityMode;
import com.prosysopc.ua.client.UaClient;
import com.prosysopc.ua.nodes.UaNode;
public class SimpleNodeTest {

private static String serverUri = "opc.tcp://10.0.1.228:4096/ignition_opc_ua_server";
private static UaClient client;
protected final static String APP_NAME = "SimpleNodeTest";
protected SecurityMode securityMode = SecurityMode.NONE;

private void test() {
try {
client = new UaClient(serverUri);
client.setSecurityMode(securityMode);
client.connect();

NodeId parentIdNode = new NodeId(1,
"[AB1]Global.SUP_RO_STR_PA_LICENSE_ID");
NodeId newNodeId = new NodeId(1,
"[AB1]Global.SUP_RO_STR_PA_LICENSE_ID.MyNewNode");
UaNode parentNode = client.getAddressSpace().getNode(parentIdNode);

System.out.println("browserName= " + parentNode.getBrowseName());
System.out.println("nodeClass= " + parentNode.getNodeClass());
System.out.println("nodeAttributes= " + parentNode.getAttributes());
System.out.println("references= " + parentNode.getReferences());

client.getAddressSpace().addNode(
// this call generate the exception
parentIdNode,
client.getAddressSpace().getReferenceTypeId(), // is this correct?
newNodeId, parentNode.getBrowseName(),
parentNode.getNodeClass(), parentNode.getAttributes(),
parentNode.getNodeId() // is this correct?
);

// Try to write something on it
client.writeValue(newNodeId, 1);
// Read the written value
System.out.println("read= " + client.readValue(newNodeId));

// Stop after 10 seconds
Thread.sleep(10 * 1000);
System.out.println("Disconnection");
client.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
SimpleNodeTest me = new SimpleNodeTest();
me.test();
}
}

This is the output of this code:

browserName= 1:SUP_RO_STR_PA_LICENSE_ID
nodeClass= Object
nodeAttributes= ObjectAttributes: ObjectAttributes (id=1382744180)
EventNotifier={class org.opcfoundation.ua.builtintypes.UnsignedByte}0
UserWriteMask=null
DisplayName={class org.opcfoundation.ua.builtintypes.LocalizedText}(en_US) SUP_RO_STR_PA_LICENSE_ID
WriteMask=null
SpecifiedAttributes=null
Description={class org.opcfoundation.ua.builtintypes.LocalizedText}(en_US) null

references= [Lcom.prosysopc.ua.nodes.UaReference;@6eeae9f1
com.prosysopc.ua.ServiceException: ServiceFault: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Diagnostic Info: ServiceResult=Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
at com.prosysopc.ua.client.AddressSpace.addNode(Unknown Source)
at com.ora.neptis.opc.SimpleNodeTest.test(SimpleNodeTest.java:33)
at com.ora.neptis.opc.SimpleNodeTest.main(SimpleNodeTest.java:59)
Caused by: ServiceFault: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Diagnostic Info:
at org.opcfoundation.ua.transport.impl.AsyncResultImpl.waitForResult(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.serviceRequest(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.serviceRequest(Unknown Source)
at org.opcfoundation.ua.application.SessionChannel.serviceRequest(Unknown Source)
at org.opcfoundation.ua.transport.ChannelService.AddNodes(Unknown Source)
… 3 more

September 24, 2015
7:34, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

I think the reason is quite obvious: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”

I recommend you contact Inductive Automation for a new feature request šŸ˜‰

September 24, 2015
13:05, EEST
Avatar
lvboque
Member
Members
Forum Posts: 8
Member Since:
March 20, 2014
sp_UserOfflineSmall Offline

Good to know …

Do you know OPC UA Server that support this AddNodesService feature?

Thanks a lot,

September 24, 2015
13:34, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Unfortunately, not.

But, if you want to test it, you can enable support for it in the SampleConsoleServer of the Java SDK (or any other server that you can compile with it) by calling

server.getAddressSpace().setNodeManagementEnabled(true);

in the code.

September 25, 2015
5:28, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

I am using the following code to create a new node in Simulation server, I am trying to create one node with name “Counter 2” in under Simulation node.
there is no Exception throwing, but the node is not created , Please help me to create new node

NodeId parentIdNode = new NodeId(5, “85/0:Simulation”);
NodeId newNodeId = new NodeId(5, “Counter2”);

NodeId sampleNodeId = new NodeId(5, “Counter1”);
UaNode sampleNode = client.getAddressSpace().getNode(sampleNodeId);
sampleNode .setBrowseName(new QualifiedName(“5:Counter2”));
sampleNode .setDisplayName(new LocalizedText(“Counter2”));

NodeId retNodeId=client.getAddressSpace().addNode(parentIdNode, client.getAddressSpace().getReferenceTypeId(), newNodeId, sampleNode .getBrowseName(), sampleNode .getNodeClass(), sampleNode .getAttributes(), sampleNode .getNodeId());

September 25, 2015
7:20, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Short answer: SimulationServer does not support the addNodes service, yet.

But, there seems to be two problems, why you don’t get the exception that you are supposed to get:

#1 The server is not returning a service level error; instead it returns an operation level error for each requested addNodesItem (when called for several nodes, or just one, for this single item). That’s why you don’t get a ServiceException
#2 The client library is not checking for the operation result in addNode() and does not raise a respective StatusException.

However, the client is returning a NodeId.NULL, instead of a valid NodeId, which you can detect to notice that it failed(checked with NodeId.isNull(nodeId)).

We will fix the problems, but I cannot promise when SimulationServer would support the addNodes() service, yet.

September 25, 2015
9:26, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

Yes, It returns null, Thank you

September 26, 2015
6:11, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

I tried with Sample Console Server, I updated server with
server.getAddressSpace().setNodeManagementEnabled(true);
but I failed to create new node, addNode() returns null, I am trying to create new node under Objects/MyObjects/MyDevice

NodeId parentNodeId = new NodeId(2, “MyDevice”);
NodeId newNodeId = new NodeId(2,”Counter2″);
NodeId referenceTypeId =new NodeId(2, “MyDevice”);
QualifiedName browseName=new QualifiedName(“Counter2”);
NodeAttributes nodeAttributes=new NodeAttributes();
nodeAttributes.setDisplayName(new LocalizedText(“Counter2”));
NodeId typeDefinition = new NodeId(0,63);

NodeId Id = client.getAddressSpace().addNode(
parentNodeId,
referenceTypeId,
newNodeId,
browseName,
NodeClass.Variable,
nodeAttributes,
typeDefinition);

Is there any problem with this code ?

September 28, 2015
8:06, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

referenceTypeId is not referring to any ReferenceType. Try Identifiers.HasComponent, for example. For the BrowseName, you could also use a name in namespaceIndex=2, ‘new QualifiedName(2, ā€œCounter2ā€)’

September 28, 2015
8:55, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

Thanks for your reply

I updated my code to

NodeId parentNodeId = new NodeId(2, “MyObjectsFolder”);
NodeId newNodeId = new NodeId(2,”JijotestNode”);
NodeId referenceTypeId = Identifiers.HasComponent;
QualifiedName browseName=new QualifiedName(2,”Jijotest”);
NodeAttributes nodeAttributes=new NodeAttributes();
nodeAttributes.setDisplayName(new LocalizedText(“Jijotest”));
NodeId typeDefinition = new NodeId(0,68);

NodeId Id = client.getAddressSpace().addNode(
parentNodeId,
referenceTypeId,
newNodeId,
browseName,
NodeClass.Variable,
nodeAttributes,
typeDefinition);

But the output is

Sep 28, 2015 2:23:36 PM opcclient.OPCClient main
SEVERE: null
com.prosysopc.ua.ServiceException: ServiceFault: Bad_InternalError (0x80020000) “An internal error occurred as a result of a programming or configuration error.”
Diagnostic Info: ServiceFault: Bad_InternalError (0x80020000) “An internal error occurred as a result of a programming or configuration error.”
Diagnostic Info: java.lang.ClassCastException: org.opcfoundation.ua.core.NodeAttributes cannot be cast to org.opcfoundation.ua.core.VariableAttributes
at com.prosysopc.ua.server.nodes.UaVariableNode.setAttributes(Unknown Source)
at com.prosysopc.ua.server.NodeManagerUaNode.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagerTable.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagerTable.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagementServiceHandler.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagementServiceHandler.addNodes(Unknown Source)
at com.prosysopc.ua.server.NodeManagementServiceHandler.onAddNodes(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.opcfoundation.ua.application.ServiceHandlerComposition$1.serve(Unknown Source)
at org.opcfoundation.ua.application.ServiceHandlerComposition.serve(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.OpcTcpServerSecureChannel.handleSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.OpcTcpServerConnection.handleSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.OpcTcpServerConnection$4.onMessageComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.fireComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.setMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

September 28, 2015
11:57, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Use ‘new VariableAttributes()’ instead of ‘new NodeAttributes()’ – the attributes should match the NodeClass of the node that you are creating. This is a bit cumbersome, yes…

September 28, 2015
12:32, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

I updated, Now the client returns null and Server throws

com.prosysopc.ua.StatusException: Bad_UserAccessDenied (0x801F0000) “User does not have permission to perform the requested operation.” StatusCode=Bad_UserAccessDenied (0x801F0000) “User does not have permission to perform the requested operation.”
at com.prosysopc.ua.samples.server.MyNodeManagerListener.checkUserAccess(MyNodeManagerListener.java:156)
at com.prosysopc.ua.samples.server.MyNodeManagerListener.onAddNode(MyNodeManagerListener.java:49)
at com.prosysopc.ua.server.NodeManager.fireAddNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagerUaNode.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagerTable.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagerTable.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagementServiceHandler.addNode(Unknown Source)
at com.prosysopc.ua.server.NodeManagementServiceHandler.addNodes(Unknown Source)
at com.prosysopc.ua.server.NodeManagementServiceHandler.onAddNodes(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.opcfoundation.ua.application.ServiceHandlerComposition$1.serve(Unknown Source)
at org.opcfoundation.ua.application.ServiceHandlerComposition.serve(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.OpcTcpServerSecureChannel.handleSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.OpcTcpServerConnection.handleSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.OpcTcpServerConnection$4.onMessageComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.fireComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.setMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

September 28, 2015
12:59, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

OK, now the next step is to enable addNode() in your NodeManager; as you can see in the stack trace, you can do that in your MyNodeManagerListener in the project.

If you look at the current implementation, it is quite obvious.

@Override
public void onAddNode(ServiceContext serviceContext, NodeId parentNodeId, UaNode parent, NodeId nodeId, UaNode node,
NodeClass nodeClass, QualifiedName browseName, NodeAttributes attributes, UaReferenceType referenceType,
ExpandedNodeId typeDefinitionId, UaNode typeDefinition) throws StatusException {
// Notification of a node addition request.
// Note that NodeManagerTable#setNodeManagementEnabled(true) must be
// called to enable these methods.
// Anyway, we just check the user access.
checkUserAccess(serviceContext);
}

private void checkUserAccess(ServiceContext serviceContext) throws StatusException {
// Do not allow for anonymous users
if (serviceContext.getSession().getUserIdentity().getType().equals(UserTokenType.Anonymous))
throw new StatusException(StatusCodes.Bad_UserAccessDenied);
}

September 29, 2015
5:45, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

Thank you,

I added
server.getAddressSpace().setNodeManagementEnabled(true);
in the initialize() method of SampleConsoleServer class,

But still i have the same problem “Bad_UserAccessDenied (0x801F0000) “User does not have permission to perform the requested operation.”.
Should I use a username and password ?, Then How can i create a user in SampleconsoleServer ?

September 29, 2015
14:46, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The SampleConsoleServer supports a default username/password combination of (opcua/opcua & opcua2/opcua2, defined in MyUserValidator).

Alternatively, you can modify the above mentioned ‘checkUserAccess’ method, to enable access for everyone.

September 30, 2015
4:56, EEST
Avatar
jijomonac
Member
Members
Forum Posts: 18
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

Thank You, Successfully created..

September 30, 2015
9:08, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Great. Thanks for your patience: it seems this could be described better in the documentation…

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
17 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: 738

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1524

Posts: 6450

Newest Members:

jonathonmcintyre, fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Bostrƶm: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1