@@ -557,7 +557,7 @@ def import_and_register_structures(self, nodes=None):
557557 If no no node is given, attemps to import variables from all nodes under
558558 "0:OPC Binary"
559559 the code is generated and imported on the fly. If you know the structures
560- are not going to be modified it is safer to copy the generated files
560+ are not going to be modified it might be interresting to copy the generated files
561561 and include them in you code
562562 """
563563 if nodes is None :
@@ -566,22 +566,29 @@ def import_and_register_structures(self, nodes=None):
566566 if desc .BrowseName != ua .QualifiedName ("Opc.Ua" ):
567567 nodes .append (self .get_node (desc .NodeId ))
568568 self .logger .info ("Importing structures from nodes: %s" , nodes )
569-
569+
570+ structs_dict = {}
570571 for node in nodes :
571572 xml = node .get_value ()
572573 xml = xml .decode ("utf-8" )
573- #with open("titi.xml", "w") as f:
574- #f.write(xml)
575574 name = "structures_" + node .get_browse_name ().Name
576575 gen = StructGenerator ()
577576 gen .make_model_from_string (xml )
578- structs_dict = gen .save_and_import (name + ".py" )
579- # register classes
580- for desc in node .get_children_descriptions ():
581- if desc .BrowseName .Name in structs_dict :
582- self .logger .info ("registring new structure: %: %s" , desc .NodeId , desc .BrowseName .Name )
583- ua .extension_object_classes [desc .NodeId ] = structs_dict [desc .BrowseName .Name ]
584- ua .extension_object_ids [desc .BrowseName .Name ] = desc .NodeId
577+ gen .save_and_import (name + ".py" , append_to = structs_dict )
578+
579+ # register classes
580+ for desc in self .nodes .base_structure_type .get_children_descriptions ():
581+ # FIXME: maybe we should look recursively at children
582+ # FIXME: we should get enoding and description but this is too
583+ # expensive. we take a shorcut and assume that browsename of struct
584+ # is the same as the name of the data type structure
585+ if desc .BrowseName .Name in structs_dict :
586+ struct_node = self .get_node (desc .NodeId )
587+ refs = struct_node .get_references (ua .ObjectIds .HasEncoding , ua .BrowseDirection .Forward )
588+ for ref in refs :
589+ if "Binary" in ref .BrowseName .Name :
590+ ua .register_extension_object (desc .BrowseName .Name , ref .NodeId , structs_dict [desc .BrowseName .Name ])
591+
585592
586593
587594
0 commit comments