2 This example demonstrates the use of custom enums by: 3 - Create a custom enum type 4 - Create an object that contains a variable of this type 7 sys.path.insert(0,
"..")
10 from IPython
import embed
17 shell = code.InteractiveConsole(vars)
23 from opcua
import ua, Server
25 from enum
import IntEnum
37 items.append(ua.LocalizedText(value.name))
40 if __name__ ==
"__main__":
43 server.set_endpoint(
"opc.tcp://0.0.0.0:4840/freeopcua/server/")
46 uri =
"http://examples.freeopcua.github.io" 47 nsidx = server.register_namespace(uri)
52 enums = server.get_root_node().get_child([
"0:Types",
"0:DataTypes",
"0:BaseDataType",
"0:Enumeration"])
56 myenum_type = enums.add_data_type(nsidx,
'MyEnum')
70 es.set_array_dimensions([0])
76 objects = server.get_objects_node()
79 myobj = objects.add_object(nsidx,
'MyObjectWithEnumVar')
82 myenum_var = myobj.add_variable(nsidx,
'MyEnum2Var', MyEnum.ok, datatype = myenum_type.nodeid)
83 myenum_var.set_writable()
84 myenum_var.set_value(MyEnum.idle)
def enum_to_stringlist(a_enum)