コード例 #1
0
ファイル: ULAI14.py プロジェクト: conandewitt/lotus
    def get_threshold_counts(self, ai_range, low_threshold_volts,
                             high_threshold_volts):
        if self.ai_props.analog_trig_resolution == 0:
            # If the trigger resolution from AnalogInputProps is 0,
            # the resolution of the trigger is the same as the
            # analog input resolution, and we can use from_eng_units
            # to convert from engineering units to count
            low_threshold = ul.from_eng_units(self.board_num, ai_range,
                                              low_threshold_volts)
            high_threshold = ul.from_eng_units(self.board_num, ai_range,
                                               high_threshold_volts)
        else:
            # Otherwise, the resolution of the triggers are different
            # from the analog input, and we must convert from engineering
            # units to count manually

            trig_range = self.ai_props.analog_trig_range
            if trig_range == ULRange.UNKNOWN:
                # If the analog_trig_range is UNKNOWN, the trigger voltage
                # range is the same as the analog input.
                trig_range = ai_range

            low_threshold = self.volts_to_count(
                low_threshold_volts, self.ai_props.analog_trig_resolution,
                trig_range)
            high_threshold = self.volts_to_count(
                high_threshold_volts, self.ai_props.analog_trig_resolution,
                trig_range)

        return low_threshold, high_threshold
コード例 #2
0
def add_example_data(board_num, data_array, ao_range, num_chans, rate,
                     points_per_channel):
    # Calculate frequencies that will work well with the size of the array
    frequencies = []
    for channel_num in range(num_chans):
        frequencies.append(
            (channel_num + 1) / (points_per_channel / rate) * 10)

    # Calculate an amplitude and y-offset for the signal
    # to fill the analog output range
    amplitude = (ao_range.range_max - ao_range.range_min) / 2
    y_offset = (amplitude + ao_range.range_min) / 2

    # Fill the array with sine wave data at the calculated frequencies.
    # Note that since we are using the SCALEDATA option, the values
    # added to data_array are the actual voltage values that the device
    # will output
    data_index = 0
    for point_num in range(points_per_channel):
        for channel_num in range(num_chans):
            freq = frequencies[channel_num]
            value = amplitude * math.sin(
                2 * math.pi * freq * point_num / rate) + y_offset
            raw_value = ul.from_eng_units(board_num, ao_range, value)
            data_array[data_index] = raw_value
            data_index += 1

    return frequencies
コード例 #3
0
ファイル: ULAI07.py プロジェクト: cullenmq/shearTest
    def update_value(self):
        channel = self.get_channel_num()
        ai_range = self.ai_props.available_ranges[0]

        try:
            gain = self.ai_props.available_ranges[0]
            trig_type = self.get_trigger_type()
            trig_value_eng = self.get_trigger_level()
            trig_value = ul.from_eng_units(self.board_num, gain,
                                           trig_value_eng)

            # Get a value from the device
            value = ul.a_trig(self.board_num, channel, trig_type, trig_value,
                              gain)
            # Convert the raw value to engineering units
            eng_units_value = ul.to_eng_units(self.board_num, ai_range, value)

            # Display the raw value
            self.value_label["text"] = str(value)
            # Display the engineering value
            self.eng_value_label["text"] = '{:.3f}'.format(eng_units_value)

            # Call this method again until the stop button is pressed (or an
            # error occurs)
            if self.running:
                self.after(100, self.update_value)
        except ULError as e:
            self.stop()
            self.show_ul_error(e)
コード例 #4
0
ファイル: DaqOutScan01.py プロジェクト: conandewitt/lotus
    def add_example_data(self, data_array, ao_range, rate, points_per_channel):
        # Calculate a frequency that will work well with the size of the array
        freq = rate / points_per_channel

        # Calculate an amplitude and y-offset for the signal
        # to fill the analog output range
        amplitude = (ao_range.range_max - ao_range.range_min) / 2
        y_offset = (amplitude + ao_range.range_min) / 2

        # Fill the array with sine wave data for the analog channel, and square wave data for all bits
        # on the digital port.
        data_index = 0
        for point_num in range(0, points_per_channel):
            # Generate a value in volts for output from the analog channel
            value_volts = amplitude * math.sin(
                2 * math.pi * freq * point_num / rate) + y_offset
            # Convert the volts to counts
            value_count = ul.from_eng_units(self.board_num, ao_range,
                                            value_volts)
            data_array[data_index] = value_count
            data_index += 1

            # Generate a value for output from the digital port
            if point_num < points_per_channel / 2:
                data_array[data_index] = 0
            else:
                data_array[data_index] = 0xFFFF
            data_index += 1

        return freq
コード例 #5
0
    def update_arena_output(self):
        channel = self.get_channel_num()
        ao_range = self.ao_props.available_ranges[0]
        data_value = self.get_speed()

        if self.tempo is not None:
            ULAIO01.output_value = ul.from_eng_units(self.board_num, ao_range,
                                                     self.tempo)
        else:
            ULAIO01.output_value = ul.from_eng_units(self.board_num, ao_range,
                                                     data_value)
            print(ULAIO01.output_value)

        try:
            ul.a_out(self.board_num, channel, ao_range, ULAIO01.output_value)
        except ULError as e:
            self.show_ul_error(e)
コード例 #6
0
 def set_analog_out(self, value: float):
     board_num = self.device.board_num
     ul_range = self.device.ao_range
     convert = lambda value: ul.from_eng_units(
         board_num=board_num, ul_range=ul_range, eng_units_value=value)
     ul.a_out(board_num=board_num,
              ul_range=ul_range,
              channel=self.channel_idx,
              data_value=convert(value))
コード例 #7
0
    def update_value(self):
        channel = self.get_channel_num()
        ao_range = self.ao_props.available_ranges[0]
        data_value = self.get_data_value()

        raw_value = ul.from_eng_units(self.board_num, ao_range, data_value)

        try:
            ul.a_out(self.board_num, channel, ao_range, raw_value)
        except ULError as e:
            self.show_ul_error(e)
コード例 #8
0
    def analog_out(self, generator: gen.SignalGenerator, sample_range: range):
        # Local variables to reduce dereferences in loop:
        board_num = self.device.board_num
        ul_range = self.device.ao_range
        convert = lambda value: ul.from_eng_units(
            board_num=board_num, ul_range=ul_range, eng_units_value=value)
        a_out = ul.a_out

        for value in generator.samples(sample_range):
            a_out(board_num=board_num,
                  ul_range=ul_range,
                  channel=self.channel_idx,
                  data_value=convert(value))
コード例 #9
0
ファイル: ULAI07.py プロジェクト: jdechevr/mcculw
    def update_value(self):
        channel = self.get_channel_num()
        ai_range = self.ai_info.supported_ranges[0]

        try:
            gain = self.ai_info.supported_ranges[0]
            trig_type = self.get_trigger_type()
            trig_value_eng = self.get_trigger_level()
            trig_value = ul.from_eng_units(self.board_num, gain,
                                           trig_value_eng)

            # Get a value from the device
            value = ul.a_trig(self.board_num, channel, trig_type, trig_value,
                              gain)
            # Convert the raw value to engineering units
            eng_units_value = ul.to_eng_units(self.board_num, ai_range, value)

            # Display the raw value
            self.value_label["text"] = str(value)
            # Display the engineering value
            self.eng_value_label["text"] = '{:.3f}'.format(eng_units_value)
        except ULError as e:
            self.stop()
            show_ul_error(e)
コード例 #10
0
    def start_scan(self):
        range_ = self.ai_props.available_ranges[0]

        low_chan = self.get_low_channel_num()
        high_chan = self.get_high_channel_num()
        trig_type = self.get_trigger_type()
        trig_value_eng = self.get_trigger_level()
        trig_value = ul.from_eng_units(
            self.board_num, range_, trig_value_eng)

        if low_chan > high_chan:
            messagebox.showerror(
                "Error",
                "Low Channel Number must be greater than or equal to High "
                "Channel Number")
            self.start_button["state"] = tk.NORMAL
            return

        rate = 100
        points_per_channel = 10
        num_channels = high_chan - low_chan + 1
        total_count = points_per_channel * num_channels
        pretrig_points_per_channel = 5
        total_pretrig_count = pretrig_points_per_channel * num_channels

        # Allocate a buffer for the scan
        if self.ai_props.resolution <= 16:
            # Use the win_buf_alloc method for devices with a resolution <=
            # 16
            memhandle = ul.win_buf_alloc(total_count)
        else:
            messagebox.showerror(
                "Error",
                "This example can only be used with boards with a "
                "resolution less than or equal to 16.")
            self.start_button["state"] = tk.NORMAL
            return

        # Check if the buffer was successfully allocated
        if not memhandle:
            messagebox.showerror("Error", "Failed to allocate memory")
            self.start_button["state"] = tk.NORMAL
            return

        try:
            # Set the trigger settings (the level will be used for
            # both thresholds, since the irrelevant threshold is ignored
            # for TRIG_ABOVE and TRIG_BELOW
            ul.set_trigger(
                self.board_num, trig_type, trig_value, trig_value)

            # Run the scan
            ul.a_pretrig(
                self.board_num, low_chan, high_chan, total_pretrig_count,
                total_count, rate, range_, memhandle, 0)

            # Convert the memhandle to a ctypes array
            # Note: the ctypes array will only be valid until win_buf_free
            # is called.
            # A copy of the buffer can be created using win_buf_to_array
            # before the memory is freed. The copy can be used at any time.
            array = self.memhandle_as_ctypes_array(memhandle)

            # Display the values
            self.display_values(array, range_, total_count,
                                low_chan, high_chan)
        except ULError as e:
            self.show_ul_error(e)
        finally:
            # Free the allocated memory
            ul.win_buf_free(memhandle)
            self.start_button["state"] = tk.NORMAL