def module(self): if hasattr(self, '_module') and self._module: return self._module # need to verify that the yocto device is attached errmsg = YRefParam() if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: raise Exception('could not register yocto usb connection') sensor = YCurrent.FirstCurrent() if sensor is None: raise Exception('could not find yocto ammeter device') if sensor.isOnline(): self._module = sensor.get_module() return self._module
def verify_usage(self, options, tests): MarionetteTestOptions.verify_usage(self, options, tests) #options, tests = self.parse_args() if options.iterations is not None and options.iterations < 1: raise ValueError('iterations must be a positive integer') if options.checkpoint_interval is not None and options.checkpoint_interval < 1: raise ValueError('checkpoint interval must be a positive integer') if options.checkpoint_interval and not options.iterations: raise ValueError( 'you must specify iterations when using checkpoint intervals') if options.yocto: # need to verify that the yocto ammeter is attached errmsg = YRefParam() if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: raise RuntimeError( 'could not register yocto usb connection: %s' % str(errmsg)) # rescan for yocto devices if YAPI.UpdateDeviceList(errmsg) != YAPI.SUCCESS: raise RuntimeError('could not detect yoctopuce modules: %s' % str(errmsg)) # check for ammeter ammeter = YCurrent.FirstCurrent() if ammeter is None: raise RuntimeError('could not find ammeter device') if ammeter.isOnline(): module = ammeter.get_module() dc_ammeter = YCurrent.FindCurrent(module.get_serialNumber() + '.current1') if (not module.isOnline()) or (dc_ammeter is None): raise RuntimeError('could not get ammeter device') else: raise RuntimeError('could not find yocto ammeter device') # check for data logger data_logger = YDataLogger.FirstDataLogger() if data_logger is None: raise RuntimeError('could not find data logger device') if data_logger.isOnline(): module = data_logger.get_module() data_logger = YDataLogger.FindDataLogger( module.get_serialNumber() + '.dataLogger') if not module.isOnline() or data_logger is None: raise RuntimeError('could not get data logger device') else: raise RuntimeError('could not find yocto ammeter device')
def startUp(self): if YAPI.RegisterHub('usb', YRefParam()) != YAPI.SUCCESS: sys.exit('Connection error: connection through USB failed') self.tiltSensorRight = Sensor() # bootstrap handlers for h in self.activeHandlers: self.tiltSensorRight.attachHandler(h()) self.tiltSensorRight.startWatching() # start display update loop def loop(): threading.Timer(.10, loop).start() # no-op here loop()
def __init__(self, target=None): errmsg = YRefParam() if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: raise IOError("init error" + errmsg.value) self.target = target if target is not None: self._module = YModule.FindModule(target) else: sensor = YHumidity.FirstHumidity() if sensor is None: raise IOError('No module connected') self._module = sensor.get_module() self.target = target = self._module.get_serialNumber() self._sensors = [ YHumidity.FindHumidity(target + '.humidity'), YPressure.FindPressure(target + '.pressure'), YTemperature.FindTemperature(target + '.temperature') ]
def gaia_verify_usage(self, options, tests): if options.yocto: # need to verify that the yocto ammeter is attached errmsg = YRefParam() if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: raise RuntimeError( 'could not register yocto usb connection: %s' % str(errmsg)) # rescan for yocto devices if YAPI.UpdateDeviceList(errmsg) != YAPI.SUCCESS: raise RuntimeError('could not detect yoctopuce modules: %s' % str(errmsg)) # check for ammeter ammeter = YCurrent.FirstCurrent() if ammeter is None: raise RuntimeError('could not find ammeter device') if ammeter.isOnline(): module = ammeter.get_module() dc_ammeter = YCurrent.FindCurrent(module.get_serialNumber() + '.current1') if (not module.isOnline()) or (dc_ammeter is None): raise RuntimeError('could not get ammeter device') else: raise RuntimeError('could not find yocto ammeter device') # check for data logger data_logger = YDataLogger.FirstDataLogger() if data_logger is None: raise RuntimeError('could not find data logger device') if data_logger.isOnline(): module = data_logger.get_module() data_logger = YDataLogger.FindDataLogger( module.get_serialNumber() + '.dataLogger') if not module.isOnline() or data_logger is None: raise RuntimeError('could not get data logger device') else: raise RuntimeError('could not find yocto ammeter device')
def module(self): # check if the module is already instantiated if hasattr(self, '_module') and self._module: return self._module # check if the ammeter is attached by USB errmsg = YRefParam() if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: raise Exception("Could not register the yocto device with USB connection.") #if YAPI.RegisterHub("http://127.0.0.1:4444", errmsg) != YAPI.SUCCESS: #raise Exception("Could not register the yocto device with USB connection.") ammeter = YCurrent.FirstCurrent() # find the ammeter if not ammeter: raise Exception("Could not find the yocto device.") # check if the ammeter is online if not ammeter.isOnline(): raise Exception("Your ammeter device is not currently reachable.") # initialize the ammeter and return this one self._module = ammeter.get_module() return self._module
def recording(self, value): if value: if self.recording: raise Exception('data logger already recording') # erase the data logger memory if self.data_logger.forgetAllDataStreams() != YAPI.SUCCESS: raise Exception('failed to clear yocto data logger memory') # go! if self.data_logger.set_recording( YDataLogger.RECORDING_ON) != YAPI.SUCCESS: raise Exception('failed to start yocto data logger') # delete all data that may be cached del self._data self._data = None # turn on the beacon self.beacon = True else: # are we currently recording? was_recording = self.recording # stop! if self.data_logger.set_recording( YDataLogger.RECORDING_OFF) != YAPI.SUCCESS: raise Exception('failed to stop yocto data logger') if was_recording: # get the first data stream streamsRef = YRefParam() self.data_logger.get_dataStreams(streamsRef) self._data = streamsRef.value[0] # turn off the beacon self.beacon = False
def startUp(self): if YAPI.RegisterHub('usb', YRefParam()) != YAPI.SUCCESS: sys.exit('Connection error: connection through USB failed') self.tiltSensorRight = Sensor() self.display = Display() # bootstrap handlers for h in self.activeHandlers: self.tiltSensorRight.attachHandler(h()) self.tiltSensorRight.startWatching() # start display update loop def loop(): threading.Timer(.10, loop).start() self.display.updateStatus() # for debugging, show data in the message row for now self.display.updateMessage('P:{} R:{}'.format( str(pitch), str(roll))) loop()