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 = 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
评论列表
文章目录