3

I am able to create a custom datatype using python-opcua examples. I want to create an array for the custom data type. Example: I want to create : ARRAY[0..1] OF type_def_Struct

I tried by creating a list, like we do in python and define custom variable in it. is this the right way to create it?

#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)
  • You don't specify why you're asking if this approach is correct. Does it work? If not, what is the issue? From what I can see, there is no need to additionally register the new data type with the server, `create_data_type` has a reference to the server and should do that automatically. If you have a client that has issues deciphering the data type, then it probably doesn't evaluate the data type dictionary correctly. – starturtle Apr 04 '20 at 10:13

0 Answers0