def add_trigger_point(self, input_channel, affected_signal_bitmask, starts_low=False, edge_count=1): """This function programs a trigger point of the timing unit. A trigger point triggers one ore more of the signals programmed previously (!) with one of the commands: - :meth:`add_generated_tiggered_signal` - :meth:`add_directly_triggered_signal` When the trigger conditions programmed with this command are met the programmend output signals will react accordingly. :param input_channel: input trigger channel number (1-6: LEDs 1-6, 7-12: TTL 1-6) :param affected_signal_bitmask: bitmask for selecting affected output channels :param starts_low: select polarity of the input signal, defaults to False :param edge_count: number of input signal edges before trigger is issued, defaults to 1 """ input_channel = strict_discrete_range(input_channel, (1, 12), 1) edge_count = strict_range(edge_count, (1, 4294967295)) affected_signal_bitmask = strict_range( affected_signal_bitmask, (1, 4095)) self.dll( 'TU_AddTriggerPoint', c_uint8(input_channel), c_bool(starts_low), c_uint32(edge_count), c_int16(affected_signal_bitmask))
def buffer_frequency_time_series(self, channel, n_samples, sample_rate, trigger_source=None): """ Record a time series to the buffer and read it out after completion. :param channel: Channel that should be used :param n_samples: The number of samples :param sample_rate: Sample rate in Hz :param trigger_source: Optionally specify a trigger source to start the measurement """ if self.interpolator_autocalibrated: max_sample_rate = 125e3 else: max_sample_rate = 250e3 # Minimum sample rate is 1 sample in the maximum measurement time. sample_rate = strict_range(sample_rate, [1 / MAX_MEASUREMENT_TIME, max_sample_rate]) measurement_time = 1 / sample_rate self.clear() self.format = "ASCII" self.configure_frequency_array_measurement(n_samples, channel) self.continuous = False self.measurement_time = measurement_time if trigger_source: self.external_start_arming_source = trigger_source # start the measurement (or wait for trigger) self.write(":INIT")
def coefficients(self, values): values = [ strict_range(v, (self.coefficients_min[i], self.coefficients_max[i])) for i, v in enumerate(values) ] self.dll('setExtNtcParameter', c_double(values[0]), c_double(values[1]))
def wavelength(self, val): val = strict_range( val, (self.wavelength_min, self.wavelength_max)) if self.wavelength_settable: self.write("SENSE:CORR:WAV %g" % val) else: raise Exception( "Wavelength is not settable for %s" % self.sensor_name)
def brightness(self, led_brightness): led_brightness = tuple(int(x*10) for x in led_brightness) log.debug( '{0}: Set LED Brightnesses (0-1000) to {1}'.format( self.name, led_brightness)) self._set_LED_parameters( 'setLED_HeadBrightness', led_brightness, c_uint16, validator=lambda v: strict_range(v, (0, 1000)))
def range(self, value): if isinstance(value, str): value = value.upper() value = strict_discrete_set( value, ('MIN', 'MAX', 'min', 'max')) else: value = strict_range(value, (self.range_min, self.range_max)) value = "%g" % value self.write(self._cmd("RANGe %s" % value))
def reference(self, value): if isinstance(value, str): value = value.upper() value = strict_discrete_set( value, ('MIN', 'MAX', 'DEF', 'DEFAULT')) else: value = strict_range( value, (self.reference_min, self.reference_max)) value = "%g" % value self.write(self._cmd("REFerence %s" % value))
def pointer_validator(value, values): """ Provides a validator function that ensures the passed value is a tuple or a list with a length of 2 and passes every item through the strict_range validator. :param value: A value to test :param values: A range of values (passed to strict_range) :raises: TypeError if the value is not a tuple or a list :raises: IndexError if the value is not of length 2 """ if not isinstance(value, (list, tuple)): raise TypeError('{:g} is not a list or tuple'.format(value)) if not len(value) == 2: raise IndexError('{:g} is not of length 2'.format(value)) return tuple(strict_range(v, values) for v in value)
def _preset_min_max_values(self, property_name, value, default=True): """Allows to pass `'MIN'/'MAX'/'DEFAULT'` as value specification for a property. Checks if value is within range. Returns numerical value to pass to instrument. :param property_name: name of property :type property_name: str :param value: value to set :type value: str or numeric :return: numerical value """ if isinstance(value, str): allowed = ('min', 'max') if default: allowed += ('default', ) value = strict_discrete_set(value.lower(), allowed) value = getattr(self, '{}_{}'.format(property_name, value)) value = strict_range(value, (getattr(self, '{}_min'.format(property_name)), getattr(self, '{}_max'.format(property_name)))) return value
def acceleration_tau(self, tau): tau = strict_range( tau, (self.acceleration_tau_min, self.acceleration_tau_max)) self.dll('setAccelTau', c_double(tau))
def responsivity(self, responsivity): responsivity = strict_range( responsivity, (self.responsivity_min, self.responsivity_max)) self.dll('set{}Responsivity'.format(self.sensor), c_double(responsivity))
def wavelength(self, wavelength): wavelength = strict_range(wavelength, (self.wavelength_min, self.wavelength_max)) self.dll('setWavelength', c_double(wavelength))
def step_position(self, pos): strict_range(pos, (-8388607, 8388607)) self.write("P%i" % pos) self.write("G")
def LED_linear_mode(self, brightness): brightness = strict_range(brightness*10, (0, 1000)) self.dll('setLED_LinearModeValue', c_uint16(brightness))
def __init__(self, dll, channel_index, name): super().__init__(dll=dll) self.name = name channel_index = strict_range(channel_index, (1, 6)) self.channel = c_uint8(channel_index)
def test_strict_range(): assert strict_range(5, range(10)) == 5 assert strict_range(5.1, range(10)) == 5.1 with pytest.raises(ValueError): strict_range(20, range(10))
def SRQ_mask(self, value): mask_str = "M" + format(strict_range(value, [0, 63]), "2o") self.write(mask_str)
def test_strict_range(): assert strict_range(5, range(10)) == 5 assert strict_range(5.1, range(10)) == 5.1 with pytest.raises(ValueError) as e_info: strict_range(20, range(10))