def send_es(vall,boo): with com_lock: val = vall.encode('utf-8') clientOut.send(val, zmq.NOBLOCK) print 'sent but waiting for response' status=clientOut.recv() logging.debug('sent message to cc: %s '%val) print 'sent' thread.exit() def get_val(): update = 'update b p monitor_1 post_monitor_1 %s %s 1 mon_wind_gen\n' %(time.time(),Gen_ID) pipe.send_sync_event(update.encode('UTF-8'), pipin) def t(): print(time.time()) #time.sleep(2)# for sync to start properly while 1: time.sleep(TIME_INT) get_val() #listen to response and send to cc x = pipe.listen(pipeout) if x: print x send_cc(x)
if iterations !=1: threading.Timer (interval,do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1] ).start() worker_func() def request_data(): update = ('update b p pre_pmu post_pmu %s a1 0\n'% time.time()) pipe.send_sync_event(update.encode('UTF-8'), pipin) pmu = read_pmu('./models/pmu.config') _cfg2(pmu) do_every(0.3,request_data) while 1: raw_message=pipe.listen(pipout) if raw_message: message=raw_message[0] if message[0] == 'cfg2': _cfg2(pmu) else: raw_data = raw_message #raw_data = '7199.36 0.1 7199.37 -2.27 7199.36 2.27 334.51 -0.6225 59.9 0.01' phasor_data, analog_data, digital_data, freq_data, dfreq_data = data_process(raw_data,pmu) _data(pmu, phasor_data, analog_data, digital_data, freq_data, dfreq_data) print('Sent')
def listen(): message=pipe.listen(pipeout) logging.debug(message)