def run(self): logging.critical('elec communication: start') try: fagpio.export(elec_gpio) gpio=fagpio.gpio(elec_gpio) gpio.edge='rising' gpio.direction='in' gpio.active=1 t=time.time() i=0 while self.running: logging.debug('elec communication: before poll') events=gpio.epoll_obj.poll(1) for fileno,event in events: if fileno==gpio.fvalue.fileno(): now=time.time() diff=round(now-t,2) t=now if i>1: ec.inc() ec.period(diff) logging.info('elec communication: '+str(ec.value)+' '+str(diff)+' '+ str(ec.act_pow)) else: i+=1 logging.info('elec communication: init..') except Exception,e: logging.error('elec communication: '+str(e))
def run(self): print('elec communication thread start') try: fagpio.export(num) gpio=fagpio.gpio(num) gpio.edge='rising' gpio.direction='in' gpio.active=1 t=time.time() i=0 while self.running: events=gpio.epoll_obj.poll(1) for fileno,event in events: if fileno==gpio.fvalue.fileno(): now=time.time() diff=round(now-t,2) t=now if i>1: ec.inc() ec.period(diff) print(str(ec.value)+' '+str(diff)+' '+ str(ec.act_pow)) else: i+=1 print('.') except Exception,e: print('elec communication error: '+str(e))
def GDO0Open(self): p=self.GDO0Pin fagpio.export(p) p_obj=fagpio.gpio(p) p_obj.active=0 p_obj.direction='in' p_obj.edge='rising' self.GDO0File=p_obj.fvalue self.epoll_obj=p_obj.epoll_obj self.GDO0State=True
def run(self): try: gpio = fagpio.gpio(self.gpio) gpio.edge = self.edge gpio.direction = self.dir gpio.active = self.act s_id = str(self.id) s_gpio = str(self.gpio) logging.critical('gpio communication: start sensor:' + s_id + ' gpio:' + s_gpio + ' \ edge:' + self.edge + ' counter:' + str(self.counter)) # Если включен счетчик на датчике if self.counter: t = time.time() i = 0 while self.running: events = gpio.epoll_obj.poll(1) # logging.debug('gpio communication: sensor id ' + s_id + ': no event') for fileno, event in events: if fileno == gpio.fvalue.fileno(): now = time.time() diff = round(now - t, 2) t = now if i > 1: sensors[self.id].counter.inc() sensors[self.id].counter.period(diff) logging.debug('gpio communication: sensor ' + s_id + ' value:' + str( sensors[self.id].counter.value) + ' ' + str(diff) + ' ' + str( sensors[self.id].counter.vih) + ' ' + str(sensors[self.id].counter.vid)) else: i += 1 logging.info('gpio communication: sensor ' + s_id + ' counter init..') else: while self.running: events = gpio.epoll_obj.poll(1) # logging.debug('gpio communication: sensor id ' + s_id + ': no event') for fileno, event in events: # logging.debug('gpio communication: event file:'+str(fileno)+' event:'+str(event)+' \ # file:'+str(gpio.fvalue.fileno())) if fileno == gpio.fvalue.fileno(): # data=s_id+':'+str(gpio.value) logging.debug('gpio communication: sensor ' + s_id + ' signal') daemon.queue_out.add({'sensor_id':s_id,'value':1,'action_id':sensors[self.id].action_id}) except Exception, e: logging.error('gpio communication: ', exc_info=True)
def run(self): gpio=fagpio.gpio(self.gpio) gpio.edge=self.edge gpio.direction=self.dir gpio.active=self.act s_id=str(self.id) s_gpio=str(self.gpio) logging.critical('gpio communication: start sensor '+s_id+' on gpio '+s_gpio+' with edge '+ self.edge) while self.running: events=gpio.epoll_obj.poll(1) logging.debug('gpio communication: sensor id ' + s_id + ': no event') for fileno,event in events: logging.debug('gpio communication: event file:'+str(fileno)+' event:'+str(event)+' file:'+str(gpio.fvalue.fileno())) if fileno==gpio.fvalue.fileno(): data=s_id+':'+str(gpio.value) logging.info('gpio communication: sensor id ' + s_id + ' gpio ' + s_gpio + ': ' + data) daemon.queue.add(data) fagpio.unexport(self.gpio) logging.critical('gpio communication: unexport '+str(self.gpio)+' gpio') logging.critical('gpio communication: stop sensor '+s_id+' on gpio '+s_gpio+' with edge '+ self.edge)