@@ -540,7 +540,7 @@ def import_and_register_structures(self, nodes=None):
540540 If no no node is given, attemps to import variables from all nodes under
541541 "0:OPC Binary"
542542 the code is generated and imported on the fly. If you know the structures
543- are not going to be modified it is safer to copy the generated files
543+ are not going to be modified it might be interresting to copy the generated files
544544 and include them in you code
545545 """
546546 if nodes is None :
@@ -549,22 +549,29 @@ def import_and_register_structures(self, nodes=None):
549549 if desc .BrowseName != ua .QualifiedName ("Opc.Ua" ):
550550 nodes .append (self .get_node (desc .NodeId ))
551551 self .logger .info ("Importing structures from nodes: %s" , nodes )
552-
552+
553+ structs_dict = {}
553554 for node in nodes :
554555 xml = node .get_value ()
555556 xml = xml .decode ("utf-8" )
556- #with open("titi.xml", "w") as f:
557- #f.write(xml)
558557 name = "structures_" + node .get_browse_name ().Name
559558 gen = StructGenerator ()
560559 gen .make_model_from_string (xml )
561- structs_dict = gen .save_and_import (name + ".py" )
562- # register classes
563- for desc in node .get_children_descriptions ():
564- if desc .BrowseName .Name in structs_dict :
565- self .logger .info ("registring new structure: %: %s" , desc .NodeId , desc .BrowseName .Name )
566- ua .extension_object_classes [desc .NodeId ] = structs_dict [desc .BrowseName .Name ]
567- ua .extension_object_ids [desc .BrowseName .Name ] = desc .NodeId
560+ gen .save_and_import (name + ".py" , append_to = structs_dict )
561+
562+ # register classes
563+ for desc in self .nodes .base_structure_type .get_children_descriptions ():
564+ # FIXME: maybe we should look recursively at children
565+ # FIXME: we should get enoding and description but this is too
566+ # expensive. we take a shorcut and assume that browsename of struct
567+ # is the same as the name of the data type structure
568+ if desc .BrowseName .Name in structs_dict :
569+ struct_node = self .get_node (desc .NodeId )
570+ refs = struct_node .get_references (ua .ObjectIds .HasEncoding , ua .BrowseDirection .Forward )
571+ for ref in refs :
572+ if "Binary" in ref .BrowseName .Name :
573+ ua .register_extension_object (desc .BrowseName .Name , ref .NodeId , structs_dict [desc .BrowseName .Name ])
574+
568575
569576
570577
0 commit comments