Skip to content
Advertisement

Understanding free OPC/UA code in python

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.

JavaScript

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

JavaScript

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:

JavaScript

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

JavaScript

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

JavaScript

root.get_child what does it means.?

Client output:

JavaScript

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.

Advertisement

Answer

I’m working with freeopcua too and on some questions I think I have an answer

JavaScript

will get you the node of the root of your server so basically ‘adress space’ in your diagram.

JavaScript

will return a list of all nodes that are direct children of the root so in the example of your tree. [node1, node2]. However add the root node this is 0:Objects, 0:Types, 0:Views

To see the tree of the server you can best use the opcua-client this is a GUI that will allow you to see the tree.

to do this start your server and then in your terminal typ;

JavaScript

(when on linux)

You can add limitation to get children e.g.:

JavaScript

This will only return other objects not methods or properties of your node.

The output you get is because Node doesn’t have a real ‘ToString()’ the i is the id of the node (can also be seen with the GUI client).

the

JavaScript

will return a node object if you’re certain you added a value you can get it,s value by calling .get_value() on the return of this. NodeId is the specification of what child you want. So say you want var1 this would be

JavaScript

Important here is that to get a child you need to know where you are (you can get children from any Node object not only root) and then go down with a combination of “idx:Name” which is what you add when you added the value to the server in the first place.

Hoped this helped a bit (did not test the code so it might need some adjustments to actually run)

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement