コード例 #1
0
class C37ReceiverThread(threading.Thread):
    def __init__(self, component):
        threading.Thread.__init__(self)
        self.active = threading.Event()
        self.active.clear()
        self.waiting = threading.Event()
        self.terminated = threading.Event()
        self.terminated.clear()
        self.component = component
        self.pdc = Pdc(pmu_ip=self.component.pmu_ip,
                             pmu_port=self.component.pmu_port)

    def run(self):
        self.data_plug = self.component.data_queue.setupPlug(self)
        self.config_plug = self.component.config_queue.setupPlug(self)
        self.header_plug = self.component.header_queue.setupPlug(self)

        while True:
            if self.terminated.is_set():
                break

            if not self.active.is_set():
                if self.pdc.is_connected():
                    self.pdc.stop()
                    self.active.wait()
                    self.pdc.start()
                else:
                    self.active.wait()

            if self.pdc.is_connected():
                data = self.pdc.get()
                self.data_plug.send_pyobj(data)

            else:
                self.pdc.run()
                if self.pdc.is_connected():
                    header = self.pdc.get_header()
                    self.header_plug.send_pyobj(header)
                    config = self.pdc.get_config()
                    self.config_plug.send_pyobj(config)
                    self.pdc.start()
                else:
                    # TODO: wait some?
                    pass


        self.pdc.quit()

    def activate(self):
        self.active.set()

    def deactivate(self):
        self.active.clear()

    def terminate(self):
        self.terminated.set()
コード例 #2
0
    def connect_pmu(self):
        #Connect to all the PMUs
        if self.pdc is None:
            self.pdc = list()
            for PMU in PMUS:
                pmu = Pdc(pmu_ip=PMU[0], pdc_id=PMU[2], pmu_port=PMU[1])
                pmu.run()
                self.pdc.append(pmu)

        for pmu in self.pdc:
            if not pmu.is_connected():
                return False
            pmu.start()

        dframe_thread = threading.Thread(target=self.get_dframes)
        dframe_thread.start()

        return True