Understanding free OPC/UA code in python

Viewed 19432

I am working on OPCUA in python. I am using freeopc. I have used their server_minimal & client_minimal example and it is running fine. I am having some issues understanding the code. As far as I know the OPCUA stack, it has address space which is like a collection of all the nodes. These nodes then further contains objects and these objects have variable from where we can read write data. Please correct me if I am wrong.

---------------------------------
         Address space
---------------------------------
   |                    |
   |                    |
   V                    V
  Node1               Node2
   |
   Object1
    |
    Var1, Var2

So on the server side I want to know what is namespace

# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)

What is the namespace used for.? What to put inside uri.?

On client side, I want to know:

After connecting to server, we are doing:

    # Client has a few methods to get proxy to UA nodes that should always be in address space such as Root or Objects
    root = client.get_root_node()
    print("Objects node is: ", root)

What does get_root_node() means. Is it like we are connecting to address space of server where all the nodes are defined.?

    # Node objects have methods to read and write node attributes as well as browse or populate address space
    print("Children of root are: ", root.get_children())

root.get_children()-- Does this means getting the objects of the nodes.?

    # Now getting a variable node using its browse path
    myvar = root.get_child(["0:Objects", "2:MyObject", "2:MyVariable"])
    obj = root.get_child(["0:Objects", "2:MyObject"])

root.get_child what does it means.?

Client output:

 ('Objects node is: ', Node(TwoByteNodeId(i=84)))
 ('Children of root are: ', [Node(NumericNodeId(i=85)), Node(NumericNodeId(i=86)), Node(NumericNodeId(i=87))])

Above code is taken from server_minimal.py client_minimal.py

Can anyone please explain these. I tried reading their docs but this is not mentioned there.

Thanks.

2 Answers

To understand this better you can use, Unified Automation UA Expert as a client. https://www.unified-automation.com/downloads/opc-ua-clients.html Start the server_minimal.py, open UA Expert add server using 'Custom Discovery' with "opc.tcp://localhost:4840/freeopcua/server/". You can easily view the entire address space.

Related