How to translate from a BrowsePath.RelativePath to the TargetId.Identifier of the BrowsePathTarget?|OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
How to translate from a BrowsePath.RelativePath to the TargetId.Identifier of the BrowsePathTarget?
Avatar
Mike Küster
Germany
Member
Members
Forum Posts: 6
Member Since:
07/04/2022
sp_UserOfflineSmall Offline
1
07/08/2022 - 08:44
sp_Permalink sp_Print

Hello,

this is my first post here, so first a short introduction:

We are developing measurement devices for our inhouse R&D. The devices contain mostly a PLC from B&R Automation and we used in the past their Automation PVI/NET for our development. But this is not compatible with the actual .NET, only with .NET Framework. Therefore we looked for an alternative and found the OPC UA and the .NET Standard package.

 

Now to my questions.

 

I started with a small demo (.NET 6) but run into some trouble ...

The PLC create the following address space (here for a variable "counter" from the task "Program"):

Root => Objects => PLC => Modules => "<Default>" => Program => counter

I tried to get the NodeIds with the Session.TranslateBrowsePathsToNodeIdsAsync method. If I use the free UaExpert program, I can see that my counter variable has this NodeId.Identifer: "::Program:counter". (The "::" is shown as the browse name from the "<Default>" Node?) If I try that as BrowsePath.RealtivePath, I got a ServiceResultException: Cannot parse relative path: '::Program:counter' with an inner exception: FormatException: Input string was not in a correct format.

I have to use "/6:Program/6:counter". The 6 is the namespace index of the "Modules" object. With that string the TranslateBrowsePathsToNodeIds gives me a "good" result with a BrowseParseTarget with the same TargetId.Identifier "::Program:counter" which I see in the UaExpert program.

Now I want to get a bigger list of variables, not only one variable at a time, but how can I find my variable? The relative path is my input and the Identifier is the output of the method? I can - of course - do some string manipulation, but this has a "bad smell" 😉

What would be the best practice here?

 

Thanks,

Mike

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
07/08/2022 - 14:23
sp_Permalink sp_Print sp_EditHistory

NodeIds are unique identifiers for Nodes.

BrowseNames are non-unique programmatic names for Nodes.

The TranslateBrowsePathsToNodeIdsAsync service allows to navigate multiple hops at once by specifying a BrowseName and a ReferenceType for each hop. The response is a NodeId for each Node found. 

NodeIds are used in subsequent calls like Read.

The fact that a NodeId might "look like" a BrowseName is an artifact of some Server implementations. You should never assume there is a relationship between the BrowseName and the NodeId. They are independent attributes of Nodes.

Can you explain what problem you need to solve?

Avatar
Mike Küster
Germany
Member
Members
Forum Posts: 6
Member Since:
07/04/2022
sp_UserOfflineSmall Offline
3
07/11/2022 - 01:19
sp_Permalink sp_Print

Hi Randy,

sorry, I was completely on the wrong track. Maybe I made a mistake during my first tests, but this works now:

NodeId counterNodeId = new NodeId("::Program:counter", 6);

DataValue counterValue = session.ReadValue(counterNodeId);

 

I thought, I can't access a node directly and have to browse for them. <shame/>

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 24
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1349
Posts: 4577