11:53, EEST
March 20, 2014
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,
14:09, EEST
December 21, 2011
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
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.
14:47, EEST
March 20, 2014
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?
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
7:34, EEST
December 21, 2011
13:05, EEST
March 20, 2014
13:34, EEST
December 21, 2011
5:28, EEST
September 24, 2015
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());
7:20, EEST
December 21, 2011
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.
9:26, EEST
September 24, 2015
6:11, EEST
September 24, 2015
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 ?
8:06, EEST
December 21, 2011
8:55, EEST
September 24, 2015
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)
11:57, EEST
December 21, 2011
12:32, EEST
September 24, 2015
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)
12:59, EEST
December 21, 2011
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.
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);
}
5:45, EEST
September 24, 2015
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 ?
14:46, EEST
December 21, 2011
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, dalenegettingerModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Bostrƶm: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1