combination of freeopcua c++ client and python opcua throws error on getChild()

Viewed 912

I use freeopcua c++ (master branch from October 2019) and python-opcua/stable 0.98.6-2 on debian.

When trying to get a child the following way:

root.GetChild(std::vector<std::string>{"0:Objects", "2:MyObject", "2:MyVariable"});

I get an error with status code 0x806f0000 = BadNoMatch when accesing the server in the server-minimal.py example (see below).

If I do it like this:

root.GetChildren()[0].GetChildren()[0].GetChildren()[0]

hand-picking which child is the right one, I can get the child.

This works as well:

auto node = m_uaclient->GetNode(OpcUa::NodeId(2,2));

My server code is just the plain server-minimal.py from python opcua:

import sys
sys.path.insert(0, "..")
import time


from opcua import ua, Server


if __name__ == "__main__":

    # setup our server
    server = Server()
    server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")

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

    # get Objects node, this is where we should put our nodes
    objects = server.get_objects_node()

    # populating our address space
    myobj = objects.add_object(idx, "MyObject")
    myvar = myobj.add_variable(idx, "MyVariable", 6.7)
    myvar.set_writable()    # Set MyVariable to be writable by clients

    # starting!
    server.start()

    try:
        count = 0
        while True:
            time.sleep(1)
            count += 0.1
            myvar.set_value(count)
    finally:
        #close connection, remove subcsriptions, etc
        server.stop()

The client is as follows:

m_uaclient = boost::make_unique<OpcUa::UaClient>();
m_uaclient->Connect("opc.tcp://localhost:4840/freeopcua/server/");
OpcUa::Node root = m_uaclient->GetRootNode();
root.GetChild(std::vector<std::string>{"0:Objects", "2:MyObject", "2:MyVariable"});

Would anybody have an idea what the problem could be or how I could proceed narrowing the problem down?

1 Answers

Hope it help you to narrow down the problem.

The error means:

0x806F0000: ('BadNoMatch', 'The requested operation has no match to return.')

After referring this sample code, I see that you might be mixing or missing some steps. Here are some suggestions:

  1. 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())
    
  2. get a specific node knowing its node id

    var = client.get_node(ua.NodeId(1002, 2))
    var = client.get_node("ns=3;i=2002")
    print(var)
    var.get_data_value() # get value of node as a DataValue object
    var.get_value() # get value of node as a python builtin
    var.set_value(ua.Variant([23], ua.VariantType.Int64)) #set node value using 
    explicit data type
    var.set_value(3.9) # set node value using implicit data type
    
  3. 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"])
    print("myvar is: ", myvar)
    print("myobj is: ", obj)
    
  4. Stacked myvar access

    print("myvar is: ", root.get_children()[0].get_children()[1].get_variables()[0].get_value())
    
Related