Esempio n. 1
0
                    event.browseName))
            self.addProperties(event)
        self.iidx -= 2

    def generateEventsCode(self, model):
        self.output_file = open(self.output_file, "w")
        self.make_header()
        for event in model.values():
            if (event.browseName == "BaseEvent"):
                self.generateEventclass(event)
            else:
                parentNode = model[event.parentNodeId]
                self.generateEventclass(event, parentNode.browseName)
        self.write("")
        self.write("")
        self.write("IMPLEMENTED_EVENTS = {")
        self.iidx += 1
        for event in model.values():
            self.write("ua.ObjectIds.{0}Type: {0},".format(event.browseName))
        self.write("}")


if __name__ == "__main__":
    xmlPath = os.path.join(BASE_DIR, 'schemas', 'UA-Nodeset-master', 'Schema',
                           'Opc.Ua.NodeSet2.xml')
    output_file = os.path.join(BASE_DIR, 'opcua', 'common', 'event_objects.py')
    p = gme.Parser(xmlPath)
    model = p.parse()
    ECG = EventsCodeGenerator(model, output_file)
    ECG.generateEventsCode(model)
Esempio n. 2
0
            self.write("super().__init__(sourcenode, message, severity)")
            self.write("self.EventType = ua.NodeId(ua.ObjectIds.{0}Type)".format(event.browseName))
            self.add_properties_and_variables(event)
        self.iidx -= 2

    def generate_events_code(self, model_):
        self.make_header(model_.values())
        for event in model_.values():
            if event.browseName == "BaseEvent":
                self.generate_event_class(event)
            else:
                parent_node = model_[event.parentNodeId]
                self.generate_event_class(event, parent_node.browseName)
        self.write("")
        self.write("")
        self.write("IMPLEMENTED_EVENTS = {")
        self.iidx += 1
        for event in model_.values():
            self.write("ua.ObjectIds.{0}Type: {0},".format(event.browseName))
        self.write("}")


if __name__ == "__main__":
    xmlPath = BASE_DIR / 'schemas' / 'UA-Nodeset-master' / 'Schema' / 'Opc.Ua.NodeSet2.xml'
    output_path = BASE_DIR / 'asyncua' / 'common' / 'event_objects.py'
    p = gme.Parser(str(xmlPath))
    model = p.parse()
    with open(output_path, "w") as fp:
        ecg = EventsCodeGenerator(model, fp, xmlPath)
        ecg.generate_events_code(model)