15:04, EET
December 20, 2021
Good morning,
Please I need help regarding the method:
I changed the class:
com.prosysopc.ua.samples.server.MyNodeManager
of the project:
sampleconsoleserver
In order to publish multiple variables with the same BrowseName MyLevel:
Root/Objects/2:MyObjects/2:MyDevice/2:MyLevel – ns=2;s=MyLevel1
Root/Objects/2:MyObjects/2:MyDevice/2:MyLevel – ns=2;s=MyLevel2
Root/Objects/2:MyObjects/2:MyDevice/2:MyLevel – ns=2;s=MyLevel3
Root/Objects/2:MyObjects/2:MyDevice/2:MyLevel – ns=2;s=MyLevel4
Root/Objects/2:MyObjects/2:MyDevice/2:MyLevel – ns=2;s=MyLevel5
Then in a client project I called the method:
but I noticed that BrowsePathTarget[] only contains one element
Could you please check it too?
Example client code:
List<RelativePathElement> browsePath = new ArrayList<RelativePathElement>();
String browsePathString = "Objects/2:MyObjects/2:MyDevice/2:MyLevel";
NodeId nodeId = Identifiers.RootFolder;
for (String s : browsePathString.split("/")) {
final QualifiedName targetName = QualifiedName.parseQualifiedName(s);
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, targetName));
}
BrowsePathTarget[] pathTargets;
try {
pathTargets =
client.getAddressSpace().translateBrowsePathToNodeId(nodeId, browsePath.toArray(new RelativePathElement[0]));
for (BrowsePathTarget pathTarget : pathTargets) {
String targetStr = "Target: " + pathTarget.getTargetId();
if (!pathTarget.getRemainingPathIndex().equals(UnsignedInteger.MAX_VALUE)) {
targetStr = targetStr + " – RemainingPathIndex: " + pathTarget.getRemainingPathIndex();
}
System.err.println(targetStr);
}
} catch (StatusException e1) {
printException(e1);
}
}
Best regards,
Francesco
8:54, EET
Moderators
February 11, 2020
Hello,
I can confirm that only one BrowsePathTarget is returned in this scenario. It seems that the Server side handling for translateBrowsePathToNodeIds doesn’t handle cases where there can be multiple targets properly and only returns one target instead of all of them.
This limitation will be fixed in a future release of the SDK. Would fixing this be urgent to you or are you just testing translateBrowsePathToNodeIds to see how it works?
14:49, EET
December 20, 2021
Dear Matti,
Thank you for checking.
For me it’s not urgent. I think I solved it this way: I wrote a recursive function that browses all the nodes.
UaNode rootNode = client.getAddressSpace().getNode(Identifiers.RootFolder);
String[] browseNames = "Objects/2:MyObjects/2:MyDevice/2:MyLevel".split("/");
UaNode varNode = translateBrowsePathToNode(rootNode, browseNames, 0);
System.err.println("varNode found: " + varNode.getBrowseName());
…
protected UaNode translateBrowsePathToNode(UaNode parentNode, String browseNames[], int browseIndex)
throws ServiceException, AddressSpaceException {
if (parentNode == null || browseNames == null || browseNames.length == 0 || browseIndex > browseNames.length) {
throw new IllegalArgumentException();
}
QualifiedName browseName = QualifiedName.parseQualifiedName(browseNames[browseIndex]);
UaReference[] references = parentNode.getForwardReferences(Identifiers.HierarchicalReferences);
UaNode target = null;
for (int i = 0; i < references.length; i++) {
UaNode tempTarget = references[i].getTargetNode();
if (tempTarget.getBrowseName().equals(browseName)) {
if (target == null || (target != null && target.equals(tempTarget))) {
target = tempTarget;
} else {
throw new IllegalStateException(
"Duplicate target node, parentNode: " + parentNode + ", target: " + browseName);
}
}
} // for
if (target == null) {
throw new IllegalStateException(
"Target node not found, parentNode: " + parentNode + ", target: " + browseName);
}
// debug
System.err.println("DEBUG browseIndex " + browseIndex + " target: " + target.getBrowseName());
browseIndex++;
if (browseIndex < (browseNames.length)) {
return translateBrowsePathToNode(target, browseNames, browseIndex);
} else {
return target;
}
}
I was also thinking about adding a cache to avoid browsing the same browsePath again.
Most Users Ever Online: 1919
Currently Online:
50 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: 726
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_galleryModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1