Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use browsepath to get the value of node id. #1673

Open
codedebugger1 opened this issue Jul 2, 2024 · 8 comments
Open

How to use browsepath to get the value of node id. #1673

codedebugger1 opened this issue Jul 2, 2024 · 8 comments

Comments

@codedebugger1
Copy link

I am have a question on top of this answer:

you can only use nodeids for direct read!
the only thing you can do use the translate browsepath to nodeid service to get the nodeid and then read.

Originally posted by @AndreasHeine in #1228 (comment)

Basically our need is how we can read and write the values via browse name.
How to use the browse path in that case.

@AndreasHeine
Copy link
Member

AndreasHeine commented Jul 2, 2024

async def translate_browsepaths(self, starting_node: ua.NodeId, relative_paths: Iterable[Union[ua.RelativePath, str]]) -> List[ua.BrowsePathResult]:

https://reference.opcfoundation.org/Core/Part4/v105/docs/A.2

rel path: "/0:Root/0:Objects/0:Server" (you need to use Browsenames!!! <NamespaceIndex>:<Name>)
remember the path is relative to the starting node!

@codedebugger1
Copy link
Author

Thanks for your response.

I have tried with below code and couldn't succeded.
I have tried with relative path only.

 async def main():
 client = Client(url=address, timeout=4)

try:
    await client.connect()
    print("Success")
except Exception as e:
    print(e)
    return

paths = await client.translate_browsepaths(starting_node="ns=1;i=100", relative_paths="/0:Root/0:Objects/1:MyServer/1:StatusWord")
print("paths", paths)

try:
    await client.disconnect()
except Exception as e:
    print(e)
    return


 if __name__ == "__main__":
      asyncio.run(main())

We wanted something like this (below is the example of the reading value from node id, we wanted similar with reading value from browsepath ):

    client.connect()
    print("Connect Success")
    node_obj= client.get_node("ns=1;i=100")
    node_value = node_obj.get_value()
    print("node_value", node_value)

@AndreasHeine
Copy link
Member

AndreasHeine commented Jul 2, 2024

Thanks for your response.

I have tried with below code and couldn't succeded. I have tried with relative path only.

 async def main():
 client = Client(url=address, timeout=4)

try:
    await client.connect()
    print("Success")
except Exception as e:
    print(e)
    return

paths = await client.translate_browsepaths(starting_node="ns=1;i=100", relative_paths="/0:Root/0:Objects/1:MyServer/1:StatusWord")
print("paths", paths)

try:
    await client.disconnect()
except Exception as e:
    print(e)
    return


 if __name__ == "__main__":
      asyncio.run(main())

We wanted something like this (below is the example of the reading value from node id, we wanted similar with reading value from browsepath ):

    client.connect()
    print("Connect Success")
    node_obj= client.get_node("ns=1;i=100")
    node_value = node_obj.get_value()
    print("node_value", node_value)

sorry in opc ua its two seperate services means always two seperate requests...

not sure if root and object belongs to a "relative" path!? i used it just to show the syntax...

@AndreasHeine
Copy link
Member

AndreasHeine commented Jul 2, 2024

its usually from the startnode the path to the node you want to get

guess this is your rel path: /1:StatusWord if "ns=1;i=100" is startnode

@codedebugger1
Copy link
Author

Yes my start node is "ns=1;i=100"

And I have tried with the relative_path as "/1:StatusWord" as below:

        asyncua_obj = asyncuaClient(address)
        asyncua_obj.connect()
        paths = asyncua_obj.translate_browsepaths(starting_node=node_address, relative_paths="/1:StatusWord")
        print("paths", paths)

Below is the response I got in the paths:

image

@AndreasHeine
Copy link
Member

are you familiar with asyncio?

        asyncua_obj = asyncuaClient(address)
        await asyncua_obj.connect()
        paths = await asyncua_obj.translate_browsepaths(starting_node=node_address, relative_paths="/1:StatusWord")
        print("paths", paths)

you need to await the connect and the translate method call...

@AndreasHeine
Copy link
Member

async def translate_browsepaths(self, starting_node: ua.NodeId, relative_paths: Iterable[Union[ua.RelativePath, str]]) -> List[ua.BrowsePathResult]:

as in the type hint its a ua.NodeId and not a string!

node_address = ua.NodeId.from_string("ns=1;i=100")

async def connect():
       asyncua_obj = asyncuaClient(address)
       await asyncua_obj.connect()
       paths = await asyncua_obj.translate_browsepaths(starting_node=node_address, relative_paths="/1:StatusWord")
       print("paths", paths)
       await asyncua_obj.disconnect()

asyncio.run(connect())

@AndreasHeine
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants