【发布时间】:2018-01-01 18:22:10
【问题描述】:
我正在使用 python 处理OPCUA。我正在使用freeopc。我已经使用了他们的 server_minimal 和 client_minimal 示例,并且运行良好。我在理解代码时遇到了一些问题。据我所知 OPCUA 堆栈,它的地址空间就像所有节点的集合。然后这些节点进一步包含对象,并且这些对象具有我们可以从中读取写入数据的变量。如果我错了,请纠正我。
---------------------------------
Address space
---------------------------------
| |
| |
V V
Node1 Node2
|
Object1
|
Var1, Var2
所以在服务器端我想知道什么是命名空间
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
命名空间的用途是什么?在 uri 里面放什么?
在客户端,我想知道:
连接服务器后,我们正在做:
# 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)
get_root_node() 是什么意思。是不是就像我们正在连接到定义了所有节点的服务器的地址空间一样?
# 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()-- 意思是获取节点的对象吗?
# 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是什么意思?
客户端输出:
('Objects node is: ', Node(TwoByteNodeId(i=84)))
('Children of root are: ', [Node(NumericNodeId(i=85)), Node(NumericNodeId(i=86)), Node(NumericNodeId(i=87))])
以上代码取自server_minimal.pyclient_minimal.py
谁能解释一下这些。我尝试阅读他们的文档,但那里没有提到。
谢谢。
【问题讨论】: