Freeopcua C++ 客户端和 Python Opcua 的组合会在 getChild() 上抛出错误
combination of freeopcua c++ client and python opcua throws error on getChild()
我在 debian 上使用freeopcua c++
(从 2019 年 10 月开始的主分支(和python-opcua/stable 0.98.6-2
。
当试图通过以下方式获得孩子时:
root.GetChild(std::vector<std::string>{"0:Objects", "2:MyObject", "2:MyVariable"});
在server-minimal.py
示例中访问服务器时,我收到状态代码0x806f0000 = BadNoMatch
错误(见下文(。
如果我这样做:
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"});
有人知道问题可能是什么,或者我如何继续缩小问题范围吗?
希望它能帮助您缩小问题范围。
该错误意味着:
0x806F0000:("BadNoMatch"、">请求的操作没有要返回的匹配项"。
参考此示例代码后,我发现您可能混合或缺少某些步骤。以下是一些建议:
节点对象具有读取和写入节点属性以及浏览或填充地址空间的方法。
print("Children of root are: ", root.get_children())
获取知道其节点 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
现在使用其浏览路径获取变量节点
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)
堆叠的myvar访问
print("myvar is: ", root.get_children()[0].get_children()[1].get_variables()[0].get_value())
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- Freeopcua C++ 客户端和 Python Opcua 的组合会在 getChild() 上抛出错误