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
Instance Declaration
May 22, 2013
8:25, EEST
Avatar
hallohein
Member
Members
Forum Posts: 6
Member Since:
May 22, 2013
sp_UserOfflineSmall Offline

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

May 22, 2013
8:57, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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?

May 22, 2013
13:47, EEST
Avatar
hallohein
Member
Members
Forum Posts: 6
Member Since:
May 22, 2013
sp_UserOfflineSmall Offline

Is it then possible to use the String Objects/ObjectsTypes/BaseObjectType/MachineType as Browse path. If yes, how can this be accomplished?
Or do I have to browse manually to the node and use the instance for the method AddessSpace.translateBrowsePathsToNodeIds(instance)?

thankfully Thomas

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

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.

May 22, 2013
16:41, EEST
Avatar
hallohein
Member
Members
Forum Posts: 6
Member Since:
May 22, 2013
sp_UserOfflineSmall Offline

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)));
}
}
}

May 23, 2013
10:49, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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.

May 23, 2013
14:28, EEST
Avatar
hallohein
Member
Members
Forum Posts: 6
Member Since:
May 22, 2013
sp_UserOfflineSmall Offline

Ok, thanks alot for your help. But I think services like that and automatic code generation for complex types (as webservices or databas translations like hibernate) could improve the speed for the spreading of OPC UA.

best regards
Thomas

May 23, 2013
15:21, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes I agree. We will need to consider these.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
41 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_gallery

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1