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)
"Running PDC(s) on {:d} separate thread(s) waiting for {:d} measurements with expected" " data rate of {:d} measurements per second.\n".format( arguments.jobs, measurements2receive, arguments.data_rate)) sleep(2) pdc = Pdc(pdc_id=arguments.id, pmu_ip=arguments.ip, pmu_port=arguments.port, buffer_size=arguments.buffer, 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(ip) #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
pdc2 = Pdc(pdc_id=7, pmu_ip=iplist[1], pmu_port=1410) pdc3 = Pdc(pdc_id=7, pmu_ip=iplist[2], pmu_port=1410) # pdc4 = Pdc(pdc_id=7, pmu_ip=iplist[3], pmu_port=1410) pdc1.logger.setLevel("DEBUG") pdc2.logger.setLevel("DEBUG") 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()
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