2017-04-18 207 views

回答

0

你想要完成什么?结构是相当重要的问题,因为你可以摆脱它。 Onces它的安装运行的服务器并检查它witth他的命令行

opcua-client 

这个GUI可能会帮助很多见的服务器的结构。

opcua服务器存在于节点组合之外。他们中的一些标准节点,你会在你运行 编程时许多这些基本的节点可以接收使用最基本的OPC服务器看到:

server.nodes#.<some node use your IDE> 

对于你需要找到他们所有自定义节点,你可以通过打电话给孩子来做到这一点。例如:

# To get the root node ALL other nodes are a child fro; this one eventually 
root = server.get_root_node() 
# To get a child: 
root.get_child("0:Objects") #Objects is one of those basic nodes 
# You can get a child from a path 
# Once again first study the tree with the opcua-client gui 
# This gui is installed automatically and under the commane opcua-client 
root.get_child(["0:Objects", "0:Server"]) 

# The above will get the child of Objects called Server 
# directly starting at the root node 

现在你可以自己创建子节点。你去你想要添加孩子的节点通常:

# The Objects node 
# Later you'll probably want to put that all in 1 line 
objects = server.nodes.objects 
id, name, type = 2, "testName", None 
test = objects.add_object(id, name, type) 
# This will add a object named testName to the objects node 
# To acces this node again we can use it's id 
server.get_node(test.nodeid) 
# I know this will return test again. 
# However the ua methods "parent' parameter is this nodeid so can come in very handy 

创建ua方法可能也将成为您的服务器的一项重要任务。

@uamethod 
def methode(parent, input): 
    print(input) # You can do all things here offcourse 

server.nodes.objects.add_method(0, "myMethod", methode, ua.VariantType.ByteString, None) 

这将方法添加到对象节点

0是你想给它的ID。我不能真正解释你应该选择什么号码...我通常只是选择2 ...

“mymethod”将是它的浏览名称,它允许您使用节点

的get_child和call_method方法找到它

方法不合适您的方法

ua.VariantType。需要解析inputargs的数据

无同上,但outputargs ...这我functiond没有

希望这有助于你一点理解,你可以用做最基础知识freeopcua库

相关问题