freeopcua c ++客户端和python opcua的组合在getChild()上抛出错误

问题描述 投票:1回答:1

我使用freeopcua c++(从2019年10月起成为主分支),并在debian上使用python-opcua/stable 0.98.6-2

[尝试通过以下方式生孩子时:

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

0x806f0000 = BadNoMatch示例中访问服务器时,出现状态代码为server-minimal.py的错误。

如果我这样做:

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

手工挑选哪个孩子是合适的孩子,我可以得到孩子。

这也可以:

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

我的服务器代码只是来自python opcua的普通server-minimal.py:

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()

客户端如下:

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"});

任何人都会知道问题可能是什么,或者我将如何缩小问题范围?

python c++ opc opc-ua
1个回答
0
投票

希望它可以帮助您缩小问题的范围。

© www.soinside.com 2019 - 2024. All rights reserved.