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()
def connect_pmu(self): self.pdc = list() for conn_dict in self.connection_dicts: pmu = Pdc(pdc_id=conn_dict["id"], pmu_ip=conn_dict["ip"], pmu_port=conn_dict["port"]) pmu.logger.setLevel("DEBUG") try: pmu.run() self.pdc.append(pmu) except: pass for pmu in self.pdc: self.parse_config(pmu) pmu.start() self.get_dframes()
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
ref_pdc = Pdc(pmu_ip=IP, pmu_port=4712, pdc_id=1) mpdc = Pdc(pmu_ip=IP, pmu_port=PORT, pdc_id=ID) #pdc_one = Pdc(pmu_ip = HARD_IP, pmu_port = HARD_PORT, pdc_id = 11) pdc_one = Pdc(pmu_ip=IP, pmu_port=PORT, pdc_id=4) mpdc.run() ref_pdc.run() print("FIRST PMU") pdc_one.run() print("RUNNING") config = mpdc.get_config() print(config) ref_pdc.start() mpdc.start() pdc_one.start() data = "Not Connected" print("Connected") for i in range(10): ref_data = ref_pdc.get() data = mpdc.get() data_one = pdc_one.get() print(len(data)) print(len(data_one)) # print("PMU1") # print(data_one)
from pypmu.pdc import Pdc from pypmu.frame import DataFrame """ tinyPDC will connect to pmu_ip:pmu_port and send request for header message, configuration and eventually to start sending measurements. """ if __name__ == "__main__": pdc = Pdc(pdc_id=9, pmu_ip="192.168.1.119", pmu_port=4712) pdc.logger.setLevel("DEBUG") pdc.run() # Connect to PMU header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU pdc.start() # Request to start sending measurements while True: data = pdc.get() # Keep receiving data if type(data) == DataFrame: print(data.get_measurements()) if not data: pdc.quit() # Close connection break