def pdcThread(pmuID, pmu_ip, port, buffSize): pdc = Pdc(pdc_id=int(pmuID), pmu_ip=pmu_ip, pmu_port=int(port), buffer_size=buffSize) # pdc.logger.setLevel("DEBUG") pdc.run() # Connect to PMU dt_buffer = list() try: header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU except BrokenPipeError as e: pdc.quit() sys.exit() pdc.start() # Request to start sending measurements while True: data = pdc.get() # Keep receiving data if data is None: data = pdc.get() # Try again receiving data if type(data) == DataFrame: outData = data.get_measurements() yield outData if not data: pdc.quit() # Close connection break
class StreamSplitter(object): def __init__(self, source_ip, source_port, listen_ip, listen_port, pdc_id=1, method="tcp", buffer_size=2048): self.pdc = Pdc(pdc_id, source_ip, source_port, buffer_size, method) self.pmu = Pmu(ip=listen_ip, port=listen_port, method=method, buffer_size=buffer_size, set_timestamp=False) self.source_cfg1 = None self.source_cfg2 = None self.source_cfg3 = None self.source_header = None def run(self): self.pdc.run() self.source_header = self.pdc.get_header() self.source_cfg2 = self.pdc.get_config() self.pdc.start() self.pmu.run() self.pmu.set_header(self.source_header) self.pmu.set_configuration(self.source_cfg2) while True: message = self.pdc.get() if self.pmu.clients and message: self.pmu.send(message) if isinstance(message, HeaderFrame): self.pmu.set_header(message) elif isinstance(message, ConfigFrame2): self.pmu.set_configuration(message)
method=arguments.method) pdc.logger.setLevel(arguments.log_level) pdc.run() # Connect to PMU header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU # Create result folder if not os.path.exists("results/" + str(arguments.data_rate)): os.makedirs("results/" + str(arguments.data_rate)) log = "./results/{:d}/result_j{:d}_id_{:d}_{:s}.log".format( arguments.data_rate, arguments.jobs, arguments.id, timestamp) pdc.start() # Request to start sending measurements start_time = stop_time = time.time() while measurements2receive > 0: try: data = pdc.get() # Keep receiving data except: print("Whooa! Something went wrong!") errors += 1 if measurements2receive == 1: stop_time = time.time() if not data: print("Wait! Wait! Where is the data?") errors += 1
#127.0.1.10", port=1420 #pdc(x) = Pdc(pdc_id=7, pmu_ip=ip, pmu_port=4712) #pdc1 = Pdc(pdc_id=7, pmu_ip="127.0.0.4", pmu_port=4712) # pdc.logger.setLevel("DEBUG") # pdc1.logger.setLevel("DEBUG") n = os.fork() if n == 0: print("Child process : ", os.getpid()) pdc = Pdc(pdc_id=idd, pmu_ip=ip, pmu_port=1420) pdc.logger.setLevel("DEBUG") pdc.run() header = pdc.get_header() config = pdc.get_config() pdc.start() while True: data = pdc.get() if type(data) == DataFrame: print(data.get_measurements()) if not data: pdc.quit() break else: print("Parent process: ", os.getpid()) p = os.wait() # pdc.run() # Connect to PMU # pdc1.run()
pdc3.logger.setLevel("DEBUG") # pdc4.logger.setLevel("DEBUG") pdc1.run() # Connect to PMU pdc2.run() # Connect to PMU pdc3.run() # Connect to PMU # pdc4.run() # Connect to PMU header = pdc1.get_header() # Get header message from PMU config = pdc1.get_config() # Get configuration from PMU header = pdc2.get_header() # Get header message from PMU config = pdc2.get_config() header = pdc3.get_header() # Get header message from PMU config = pdc3.get_config() pdc1.start() # Request to start sending measurements pdc2.start() # Request to start sending measurements pdc3.start() # Request to start sending measurements while True: Test = [] result_queue = Queue() result_queue1 = Queue() result_queue2 = Queue() data1 = Process(target=pdc1.get_msg, args=(result_queue,)) data1.start() results = result_queue.get()
from synchrophasor.pdc import Pdc """ tinyPDC will connect to pmu_ip:pmu_port and send request for header message, configuration and eventually to start sending measurements. ONLY FOR TCP """ pdc = Pdc(pdc_id=7, pmu_ip='127.0.0.1', pmu_port=4712) 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 not data: pdc.quit() # Close connection break