14:29, EEST
September 18, 2017
Hi everyone,
I use Java SDK 3.1.6. I created a test server which dynamically adds and removes nodes.
I use custom structs but I don’t think it belongs to the custom types.
But for completeness I’ll describe them here:
- DataType Point2D which has to elements X:ushort and Y:ushort.
- VariableType Point2DType which is a subtype of BaseDataVariableType and a value of type Point2D. Nodes of this type will be added and removed.
- ObjectType PointFolderType which is a subtype of FolderType and has two methods:
- addPoint with one input argument of type Point2D. This will add variable nodes of type Point2DType as children of this folder with reference type Organizes.
- removeAll with no arguments. This method deletes the nodes from this folder.
This folder also has the property NodeVersion
- EventType PointCreationEventType with one extra field PointData of type Point2D.
I used UA Modeler for modelling and the code generator to get the code for my server.
This is the code of the method listener:
private static final NodeId NODE_ID_POINTS_FOLDER = new NodeId(3, 5018);
@Override
public boolean onCall(ServiceContext serviceContext, NodeId objectId, UaNode object, NodeId methodId,
UaMethod method, Variant[] inputArguments, StatusCode[] inputArgumentResults,
DiagnosticInfo[] inputArgumentDiagnosticInfos, Variant[] outputs) throws StatusException {
String sNodeId = methodId.toString();
switch (sNodeId) {
case "ns=3;i=7022":
try {
addPoint(inputArguments, inputArgumentResults, outputs);
} catch (ServiceException e) {
throw new StatusException(e.getMessage(), e.getServiceResult());
}
return true;
case "ns=3;i=7027":
removeAllPoints(inputArguments, inputArgumentResults, outputs);
return true;
}
return false;
}
The addPoint method:
Point2D point = inputArguments[0].asClass(Point2D.class, null);
if (point.getX() == null || point.getY() == null) {
inputArgumentResults[0] = new StatusCode(StatusCodes.Bad_InvalidArgument);
throw new StatusException(inputArgumentResults[0]);
} else {
PointFolderTypeNode pointFolder = (PointFolderTypeNode)this.nodeManager.getNode(NODE_ID_POINTS_FOLDER);
this.rootManager.beginModelChange();
try {
Point2DTypeNode pointNode = this.nodeManager.createInstance(Point2DTypeNode.class, point.getX().toString() + "," + point.getY().toString());
pointNode.setValue(point);
pointFolder.addReference(pointNode, Identifiers.Organizes, false);
} finally {
this.rootManager.endModelChange();
}
PointCreationEventType event = this.nodeManager.createEvent(PointCreationEventType.class);
event.setPointData(point);
event.setSourceNode(pointFolder.getNodeId());
event.setMessage(new LocalizedText("Point {" + point.getX() + "," + point.getY() + "} created."));
((PointCreationEventTypeNode)event).triggerEvent(null);
}
}
The string representation of X and Y is used for node id and browse/display name. When I call this method a new variable node is created and all attributes are correct. Also the event is raised.
The removeAll method:
PointFolderTypeNode pointFolder = (PointFolderTypeNode)this.nodeManager.getNode(NODE_ID_POINTS_FOLDER);
UaReference[] references = this.nodeManager.getReferences(pointFolder.getNodeId());
this.rootManager.beginModelChange();
try {
List<UaNode> nodes = Stream.of(references)
// Filter1: only references of type "Organizes"
.filter(ref -> ref.getReferenceTypeId().equals(Identifiers.Organizes))
// Filter2: only forward references starting at "Points" folder
.filter(ref -> ref.getSourceNode().equals(pointFolder))
.map(ref -> ref.getTargetNode())
.collect(Collectors.toList());
for (UaNode node : nodes) {
this.nodeManager.deleteNode(node, true, false);
}
} finally {
this.rootManager.endModelChange();
}
}
After calling this method all nodes disappear from the address space.
Here comes the problem: when I call addPoint again with the same arguments (x,y) as before I’l get a Bad_InternalError.
After restarting my server I can recreate the nodes (but only once).
It seems that deleting the nodes is not enough.
Update:
On the server side I’ll get the exception:
Caused by: com.prosysopc.ua.server.NodeBuilderException: Could not add node NodeId=ns=3;s=0,0/3:X, NodeClass=Variable, BrowseName=3:X; Type={NodeId=i=63, NodeClass=VariableType, BrowseName=BaseDataVariableType, IsAbstract=false, DataType=i=24, ValueRank=-2, ArrayDimensions=null, Value=(null)} DataType=NodeId=i=24, NodeClass=DataType, BrowseName=BaseDataType, IsAbstract=true, ValueRank=-1, MinimumSamplingInterval=-1,000000, AccessLevel=[CurrentRead, CurrentWrite], UserAccessLevel=[CurrentRead, CurrentWrite], Historizing=false, Value=DataValue(value=(null), statusCode=Bad_WaitingForInitialData (0x80320000) "Waiting for the server to obtain values from the underlying data source.", sourceTimestamp=null, sourcePicoseconds=0, serverTimestamp=null, serverPicoseconds=0) to NodeManager
Caused by: com.prosysopc.ua.StatusException: A different node with the same nodeId (ns=3;s=0,0/3:X) already exists in the nodeManager. Existing node: NodeId=ns=3;s=0,0/3:X, NodeClass=Variable, BrowseName=3:X; Type={NodeId=i=63, NodeClass=VariableType, BrowseName=BaseDataVariableType, IsAbstract=false, DataType=i=24, ValueRank=-2, ArrayDimensions=null, Value=(null)} DataType=NodeId=i=5, NodeClass=DataType, BrowseName=UInt16, IsAbstract=false, ValueRank=-1, MinimumSamplingInterval=0,000000, AccessLevel=[CurrentRead], UserAccessLevel=[CurrentRead, CurrentWrite], Historizing=false, Value=DataValue(value=0, statusCode= (0x00004000) "", sourceTimestamp=05/03/19 11:52:40.0370000 GMT, sourcePicoseconds=0, serverTimestamp=05/03/19 11:52:40.0370000 GMT, serverPicoseconds=0) StatusCode=Bad_UnexpectedError (0x80010000) "An unexpected error occurred." Diagnostics=Diagnostic Info:
If I call nodeManager.getNode(nodeId) immediatly after call of deleteNode() I’ll get an error “BadNodeIdUnknown”. So the node was deleted by NodeManagerUaNode.
Thomas
15:04, EEST
September 18, 2017
Sorry, I made a mistake.
Please do not investigate on this.
I was not aware of the fact that there were sub-nodes for each variable node. The structure variable node created sub-nodes for each element of the structure. The delete command accidently deletes only the parent. When I re-recreate the node, the children already exist.
To find out I needed to carefullly read the stack trace.
Most Users Ever Online: 1919
Currently Online:
16 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: 729
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1