def run(self): try: timer = IntervalTimer(self.__sample_interval) while timer.true(): # position... gga = self.__gps.report(GPGGA) datum = GPSDatum.construct_from_gga(gga) if datum is None: continue # average... if datum.quality > 0: self.__averaging.append( datum) # only append valid positional fixes value = self.__averaging.compute() if value is None: value = datum # provide current datum when there is no average # report... with self._lock: value.as_list(self._value) except KeyboardInterrupt: pass
def run(self): try: timer = IntervalTimer(self.item.interval) while timer.true(): # enable sampler... self.__mutex.release() time.sleep(Scheduler.RELEASE_PERIOD ) # release period: hand semaphore to sampler try: # disable sampler... self.__mutex.acquire(self.item.interval) except BusyError: # release... self.__mutex.release() print('%s.run: released on busy' % self.item.name, file=sys.stderr) sys.stderr.flush() except (ConnectionError, KeyboardInterrupt, SignalError, SystemExit): pass
def run(self): try: timer = IntervalTimer(60) # self.__conf.sample_period while timer.true(): datum = self.__psu.status() with self._lock: datum.as_list(self._value) except KeyboardInterrupt: pass
def run(self): self.__opc.sample() # reset counts try: timer = IntervalTimer(self.__conf.sample_period) while timer.true(): datum = self.__opc.sample() with self._lock: datum.as_list(self._value) except KeyboardInterrupt: pass
def run(self): try: timer = IntervalTimer(self.UPDATE_INTERVAL) while timer.true(): with self._lock: status = SystemStatus.construct_from_jdict( OrderedDict(self._value)) if status is not None: self.__display.status_message = status.message self.__display.update() except (BrokenPipeError, KeyboardInterrupt, SystemExit): pass
def run(self): try: # clean... self.__opc.clean() # sample... timer = IntervalTimer(self.__conf.sample_period) while timer.true(): try: if not self.__opc.data_ready(): print("OPCMonitor.run: data not ready.", file=sys.stderr) self.__empty() continue datum = self.__opc.sample() if datum.is_zero() and not self.__first_reading: raise ValueError("zero reading") if not self.__first_reading: with self._lock: datum.as_list(self._value) except LockTimeout as ex: print("OPCMonitor.run: %s" % ex, file=sys.stderr) self.__empty() except ValueError as ex: print("OPCMonitor.run: %s" % ex, file=sys.stderr) self.__empty() self.__power_cycle() except OSError as ex: print("OPCMonitor.run: %s" % ex, file=sys.stderr) self.__error(self.__FATAL_ERROR) break if self.__first_reading: self.__first_reading = False except KeyboardInterrupt: pass
def run(self): self.__opc.sample() # reset counts try: timer = IntervalTimer(self.__conf.sample_period) while timer.true(): sample = self.__opc.sample() # report... with self._lock: sample.as_list(self._value) # monitor... if sample.is_zero(): self.__power_cycle() except KeyboardInterrupt: pass
class TimedRunner(Runner): """ classdocs """ # ---------------------------------------------------------------------------------------------------------------- def __init__(self, interval, sample_count=None): """ Constructor """ self.__timer = IntervalTimer(interval) self.__sample_count = sample_count # ---------------------------------------------------------------------------------------------------------------- def reset(self): self.__timer = IntervalTimer(self.__timer.interval) def samples(self, sampler): if self.__sample_count is None: while self.__timer.true(): yield sampler.sample() else: for _ in self.__timer.range(self.__sample_count): yield sampler.sample() # ---------------------------------------------------------------------------------------------------------------- @property def timer(self): return self.__timer @property def sample_count(self): return self.__sample_count # ---------------------------------------------------------------------------------------------------------------- def __str__(self, *args, **kwargs): return "TimedRunner:{timer:%s, sample_count:%s}" % ( self.__timer, self.__sample_count)
def run(self): sleep_time = self.__ndir.get_sample_interval() timer = IntervalTimer(sleep_time + 0.2) try: while timer.true(): self.__ndir.sample() time.sleep(sleep_time) datum = NDIRVoltages(*self.__ndir.get_sample_voltage()) if self.__raw else self.__ndir.get_sample_gas() self.__averaging.append(datum) average = self.__averaging.mid() # report... with self._lock: average.as_list(self._value) except (ConnectionError, KeyboardInterrupt, LockTimeout): pass
def run(self): # initialise fuel guage... batt_pack = self.__psu.batt_pack if batt_pack is not None: params = batt_pack.initialise(self.__host, force_config=False) if params: print("PSUMonitor.run: battery pack initialised: %s" % params, file=sys.stderr) sys.stderr.flush() # monitor PSU... try: timer = IntervalTimer(self.__MONITOR_INTERVAL) while timer.true(): status = self.__psu.status() if status is None: continue # report... with self._lock: status.as_list(self._value) # fuel gauge... self.__save_fuel_gauge_params(batt_pack) # shutdown... if not self.__ignore_standby and status.standby: self.__enter_host_shutdown("STANDBY") if not self.__ignore_threshold and status.below_power_threshold(self.__psu.charge_min()): self.__enter_host_shutdown("BELOW POWER THRESHOLD") except (ConnectionError, KeyboardInterrupt, SystemExit): pass
from scs_ndir.gas.ndir.spi_ndir_x1.spi_ndir_x1 import SPINDIRx1 # -------------------------------------------------------------------------------------------------------------------- try: I2C.Sensors.open() ndir = SPINDIRx1(False, Host.ndir_spi_bus(), Host.ndir_spi_device()) print(ndir, file=sys.stderr) print("-", file=sys.stderr) ndir.power_on() start_time = time.time() timer = IntervalTimer(3.0) for _ in timer.range(4000): ndir.get_sample_mode(True) rec = LocalizedDatetime.now().utc() co2_datum = ndir.sample() sample = GasesSample('', rec, co2_datum, None, None) print(JSONify.dumps(sample)) sys.stdout.flush() except KeyboardInterrupt: print("") finally:
ndir.sample() time.sleep(interval) datum = ndir.get_sample_gas() print("response after %s secs..." % interval) print("datum: %s" % datum) print("-") ndir.sample() start_time = time.time() time.sleep(0.7) timer = IntervalTimer(0.1) for i in timer.range(15): elapsed_time = time.time() - start_time try: datum = ndir.get_sample_gas() except NDIRException as ex: datum = ex print("%0.3f: datum: %s" % (elapsed_time, datum)) print("-") version = ndir.version() print("version: %s" % version)
def reset(self): self.__timer = IntervalTimer(self.__timer.interval)
def __init__(self, interval, sample_count=None): """ Constructor """ self.__timer = IntervalTimer(interval) self.__sample_count = sample_count
from scs_ndir.gas.ndir.spi_ndir_x1.spi_ndir_x1 import SPINDIRx1 # -------------------------------------------------------------------------------------------------------------------- try: I2C.Sensors.open() ndir = SPINDIRx1(False, Host.ndir_spi_bus(), Host.ndir_spi_device()) print(ndir, file=sys.stderr) print("-", file=sys.stderr) ndir.power_on() start_time = time.time() timer = IntervalTimer(1.0) print("rec, pile_ref_amplitude, pile_act_amplitude, pile_diff, thermistor_avg") while timer.true(): elapsed_time = time.time() - start_time pile_ref_amplitude, pile_act_amplitude, thermistor_avg = ndir.get_sample_voltage() diff = pile_ref_amplitude - pile_act_amplitude print("%7.3f, %0.4f, %0.4f, %0.4f, %0.4f" % (elapsed_time, pile_ref_amplitude, pile_act_amplitude, diff, thermistor_avg)) sys.stdout.flush() except KeyboardInterrupt: print("")
print(ndir, file=sys.stderr) print("-", file=sys.stderr) ndir.power_on() status = ndir.status() jstr = JSONify.dumps(status) print("status: %s" % jstr, file=sys.stderr) print("-", file=sys.stderr) print("calibrating...", file=sys.stderr) ndir.measure_calibrate() start_time = time.time() timer = IntervalTimer(interval) print("rec, pile_ref, pile_act, thermistor") for _ in timer.range(sample_count): pile_ref_voltage, pile_act_voltage, thermistor_voltage = ndir.measure_raw( ) elapsed_time = time.time() - start_time # fluked_thermistor = thermistor_voltage - 65536 # print("%0.3f, %0.4f, %0.4f, %0.4f" % (elapsed_time, pile_ref_voltage, pile_act_voltage, thermistor_voltage)) print("%0.3f, %s, %s, %s" % (elapsed_time, pile_ref_voltage, pile_act_voltage, thermistor_voltage)) sys.stdout.flush()