2 Show 3 different examples for creating an object: 3 1) create a basic object 4 2) create a new object type and a instance of the new object type 5 3) import a new object from xml address space and create a instance of the new object type 8 sys.path.insert(0,
"..")
12 from opcua
import ua, Server
15 if __name__ ==
"__main__":
19 server.set_endpoint(
"opc.tcp://0.0.0.0:4840/freeopcua/server/")
22 uri =
"http://examples.freeopcua.github.io" 23 idx = server.register_namespace(uri)
26 objects = server.get_objects_node()
30 myobj = objects.add_object(idx,
"MyObject")
36 types = server.get_node(ua.ObjectIds.BaseObjectType)
38 object_type_to_derive_from = server.get_root_node().get_child([
"0:Types",
41 mycustomobj_type = types.add_object_type(idx,
"MyCustomObject")
42 mycustomobj_type.add_variable(0,
"var_should_be_there_after_instantiate", 1.0)
44 myobj = objects.add_object(idx,
"MyCustomObjectA", mycustomobj_type.nodeid)
51 server.import_xml(
'customobject.xml')
58 myobject1_type_nodeid = ua.NodeId.from_string(
'ns=1;i=1002')
59 myobject2_type_nodeid = server.get_root_node().get_child([
"0:Types",
"0:ObjectTypes",
"0:BaseObjectType",
"1:MyObjectType"]).nodeid
60 myobject3_type_nodeid = server.get_node(ua.ObjectIds.BaseObjectType).get_child([
"1:MyObjectType"]).nodeid
64 myobj = objects.add_object(idx,
"MyCustomObjectB", myobject3_type_nodeid)