示例#1
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 = self.memhandle_as_ctypes_array(memhandle)

            # Display the values
            self.display_values(array, temp_data_array, total_count)
        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
示例#2
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 = self.memhandle_as_ctypes_array_32(memhandle)

            # Display the values
            self.display_values(array, total_count)
        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
示例#3
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