我能够使用python-opcua示例创建自定义数据类型。我想为自定义数据类型创建一个数组。示例:我想创建:ARRAY [0..1] OF type_def_Struct
我尝试创建一个列表,就像在python中一样,并在其中定义自定义变量。这是创建它的正确方法吗?
#Custom Variable
custom_var_1 = "custom_var_1"
dict_builder = DataTypeDictionaryBuilder(server, idx, OPCUA_NAMESPACE, "My_Dict")
custom_var_1_name = dict_builder.create_data_type(custom_var_1)
custom_var_1_name.add_field("id", ua.VariantType.Int32)
custom_var_1_name.add_field("name", ua.VariantType.String)
# dev is just another object
my_obj = server.nodes.objects.add_object(idx, "Device-001", dev)
# Array for custom variable
basic_struct_1= [my_obj.add_variable(idx, "type_def_Struct_1", ua.Variant(None, ua.VariantType.Null),
custom_var_1_name.data_type),
my_obj.add_variable(idx, "type_def_Struct_2",
ua.Variant(None, ua.VariantType.Null),
custom_var_1_name.data_type)]
basic_struct_1[0].set_writable(True)
basic_msg_1 = get_ua_class(custom_var_1)()
basic_msg_1.id = 1
basic_msg_1.name = "abc"
basic_struct_1[0].set_value(basic_msg_1)
basic_struct_1[1].set_writable(True)
basic_msg_1 = get_ua_class(custom_var_1)()
basic_msg_1.id = 2
basic_msg_1.name = "cdf"
basic_struct_1[1].set_value(basic_msg_1)