def validate(self): # pylint: disable=too-many-branches if not daq: raise ImportError(import_error_mesg) self._results = None self._metrics = set() if self.labels: if len(self.labels) != len(self.resistor_values): raise ConfigError('Number of DAQ port labels does not match the number of resistor values.') duplicates = set([x for x in self.labels if self.labels.count(x) > 1]) if len(duplicates) > 0: raise ConfigError('Duplicate labels: {}'.format(', '.join(duplicates))) else: self.labels = ['PORT_{}'.format(i) for i, _ in enumerate(self.resistor_values)] self.server_config = ServerConfiguration(host=self.server_host, port=self.server_port) self.device_config = DeviceConfiguration(device_id=self.device_id, v_range=self.v_range, dv_range=self.dv_range, sampling_rate=self.sampling_rate, resistor_values=self.resistor_values, channel_map=self.channel_map, labels=self.labels) try: self.server_config.validate() self.device_config.validate() except ConfigurationError, ex: raise ConfigError('DAQ configuration: ' + ex.message) # Re-raise as a WA error
def validate(self): if not daq: raise ImportError(import_error_mesg) self._results = None self._metrics = set() if self.labels: if not (len(self.labels) == len(self.resistor_values)): # pylint: disable=superfluous-parens raise ConfigError( 'Number of DAQ port labels does not match the number of resistor values.' ) else: self.labels = [ 'PORT_{}'.format(i) for i, _ in enumerate(self.resistor_values) ] self.server_config = ServerConfiguration(host=self.server_host, port=self.server_port) self.device_config = DeviceConfiguration( device_id=self.device_id, v_range=self.v_range, dv_range=self.dv_range, sampling_rate=self.sampling_rate, resistor_values=self.resistor_values, channel_map=self.channel_map, labels=self.labels) try: self.server_config.validate() self.device_config.validate() except ConfigurationError, ex: raise ConfigError('DAQ configuration: ' + ex.message) # Re-raise as a WA error
def __init__( self, target, resistor_values, # pylint: disable=R0914 labels=None, host='localhost', port=45677, device_id='Dev1', v_range=2.5, dv_range=0.2, sample_rate_hz=10000, channel_map=(0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23), keep_raw=False, time_as_clock_boottime=True): # pylint: disable=no-member super(DaqInstrument, self).__init__(target) self.keep_raw = keep_raw self._need_reset = True self._raw_files = [] self.tempdir = None self.target_boottime_clock_at_start = 0.0 if DaqClient is None: raise HostError( 'Could not import "daqpower": {}'.format(import_error_mesg)) if labels is None: labels = ['PORT_{}'.format(i) for i in range(len(resistor_values))] if len(labels) != len(resistor_values): raise ValueError( '"labels" and "resistor_values" must be of the same length') self.daq_client = DaqClient(host, port) try: devices = self.daq_client.list_devices() if device_id not in devices: msg = 'Device "{}" is not found on the DAQ server. Available devices are: "{}"' raise ValueError(msg.format(device_id, ', '.join(devices))) except Exception as e: raise HostError('Problem querying DAQ server: {}'.format(e)) self.device_config = DeviceConfiguration( device_id=device_id, v_range=v_range, dv_range=dv_range, sampling_rate=sample_rate_hz, resistor_values=resistor_values, channel_map=channel_map, labels=labels) self.sample_rate_hz = sample_rate_hz self.time_as_clock_boottime = time_as_clock_boottime self.add_channel('Time', 'time') for label in labels: for kind in ['power', 'voltage']: self.add_channel(label, kind) if time_as_clock_boottime: host_path = os.path.join(PACKAGE_BIN_DIRECTORY, self.target.abi, 'get_clock_boottime') self.clock_boottime_cmd = self.target.install_if_needed( host_path, search_system_binaries=False)
def __init__( self, target, resistor_values, # pylint: disable=R0914 labels=None, host='localhost', port=45677, device_id='Dev1', v_range=2.5, dv_range=0.2, sample_rate_hz=10000, channel_map=(0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23), ): # pylint: disable=no-member super(DaqInstrument, self).__init__(target) self._need_reset = True self._raw_files = [] if execute_command is None: raise HostError( 'Could not import "daqpower": {}'.format(import_error_mesg)) if labels is None: labels = [ 'PORT_{}'.format(i) for i in xrange(len(resistor_values)) ] if len(labels) != len(resistor_values): raise ValueError( '"labels" and "resistor_values" must be of the same length') self.server_config = ServerConfiguration(host=host, port=port) result = self.execute('list_devices') if result.status == Status.OK: if device_id not in result.data: raise ValueError( 'Device "{}" is not found on the DAQ server.'.format( device_id)) elif result.status != Status.OKISH: raise HostError('Problem querying DAQ server: {}'.format( result.message)) self.device_config = DeviceConfiguration( device_id=device_id, v_range=v_range, dv_range=dv_range, sampling_rate=sample_rate_hz, resistor_values=resistor_values, channel_map=channel_map, labels=labels) self.sample_rate_hz = sample_rate_hz for label in labels: for kind in ['power', 'voltage']: self.add_channel(label, kind)
def configure(self, config_kwargs): """Configure the DAQ""" if self.runner: message = 'Configuring a new session before previous session has been terminated.' self.logger.warning(message) if self.runner.is_running: self.runner.stop() config = DeviceConfiguration(**config_kwargs) config.validate() self.output_directory = self._create_output_directory() self.labels = config.labels self.logger.info('Writing port files to %s', self.output_directory) self.opened_files = OpenFileTracker() self.runner = DaqRunner(config, self.output_directory)