예제 #1
0
    def discover_device(self):
        host = self.host_entry.get()
        port = self.get_port()
        timeout_ms = 5000

        try:
            # Release any previously created device
            if self.device_created:
                ul.release_daq_device(self.board_num)
                self.device_created = False

            descriptor = ul.get_net_device_descriptor(host, port, timeout_ms)
            if descriptor is not None:
                # Create the DAQ device from the descriptor
                ul.create_daq_device(self.board_num, descriptor)
                self.device_created = True

                self.status_label["text"] = "DAQ Device Discovered"
                self.flash_led_button["state"] = "normal"
                self.device_name_label["text"] = descriptor.product_name
                self.device_id_label["text"] = descriptor.unique_id
            else:
                self.status_label["text"] = "No Device Discovered"
                self.flash_led_button["state"] = "disabled"
                self.device_name_label["text"] = ""
                self.device_id_label["text"] = ""

        except ULError as e:
            self.status_label["text"] = "No Device Discovered"
            self.flash_led_button["state"] = "disabled"
            self.device_name_label["text"] = ""
            self.device_id_label["text"] = ""
            show_ul_error(e)
예제 #2
0
파일: ULDI03.py 프로젝트: jdechevr/mcculw
    def start_scan(self):
        rate = 100
        count = 1000

        # Allocate a buffer for the scan
        self.memhandle = ul.win_buf_alloc(count)

        # Check if the buffer was successfully allocated
        if not self.memhandle:
            messagebox.showerror("Error", "Failed to allocate memory")
            self.set_ui_idle_state()
            return

        try:
            # Configure the port (if necessary)
            if self.port.is_port_configurable:
                ul.d_config_port(self.board_num, self.port.type,
                                 DigitalIODirection.IN)

            # Run the scan
            ul.d_in_scan(self.board_num, self.port.type, count, rate,
                         self.memhandle, ScanOptions.BACKGROUND)
        except ULError as e:
            show_ul_error(e)
            self.set_ui_idle_state()
            return

        # Convert the memhandle to a ctypes array
        # Note: the ctypes array will no longer be valid after 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.
        self.ctypes_array = cast(self.memhandle, POINTER(c_ushort))

        # Start updating the displayed values
        self.update_displayed_values()
예제 #3
0
파일: ULTI02.py 프로젝트: jdechevr/mcculw
    def update_values(self):
        try:
            # Get the values from the device (optional parameters omitted)
            err_code, data_array = ul.t_in_scan(self.board_num, self.low_chan,
                                                self.high_chan,
                                                TempScale.CELSIUS)

            # Check err_code for OUTOFRANGE or OPENCONNECTION. All other
            # error codes will raise a ULError and are checked by the except
            # clause.
            if err_code == ErrorCode.OUTOFRANGE:
                self.warning_label["text"] = (
                    "A thermocouple input is out of range.")
            elif err_code == ErrorCode.OPENCONNECTION:
                self.warning_label["text"] = (
                    "A thermocouple input has an open connection.")
            else:
                self.warning_label["text"] = ""

            self.display_values(data_array)

            # Call this method again until the stop button is pressed (or an
            # error occurs)
            if self.running:
                self.after(100, self.update_values)
        except ULError as e:
            self.stop()
            show_ul_error(e)
예제 #4
0
    def start_scan(self):
        # Build the data array
        points_per_channel = 1000
        rate = 1000
        num_points = self.num_chans * points_per_channel
        scan_options = ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS
        ao_range = self.ao_info.supported_ranges[0]

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

        try:
            data_array = cast(self.memhandle, POINTER(c_ushort))
            freq = self.add_example_data(data_array, ao_range, rate,
                                         points_per_channel)
            self.freq_label["text"] = str(freq) + "Hz"

            ul.daq_out_scan(self.board_num, self.chan_list,
                            self.chan_type_list, self.gain_list,
                            self.num_chans, rate, num_points, self.memhandle,
                            scan_options)

            # Start updating the displayed values
            self.update_displayed_values()
        except ULError as e:
            show_ul_error(e)
            self.set_ui_idle_state()
            return
예제 #5
0
파일: ULDO02.py 프로젝트: jdechevr/mcculw
 def exit(self):
     # Set the port to 0 at exit
     try:
         ul.d_out(self.board_num, self.port.type, 0)
     except ULError as e:
         show_ul_error(e)
     self.master.destroy()
예제 #6
0
파일: VIn01.py 프로젝트: jdechevr/mcculw
    def update_value(self):
        channel = self.get_channel_num()
        ai_range = self.get_range()

        try:
            # Get a value from the device
            if self.ai_info.resolution <= 16:
                # Use the v_in method for devices with a resolution <= 16
                # (optional parameter omitted)
                value = ul.v_in(self.board_num, channel, ai_range)
            else:
                # Use the v_in_32 method for devices with a resolution > 16
                # (optional parameter omitted)
                value = ul.v_in_32(self.board_num, channel, ai_range)

            # Display the raw value
            self.value_label["text"] = '{:.3f}'.format(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()
            show_ul_error(e)
예제 #7
0
    def update_value(self):
        channel = self.get_channel_num()
        ai_range = self.ai_info.supported_ranges[0]

        try:
            # Get a value from the device
            if self.ai_info.resolution <= 16:
                # Use the a_in method for devices with a resolution <= 16
                value = ul.a_in(self.board_num, channel, ai_range)
                # Convert the raw value to engineering units
                eng_units_value = ul.to_eng_units(self.board_num, ai_range,
                                                  value)
            else:
                # Use the a_in_32 method for devices with a resolution > 16
                # (optional parameter omitted)
                value = ul.a_in_32(self.board_num, channel, ai_range)
                # Convert the raw value to engineering units
                eng_units_value = ul.to_eng_units_32(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()
            show_ul_error(e)
예제 #8
0
파일: ULDO01.py 프로젝트: jdechevr/mcculw
 def data_value_changed(self, *args):
     try:
         # Get the data value
         data_value = self.get_data_value()
         # Send the value to the device
         ul.d_out(self.board_num, self.port.type, data_value)
     except ULError as e:
         show_ul_error(e)
예제 #9
0
파일: ULDO02.py 프로젝트: jdechevr/mcculw
 def bit_checkbutton_changed(self, bit_num):
     try:
         # Get the value from the checkbutton
         bit_value = self.bit_checkbutton_vars[bit_num].get()
         # Output the value to the board
         ul.d_bit_out(self.board_num, self.port.type, bit_num, bit_value)
     except ULError as e:
         show_ul_error(e)
예제 #10
0
 def exit(self):
     # Stop all the timers at exit
     if self.first_chan_num != -1:
         for chan_num in range(self.first_chan_num, self.last_chan_num + 1):
             try:
                 ul.timer_out_stop(self.board_num, chan_num)
             except ULError as e:
                 show_ul_error(e)
     self.master.destroy()
예제 #11
0
    def update_value(self):
        channel = self.get_channel_num()
        ao_range = self.ao_info.supported_ranges[0]
        data_value = self.get_data_value()

        try:
            # Send the value to the device (optional parameter omitted)
            ul.v_out(self.board_num, channel, ao_range, data_value)
        except ULError as e:
            show_ul_error(e)
예제 #12
0
    def start_scan(self):
        rate = 100
        points_per_channel = 10
        total_count = points_per_channel * self.num_chans

        # Allocate a buffer for the scan
        memhandle = ul.win_buf_alloc(total_count)

        # 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:
            # Configure the digital port for input
            ul.d_config_port(self.board_num, DigitalPortType.FIRSTPORTA,
                             DigitalIODirection.IN)

            # Configure the counter channel
            ul.c_config_scan(self.board_num, 0, CounterMode.STOP_AT_MAX,
                             CounterDebounceTime.DEBOUNCE_NONE, 0,
                             CounterEdgeDetection.RISING_EDGE,
                             CounterTickSize.TICK20PT83ns, 0)

            # Run the scan
            ul.daq_in_scan(self.board_num, self.chan_list, self.chan_type_list,
                           self.gain_list, self.num_chans, rate, 0,
                           total_count, memhandle, 0)

            # Convert the TC values (optional parameter omitted)
            err, temp_data_array = ul.get_tc_values(self.board_num,
                                                    self.chan_list,
                                                    self.chan_type_list,
                                                    self.num_chans, memhandle,
                                                    0, points_per_channel,
                                                    TempScale.CELSIUS)

            if err == ErrorCode.OUTOFRANGE:
                messagebox.showwarning("Warning",
                                       "Temperature data is out of range")

            # Cast the memhandle to a ctypes pointer
            # Note: the ctypes array will only be valid until win_buf_free
            # is called.
            array = cast(memhandle, POINTER(c_ushort))

            # Display the values
            self.display_values(array, temp_data_array, total_count)
        except ULError as e:
            show_ul_error(e)
        finally:
            # Free the allocated memory
            ul.win_buf_free(memhandle)
            self.start_button["state"] = tk.NORMAL
예제 #13
0
    def scan_loop(self):
        rate = 100
        points_per_channel = 10
        low_chan = 0  # Ignored by a_in_scan when queue is enabled
        high_chan = 3  # Ignored by a_in_scan when queue is enabled
        num_channels = high_chan - low_chan + 1
        total_count = points_per_channel * num_channels

        # Ignored by a_in_scan when queue is enabled
        range_ = self.ai_info.supported_ranges[0]

        # Allocate a buffer for the scan
        if self.ai_info.resolution <= 16:
            # Use the win_buf_alloc method for devices with a resolution <= 16
            memhandle = ul.win_buf_alloc(total_count)
        else:
            # Use the win_buf_alloc_32 method for devices with a resolution >
            # 16
            memhandle = ul.win_buf_alloc_32(total_count)

        # Check if the buffer was successfully allocated
        if not memhandle:
            messagebox.showerror("Error", "Failed to allocate memory")
            return

        try:
            # Run the scan
            ul.a_in_scan(self.board_num, low_chan, high_chan, 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
            # or win_buf_to_array_32 before the memory is freed. The copy can
            # be used at any time.
            if self.ai_info.resolution <= 16:
                # Use the memhandle_as_ctypes_array method for devices with a
                # resolution <= 16
                array = cast(memhandle, POINTER(c_ushort))
            else:
                # Use the memhandle_as_ctypes_array_32 method for devices with
                # a resolution > 16
                array = cast(memhandle, POINTER(c_ulong))

            # Display the values
            self.display_values(array, total_count)

            self.after(1000, self.scan_loop)
        except ULError as e:
            show_ul_error(e)
        finally:
            # Free the allocated memory
            ul.win_buf_free(memhandle)
예제 #14
0
파일: ULAO01.py 프로젝트: jdechevr/mcculw
    def update_value(self):
        channel = self.get_channel_num()
        ao_range = self.ao_info.supported_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:
            show_ul_error(e)
예제 #15
0
    def update_output(self):
        try:
            timer_num = self.get_channel_num()
            frequency = self.get_frequency()

            actual_freq = ul.timer_out_start(self.board_num, timer_num,
                                             frequency)

            self.update_actual_values(actual_freq)
        except ULError as e:
            show_ul_error(e)
예제 #16
0
    def err_code_changed(self, *args):
        try:
            err_code = int(self.err_code_variable.get())
        except ValueError:
            err_code = 0

        try:
            message = ul.get_err_msg(err_code)

            self.err_msg_label["text"] = message
        except ULError as e:
            show_ul_error(e)
예제 #17
0
    def update_output(self):
        try:
            timer_num = self.get_channel_num()
            frequency = self.get_frequency()
            duty_cycle = self.get_duty_cycle()

            # Start the pulse output (optional parameters omitted)
            actual_freq, actual_duty_cycle, _ = ul.pulse_out_start(
                self.board_num, timer_num, frequency, duty_cycle)

            self.update_actual_values(actual_freq, actual_duty_cycle)
        except ULError as e:
            show_ul_error(e)
예제 #18
0
    def start(self):
        self.running = True
        self.start_button["command"] = self.stop
        self.start_button["text"] = "Stop"

        try:
            # Clear the counter
            ul.c_clear(self.board_num, self.get_channel_num())
            # Start updating the counter values
            self.update_value()
        except ULError as e:
            self.stop()
            show_ul_error(e)
예제 #19
0
    def start_output_scan(self):
        # Build the data array
        self.output_low_chan = self.get_output_low_channel_num()
        self.output_high_chan = self.get_output_high_channel_num()
        self.num_output_chans = (
            self.output_high_chan - self.output_low_chan + 1)

        if self.output_low_chan > self.output_high_chan:
            messagebox.showerror(
                "Error",
                "Low Channel Number must be greater than or equal to High "
                "Channel Number")
            self.set_output_ui_idle_state()
            return

        points_per_channel = 1000
        rate = 1000
        num_points = self.num_output_chans * points_per_channel
        scan_options = (ScanOptions.BACKGROUND |
                        ScanOptions.CONTINUOUS | ScanOptions.SCALEDATA)
        ao_range = self.ao_info.supported_ranges[0]

        self.output_memhandle = ul.scaled_win_buf_alloc(num_points)

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

        try:
            data_array = cast(self.output_memhandle, POINTER(c_double))
            frequencies = self.add_output_example_data(
                data_array, ao_range, self.num_output_chans, rate,
                points_per_channel)

            self.recreate_freq_frame()
            self.display_output_signal_info(frequencies)

            ul.a_out_scan(
                self.board_num, self.output_low_chan, self.output_high_chan,
                num_points, rate, ao_range, self.output_memhandle,
                scan_options)

            # Start updating the displayed values
            self.update_output_displayed_values()
        except ULError as e:
            show_ul_error(e)
            self.set_output_ui_idle_state()
            return
예제 #20
0
파일: ULDI06.py 프로젝트: jdechevr/mcculw
    def start(self):
        self.running = True
        self.start_button["command"] = self.stop
        self.start_button["text"] = "Stop"

        try:
            ul.d_config_bit(self.board_num, self.port.type,
                            self.port.first_bit, DigitalIODirection.IN)
        except ULError as e:
            self.stop()
            show_ul_error(e)
            return

        self.update_value()
예제 #21
0
    def start_scan(self):
        rate = 100
        points_per_channel = 100
        total_count = points_per_channel * self.num_chans
        scan_options = (ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS
                        | ScanOptions.EXTTRIGGER)

        # Allocate a buffer for the scan
        self.memhandle = ul.win_buf_alloc(total_count)

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

        try:
            # Set the start trigger settings
            ul.daq_set_trigger(self.board_num, TriggerSource.ANALOG_SW,
                               TriggerSensitivity.RISING_EDGE,
                               self.chan_list[0], self.chan_type_list[0],
                               self.gain_list[0], 2, 0, TriggerEvent.START)

            # Set the stop trigger settings
            ul.daq_set_trigger(self.board_num, TriggerSource.COUNTER,
                               TriggerSensitivity.ABOVE_LEVEL,
                               self.chan_list[2], self.chan_type_list[2],
                               self.gain_list[2], 2, 0, TriggerEvent.START)

            # Run the scan
            ul.daq_in_scan(self.board_num, self.chan_list, self.chan_type_list,
                           self.gain_list, self.num_chans, rate, 0,
                           total_count, self.memhandle, scan_options)

            # Cast the memhandle to a ctypes pointer
            # 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.
            self.array = cast(self.memhandle, POINTER(c_ushort))
        except ULError as e:
            # Free the allocated memory
            ul.win_buf_free(self.memhandle)
            show_ul_error(e)
            return

        # Start updating the displayed values
        self.update_displayed_values()
예제 #22
0
파일: ULAI15.py 프로젝트: jdechevr/mcculw
    def start_scan(self):
        low_chan = self.get_low_channel_num()
        high_chan = self.get_high_channel_num()

        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

        range_ = self.ai_info.supported_ranges[0]

        # Allocate a buffer for the scan
        memhandle = ul.scaled_win_buf_alloc(total_count)

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

        # 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 scaled_win_buf_to_array
        # before the memory is freed. The copy can be used at any time.
        array = cast(memhandle, POINTER(c_double))

        try:
            # Run the scan
            ul.a_in_scan(self.board_num, low_chan, high_chan, total_count,
                         rate, range_, memhandle, ScanOptions.SCALEDATA)

            # Display the values
            self.display_values(array, total_count, low_chan, high_chan)
        except ULError as e:
            show_ul_error(e)
        finally:
            # Free the allocated memory
            ul.win_buf_free(memhandle)
            self.start_button["state"] = tk.NORMAL
예제 #23
0
파일: ULDI06.py 프로젝트: jdechevr/mcculw
    def update_value(self):
        try:
            # Get a value from the device
            value = ul.d_bit_in(self.board_num, self.port.type,
                                self.port.first_bit)

            # Display the value
            self.value_label["text"] = str(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()
            show_ul_error(e)
예제 #24
0
    def start_scan(self):
        rate = 100
        total_count = 10

        # Allocate a buffer for the scan
        memhandle = ul.win_buf_alloc_32(total_count)

        # 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:
            mode = CounterMode.ENCODER + CounterMode.ENCODER_MODE_X1 \
                + CounterMode.ENCODER_MODE_CLEAR_ON_Z_ON
            debounce_time = CounterDebounceTime.DEBOUNCE_NONE
            debounce_mode = 0
            edge_detection = CounterEdgeDetection.RISING_EDGE
            tick_size = CounterTickSize.TICK20PT83ns
            mapped_channel = 2

            # Configure the first counter channel for Encoder mode
            ul.c_config_scan(self.board_num, self.chan_num, mode,
                             debounce_time, debounce_mode, edge_detection,
                             tick_size, mapped_channel)

            # Run the scan
            ul.c_in_scan(self.board_num, self.chan_num, self.chan_num,
                         total_count, rate, 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_32
            # before the memory is freed. The copy can be used at any time.
            array = cast(memhandle, POINTER(c_ulong))

            # Display the values
            self.display_values(array, total_count)
        except ULError as e:
            show_ul_error(e)
        finally:
            # Free the allocated memory
            ul.win_buf_free(memhandle)
            self.start_button["state"] = tk.NORMAL
예제 #25
0
    def start_scan(self):
        rate = 100
        points_per_channel = 100
        total_count = points_per_channel * self.num_chans
        scan_options = ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS

        # Allocate a buffer for the scan
        if self.resolution <= 16:
            self.memhandle = ul.win_buf_alloc(total_count)
        else:
            self.memhandle = ul.win_buf_alloc_32(total_count)

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

        try:
            # Run the scan
            ul.daq_in_scan(self.board_num, self.chan_list, self.chan_type_list,
                           self.gain_list, self.num_chans, rate, 0, total_count,
                           self.memhandle, scan_options)

            # Cast the memhandle to a ctypes pointer
            # 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
            # or win_buf_to_array_32 before the memory is freed. The copy can
            # be used at any time.
            if self.resolution <= 16:
                # Use the memhandle_as_ctypes_array method for devices with a
                # resolution <= 16
                self.array = cast(self.memhandle, POINTER(c_ushort))
            else:
                # Use the memhandle_as_ctypes_array_32 method for devices with a
                # resolution > 16
                self.array = cast(self.memhandle, POINTER(c_ulong))
        except ULError as e:
            # Free the allocated memory
            ul.win_buf_free(self.memhandle)
            show_ul_error(e)
            return

        # Start updating the displayed values
        self.update_displayed_values()
예제 #26
0
파일: ULTI01.py 프로젝트: jdechevr/mcculw
    def update_value(self):
        channel = self.get_channel_num()

        try:
            # Get a value from the device
            value = ul.t_in(self.board_num, channel, TempScale.CELSIUS)

            # Display the raw value
            self.value_label["text"] = '{:.3f}'.format(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()
            show_ul_error(e)
예제 #27
0
    def update_value(self):
        channel = self.get_channel_num()

        try:
            # Get a value from the device
            value = ul.c_in_32(self.board_num, channel)

            # Display the value
            self.value_label["text"] = str(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()
            show_ul_error(e)
예제 #28
0
    def update_value(self):
        try:
            # Display the bit values
            first_bit = self.port.first_bit
            for bit_num in range(first_bit,
                                 first_bit + min(self.port.num_bits, 8)):
                # Get a value from the device
                value = ul.d_bit_in(self.board_num, self.port.type, bit_num)

                # Display it
                self.bit_value_labels[bit_num]["text"] = str(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()
            show_ul_error(e)
예제 #29
0
    def start_scan(self):
        rate = 100
        points_per_channel = 100
        total_count = points_per_channel * self.num_chans
        scan_options = ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS

        # Allocate a buffer for the scan
        self.memhandle = ul.win_buf_alloc(total_count)

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

        try:
            # Configure the setpoints
            ul.daq_set_setpoints(self.board_num, self.limit_a_list,
                                 self.limit_b_list, self.setpoint_flags_list,
                                 self.setpoint_output_list, self.output_1_list,
                                 self.output_2_list, self.output_mask_1_list,
                                 self.output_mask_2_list, self.setpoint_count)

            # Run the scan
            ul.daq_in_scan(self.board_num, self.chan_list, self.chan_type_list,
                           self.gain_list, self.num_chans, rate, 0,
                           total_count, self.memhandle, scan_options)

            # Cast the memhandle to a ctypes pointer
            # 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.
            self.array = cast(self.memhandle, POINTER(c_ushort))
        except ULError as e:
            # Free the allocated memory
            ul.win_buf_free(self.memhandle)
            show_ul_error(e)
            return

        # Start updating the displayed values
        self.update_displayed_values()
예제 #30
0
    def start_scan(self):
        rate = 390
        total_count = 100

        # Allocate a buffer for the scan
        memhandle = ul.win_buf_alloc_32(total_count)

        # 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:
            # Configure the counter
            ul.c_config_scan(
                self.board_num, self.chan_num, CounterMode.DECREMENT_ON,
                CounterDebounceTime.DEBOUNCE_NONE, 0,
                CounterEdgeDetection.FALLING_EDGE,
                CounterTickSize.TICK20PT83ns, 1)

            # Run the scan
            ul.c_in_scan(
                self.board_num, self.chan_num, self.chan_num, total_count,
                rate, 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_32
            # before the memory is freed. The copy can be used at any time.
            array = cast(memhandle, POINTER(c_ulong))

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