代码拉取完成,页面将自动刷新
import sys
sys.path.insert(0, "..")
from opcua import Client
if __name__ == "__main__":
#client = Client("opc.tcp://localhost:4840/freeopcua/server/")
client = Client("opc.tcp://localhost:4842")
# client = Client("opc.tcp://admin@localhost:4840/freeopcua/server/") #connect using a user
try:
client.connect()
# 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)
# 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())
# 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
# Now getting a variable node using its browse path
#myvar = root.get_child(["0:Objects", "2:MyObject", "2:MyVariable"])
myvar = root.get_children()
obj = root.get_child(["0:Objects", "2:MyObject"])
print("myvar is: ", str(myvar))
print("myobj is: ", str(obj))
# Stacked myvar access
# print("myvar is: ", root.get_children()[0].get_children()[1].get_variables()[0].get_value())
finally:
client.disconnect()
#"""\
# % Search needed signal nodes from namespace
# topNodes = uaClient.Namespace;
# simulationChildren = topNodes(2).Children;
# The NodeId’s of all Apros modules, properties, and simulation control methods are of type
# String and belong to the namespace http://www.apros.fi/OPC_UA/ (the namespace
# index is 2).
# simulationTypes = simulationChildren(1).Children;
# % Get analog signal nodes
# simulationTypesA = simulationTypes(1).Children;
#"""
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。