class Command(BaseCommand): args = '' help = 'Runs the UberClock background daemon' option_list = BaseCommand.option_list + ( make_option('--msp-ap', dest='msp_ap', default=None, help='EZ430 Accesspoint Path'), ) def handle(self, *args, **options): logging.basicConfig(level=logging.DEBUG) # main clock instance self.clock = Clock() thread.start_new_thread(self.start_webserver, ()) thread.start_new_thread(self.start_clock, ()) if settings.CLOCK_HARDWARE.lower() == "ezchronos": self.msp_ap = options['msp_ap'] or settings.EZ_SERIAL self.ez_chronos(*args, **options) def start_clock(self, *args, **options): self.clock.run() def ez_chronos(self, *args, **options): while True: try: ser = serial.Serial(self.msp_ap, 115200,timeout=1) except serial.serialutil.SerialException: logging.error("Can't open console %s" %self.msp_ap) time.sleep(5) continue pv = DBWriter(ser, clock=self.clock) pv.debug = 0 pv.reset() pv.start_ap() try: logging.info("OpenChronos interface started on %s" %self.msp_ap) pv.loop_smpl_get() except KeyboardInterrupt: pv.close() ser.close() sys.exit(0) except Exception, e: logging.exception(e) # try to cleanup, which may fail try: pv.reset() except: pass try: pv.close() except: pass try: ser.close() del ser except: pass
def handle(self, *args, **options): logging.basicConfig(level=logging.DEBUG) # main clock instance self.clock = Clock() thread.start_new_thread(self.start_webserver, ()) thread.start_new_thread(self.start_clock, ()) if settings.CLOCK_HARDWARE.lower() == "ezchronos": self.msp_ap = options['msp_ap'] or settings.EZ_SERIAL self.ez_chronos(*args, **options)