8:25, EEST
May 22, 2013
Hi,
i’ve read in the OPC Unfied Architecture book, that the specifications allows the creation of InstanceDeclaration. I like the feature to use the UA type to browse all derived instance declarations. Is there a possibility to this with your framework. If so, could you please give me a small example?.
I can’t find anythink in the Java Docs.
Best regards
Thomas
8:57, EEST
December 21, 2011
Good question. At the moment there is no method that would take a type and use the InstanceDeclarations of it to find the respective nodes in an instance.
You must browse the structure of the type yourself and use AddessSpace.translateBrowsePathsToNodeIds() to find the respective NodeIds in an instance.
Is this what you were looking for?
14:21, EEST
December 21, 2011
Not directly. You will need to compose the BrowsePath of RelativePathElements. I modified the example in SampleConsoleClient as follows:
println("Which node do you wish to translate?"); println("Use / to separate nodes in the browsePath, i.e. 'Types/ObjectsTypes/BaseObjectType/3:YourType'"); println("where each element is a 'parseable' BrowseName, i.e. it can define the namespaceIndex with a prefix, like '3:'"); String browsePathString = readInput(false); List browsePath = new ArrayList(); for (String s : browsePathString.split("/")) { final QualifiedName targetName = QualifiedName .parseQualifiedName(s); browsePath.add(new RelativePathElement( Identifiers.HierarchicalReferences, false, true, targetName)); } // The result may always contain several targets (if there are // nodes with the same browseName) // We will, however, only expect one and use the first result BrowsePathTarget pathTarget = client.getAddressSpace() .translateBrowsePathToNodeId(nodeId, browsePath.toArray(new RelativePathElement[0]))[0]; println("Target: " + pathTarget.getTargetId());
Note that your own types are in your own namespace – and you need to know the namespaceIndex of it.
16:41, EEST
May 22, 2013
Thanks for your fast response.
I came up with this, partly lousy, solution. Is there a better way to receive the typeofdefinitions of the browsed note? As seen in my example in the last lines?
RelativePathElement[] rps = new RelativePathElement[4];
//declaring the browsepath
rps[0] = new RelativePathElement(Identifiers.HierarchicalReferences,false,true,new QualifiedName(Identifiers.RootFolder.getNamespaceIndex(), “Types”));
rps[1] = new RelativePathElement(Identifiers.HierarchicalReferences,false,true,new QualifiedName(Identifiers.RootFolder.getNamespaceIndex(), “ObjectTypes”));
rps[2] = new RelativePathElement(Identifiers.HierarchicalReferences,false,true,new QualifiedName(Identifiers.RootFolder.getNamespaceIndex(), “BaseObjectType”));
rps[3] = new RelativePathElement(Identifiers.HierarchicalReferences,false,true,new QualifiedName(2, “MachineType”));
BrowsePath path = new BrowsePath(Identifiers.RootFolder,new RelativePath(rps));
BrowsePathResult[] results;
try {
//receving the results
results = client.getAddressSpace().translateBrowsePathsToNodeIds(path);
for(BrowsePathResult ta : results)
{
for(BrowsePathTarget t: ta.getTargets())
{
NodeId id = client.getAddressSpace().getNamespaceTable().toNodeId(t .getTargetId());
printCurrentNode(id);
// The TypeofDefinition is inverse so i chose these options
client.getAddressSpace().setBrowseDirection(BrowseDirection.Inverse);
client.getAddressSpace().setReferenceTypeId(NodeId.NULL);
// browsing from the selected Type
List references = client.getAddressSpace().browse(id);
// print the nodes which have the same type as the selected node, which is in fact the Machine TypeId
for (int i = 0; i < references.size(); i++)
{
if(references.get(i).getTypeDefinition().getValue().equals("MachineTypeId"))
printf("%d – %s\n", i, referenceToString(references.get(i)));
}
}
}
10:49, EEST
December 21, 2011
If I got it right this is the way to do it. You can use Identifiers.HasTypeDefintion, instead of NodeId.NULL for ReferenceTypeId.
Another option is to use AddressSpace.getNode() to receive the node you are interested in and look at it’s References. It is probably easier to read, but a bit slower to perform.
Most Users Ever Online: 1919
Currently Online:
28 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: 734
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1523
Posts: 6449
Newest Members:
christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16, edgardo3518Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1