本文整理汇总了Python中opcua.Server.get_root_node方法的典型用法代码示例。如果您正苦于以下问题:Python Server.get_root_node方法的具体用法?Python Server.get_root_node怎么用?Python Server.get_root_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcua.Server
的用法示例。
在下文中一共展示了Server.get_root_node方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import get_root_node [as 别名]
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# Import customobject type
server.import_xml('customobject.xml')
# get Objects node, this is where we should put our custom stuff
objects = server.get_objects_node()
# get nodeid of custom object type by :
# 1) Use node ID
# 2) Or Full path
# 3) Or As child from parent
nodeid_a = ua.NodeId.from_string('ns=1;i=1002')
nodeid_b = server.get_root_node().get_child(["0:Types", "0:ObjectTypes", "0:BaseObjectType", "1:MyObjectType"]).nodeid
nodeid_c = server.get_node(ua.ObjectIds.BaseObjectType).get_child(["1:MyObjectType"]).nodeid
myobject_type_nodeid = nodeid_a
# populating our address space
myobj = objects.add_object(idx, "MyObject",)
myobj = objects.add_object(idx, "MyCustomObject", myobject_type_nodeid)
# starting!
server.start()
try:
while True:
time.sleep(1)
示例2: Server
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import get_root_node [as 别名]
items.append(ua.LocalizedText(value.name))
return items
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"
nsidx = server.register_namespace(uri)
# --------------------------------------------------------
# create custom enum data type
# --------------------------------------------------------
enums = server.get_root_node().get_child(["0:Types", "0:DataTypes", "0:BaseDataType", "0:Enumeration"])
# 1.
# Create Enum Type
myenum_type = enums.add_subtype(nsidx, 'MyEnum', ua.NodeClass.DataType)
# 2.
# Add enumerations as EnumStrings (Not yet tested with EnumValues)
# Essential to use namespace 0 for EnumStrings !
# By hand
# es = myenum_type.add_variable(0, "EnumStrings" , [ua.LocalizedText("ok"),
# ua.LocalizedText("idle")])
# Or convert the existing IntEnum MyEnum
es = myenum_type.add_variable(0, "EnumStrings" , enum_to_stringlist(MyEnum))
示例3:
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import get_root_node [as 别名]
# get Objects node, this is where we should put our custom stuff
objects = server.get_objects_node()
# Example 1 - create a basic object
#-------------------------------------------------------------------------------
myobj = objects.add_object(idx, "MyObject")
#-------------------------------------------------------------------------------
# Example 2 - create a new object type and a instance of the new object type
#-------------------------------------------------------------------------------
types = server.get_node(ua.ObjectIds.BaseObjectType)
object_type_to_derive_from = server.get_root_node().get_child(["0:Types",
"0:ObjectTypes",
"0:BaseObjectType"])
mycustomobj_type = types.add_object_type(idx, "MyCustomObjectType")
mycustomobj_type.add_variable(0, "var_should_be_there_after_instantiate", 1.0) # demonstrates instantiate
myobj = objects.add_object(idx, "MyCustomObjectA", mycustomobj_type.nodeid)
#-------------------------------------------------------------------------------
# Example 3 - import a new object from xml address space and create a instance of the new object type
#-------------------------------------------------------------------------------
# Import customobject type
server.import_xml('customobject.xml')
# get nodeid of custom object type by one of the following 3 ways: