def __init__(self, master=None): super(ULAI15, self).__init__(master) self.board_num = 0 self.ai_props = AnalogInputProps(self.board_num) self.create_widgets()
def run_example(): board_num = 0 if use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(board_num): print("Could not find device.") return channel = 0 ai_props = AnalogInputProps(board_num) if ai_props.num_ti_chans < 1: util.print_unsupported_example(board_num) return try: # Get the value from the device (optional parameters omitted) value = ul.t_in(board_num, channel, TempScale.CELSIUS) # Display the value print("Channel " + str(channel) + " Value (deg C): " + str(value)) except ULError as e: util.print_ul_error(e) finally: if use_device_detection: ul.release_daq_device(board_num)
def __init__(self, master=None): super(ULAI06, self).__init__(master) self.board_num = 0 self.ai_props = AnalogInputProps(self.board_num) # Initialize tkinter self.create_widgets()
def __init__(self, master): super(ULAI01, self).__init__(master) self.board_num = 0 self.ai_props = AnalogInputProps(self.board_num) self.running = False self.create_widgets()
def __init__(self, master=None): super(DaqInScan03, self).__init__(master) self.board_num = 0 self.daqi_props = DaqInputProps(self.board_num) self.ai_props = AnalogInputProps(self.board_num) if self.daqi_props.is_supported and self.ai_props.num_ti_chans > 1: self.init_scan_channel_info() self.create_widgets()
def __init__(self, master=None): super(DaqInScan01, self).__init__(master) self.board_num = 0 self.daqi_props = DaqInputProps(self.board_num) self.ai_props = AnalogInputProps(self.board_num) self.digital_props = DigitalProps(self.board_num) self.counter_props = CounterProps(self.board_num) self.init_scan_channel_info() self.create_widgets()
def __init__(self, master=None): super(ULAI10, self).__init__(master) self.board_num = 0 self.ai_props = AnalogInputProps(self.board_num) self.num_elements = 4 self.queue_loaded = False self.create_widgets() if self.ai_props.num_ai_chans > 0: self.scan_loop()
def __init__(self, master=None): super(ULAIO01, self).__init__(master) self.period = 1 self.period_switch = [] self.tempo = None # for arena output self.board_num = 0 self.ai_props = AnalogInputProps(self.board_num) self.ao_props = AnalogOutputProps(self.board_num) # Initialize tkinter self.create_widgets()
def __init__(self, master=None): super(DaqSetSetpoints01, self).__init__(master) self.board_num = 0 self.daqi_props = DaqInputProps(self.board_num) example_supported = (self.daqi_props.is_supported and self.daqi_props.supports_setpoints) if example_supported: self.ai_props = AnalogInputProps(self.board_num) self.digital_props = DigitalProps(self.board_num) self.counter_props = CounterProps(self.board_num) self.init_scan_channel_info() self.init_setpoints() self.create_widgets()
def __init__(self, use_device_detection=True): self.use_device_detection = use_device_detection self.board_num = 0 # board initially uninitalized self.Init = False if use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(self.board_num): print("Could not find device.") return self.channel = 0 ai_props = AnalogInputProps(self.board_num) if ai_props.num_ti_chans < 1: util.print_unsupported_example(self.board_num) return #if we made it this far, we gucci self.isInit = True return
def run_example(): board_num = 0 if use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(board_num): print("Could not find device.") return channel = 0 ai_props = AnalogInputProps(board_num) if ai_props.num_ai_chans < 1: util.print_unsupported_example(board_num) return ai_range = ai_props.available_ranges[0] try: # Get a value from the device if ai_props.resolution <= 16: # Use the a_in method for devices with a resolution <= 16 value = ul.a_in(board_num, channel, ai_range) # Convert the raw value to engineering units eng_units_value = ul.to_eng_units(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(board_num, channel, ai_range) # Convert the raw value to engineering units eng_units_value = ul.to_eng_units_32(board_num, ai_range, value) # Display the raw value print("Raw Value: " + str(value)) # Display the engineering value print("Engineering Value: " + '{:.3f}'.format(eng_units_value)) except ULError as e: util.print_ul_error(e) finally: if use_device_detection: ul.release_daq_device(board_num)
def __init__(self, biprange, srate): super(DaqThread, self).__init__() # QObject.__init__(self) self.biprange = biprange # self.mutex = QMutex() self.rate = srate self.chunksize = 1024 # int(self.rate/1000) self.board_num = 1 self.file_ls = [] self.chunk_ls = [] self.chunk_np = np.zeros(self.chunksize) ######## # The size of the UL buffer to create, in seconds buffer_size_seconds = 15 # The number of buffers to write num_buffers_to_write = 8 # VER si eliminar o dejar para que confirme si recibe el device y # lo libere al final, esta bueno para no tener que abrir instacal self.use_device_detection = False # Cambiar a True en version final if self.use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(self.board_num): QtGui.QMessageBox.information( self, "Connect device", "Could not find device") # check message box return ai_props = AnalogInputProps(self.board_num) # In case more channels are added in the future self.low_chan = 0 self.high_chan = 0 num_chans = self.high_chan - self.low_chan + 1 # Create a circular buffer that can hold buffer_size_seconds worth of # data, or at least 10 points (this may need to be adjusted to prevent # a buffer overrun) points_per_channel = max(self.rate * buffer_size_seconds, 10) # Some hardware requires that the total_count is an integer multiple # of the packet size. For this case, calculate a points_per_channel # that is equal to or just above the points_per_channel selected # which matches that requirement. if ai_props.continuous_requires_packet_size_multiple: packet_size = ai_props.packet_size remainder = points_per_channel % packet_size if remainder != 0: points_per_channel += packet_size - remainder # In case more channels are added in the future self.ul_buffer_count = points_per_channel * num_chans # Pick range from settings Combobox self.ai_range = ai_props.available_ranges[self.biprange] # Write the UL buffer to the file num_buffers_to_write times self.points_to_write = self.ul_buffer_count * num_buffers_to_write # # When handling the buffer, we will read 1/10 of the buffer at a time self.write_chunk_size = self.chunksize # int(self.ul_buffer_count / 10) self.scan_options = (ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS) self.memhandle = ul.win_buf_alloc(self.ul_buffer_count) # Allocate an array of doubles temporary storage of the data self.write_chunk_array = (c_ushort * self.write_chunk_size)() # Check if the buffer was successfully allocated if not self.memhandle: QtGui.QMessageBox.critical(self, "No Buffer", "Failed to allocate memory.") print("No Buffer") ul.stop_background(self.board_num, FunctionType.AIFUNCTION) return
def run_example(): board_num = 0 rate = 100 points_per_channel = 1000 if use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(board_num): print("Could not find device.") return ai_props = AnalogInputProps(board_num) if ai_props.num_ai_chans < 1: util.print_unsupported_example(board_num) return low_chan = 0 high_chan = min(3, ai_props.num_ai_chans - 1) num_chans = high_chan - low_chan + 1 total_count = points_per_channel * num_chans ai_range = ai_props.available_ranges[0] scan_options = ScanOptions.BACKGROUND if ScanOptions.SCALEDATA in ai_props.supported_scan_options: # If the hardware supports the SCALEDATA option, it is easiest to # use it. scan_options |= ScanOptions.SCALEDATA memhandle = ul.scaled_win_buf_alloc(total_count) # Convert the memhandle to a ctypes array. # Use the memhandle_as_ctypes_array_scaled method for scaled # buffers. ctypes_array = util.memhandle_as_ctypes_array_scaled(memhandle) elif ai_props.resolution <= 16: # Use the win_buf_alloc method for devices with a resolution <= 16 memhandle = ul.win_buf_alloc(total_count) # Convert the memhandle to a ctypes array. # Use the memhandle_as_ctypes_array method for devices with a # resolution <= 16. ctypes_array = util.memhandle_as_ctypes_array(memhandle) else: # Use the win_buf_alloc_32 method for devices with a resolution > 16 memhandle = ul.win_buf_alloc_32(total_count) # Convert the memhandle to a ctypes array. # Use the memhandle_as_ctypes_array_32 method for devices with a # resolution > 16 ctypes_array = util.memhandle_as_ctypes_array_32(memhandle) # 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 or # win_buf_to_array_32 before the memory is freed. The copy can be used # at any time. # Check if the buffer was successfully allocated if not memhandle: print("Failed to allocate memory.") return try: # Start the scan ul.a_in_scan(board_num, low_chan, high_chan, total_count, rate, ai_range, memhandle, scan_options) # Create a format string that aligns the data in columns row_format = "{:>12}" * num_chans # Print the channel name headers labels = [] for ch_num in range(low_chan, high_chan + 1): labels.append("CH" + str(ch_num)) print(row_format.format(*labels)) # Start updating the displayed values status, curr_count, curr_index = ul.get_status(board_num, FunctionType.AIFUNCTION) while status != Status.IDLE: # Make sure a data point is available for display. if curr_count > 0: # curr_index points to the start of the last completed # channel scan that was transferred between the board and # the data buffer. Display the latest value for each # channel. display_data = [] for data_index in range(curr_index, curr_index + num_chans): if ScanOptions.SCALEDATA in scan_options: # If the SCALEDATA ScanOption was used, the values # in the array are already in engineering units. eng_value = ctypes_array[data_index] else: # If the SCALEDATA ScanOption was NOT used, the # values in the array must be converted to # engineering units using ul.to_eng_units(). eng_value = ul.to_eng_units(board_num, ai_range, ctypes_array[data_index]) display_data.append('{:.3f}'.format(eng_value)) print(row_format.format(*display_data)) # Wait a while before adding more values to the display. time.sleep(0.5) status, curr_count, curr_index = ul.get_status( board_num, FunctionType.AIFUNCTION) # Stop the background operation (this is required even if the # scan completes successfully) ul.stop_background(board_num, FunctionType.AIFUNCTION) print("Scan completed successfully.") except ULError as e: util.print_ul_error(e) finally: # Free the buffer in a finally block to prevent errors from causing # a memory leak. ul.win_buf_free(memhandle) if use_device_detection: ul.release_daq_device(board_num)
def mc_analog_init(board_num): ai_props = AnalogInputProps(board_num) ai_range = ai_props.available_ranges[0]
def run_example(): board_num = 0 rate = 100 points_per_channel = 10 if use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(board_num): print("Could not find device.") return ai_props = AnalogInputProps(board_num) if ai_props.num_ai_chans < 1: util.print_unsupported_example(board_num) return low_chan = 0 high_chan = min(3, ai_props.num_ai_chans - 1) num_chans = high_chan - low_chan + 1 total_count = points_per_channel * num_chans ai_range = ai_props.available_ranges[0] scan_options = ScanOptions.FOREGROUND if ScanOptions.SCALEDATA in ai_props.supported_scan_options: # If the hardware supports the SCALEDATA option, it is easiest to # use it. scan_options |= ScanOptions.SCALEDATA memhandle = ul.scaled_win_buf_alloc(total_count) # Convert the memhandle to a ctypes array. # Use the memhandle_as_ctypes_array_scaled method for scaled # buffers. ctypes_array = util.memhandle_as_ctypes_array_scaled(memhandle) elif ai_props.resolution <= 16: # Use the win_buf_alloc method for devices with a resolution <= 16 memhandle = ul.win_buf_alloc(total_count) # Convert the memhandle to a ctypes array. # Use the memhandle_as_ctypes_array method for devices with a # resolution <= 16. ctypes_array = util.memhandle_as_ctypes_array(memhandle) else: # Use the win_buf_alloc_32 method for devices with a resolution > 16 memhandle = ul.win_buf_alloc_32(total_count) # Convert the memhandle to a ctypes array. # Use the memhandle_as_ctypes_array_32 method for devices with a # resolution > 16 ctypes_array = util.memhandle_as_ctypes_array_32(memhandle) # 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 or # win_buf_to_array_32 before the memory is freed. The copy can be used # at any time. # Check if the buffer was successfully allocated if not memhandle: print("Failed to allocate memory.") return try: # Start the scan ul.a_in_scan(board_num, low_chan, high_chan, total_count, rate, ai_range, memhandle, scan_options) print("Scan completed successfully. Data:") # Create a format string that aligns the data in columns row_format = "{:>5}" + "{:>10}" * num_chans # Print the channel name headers labels = [] labels.append("Index") for ch_num in range(low_chan, high_chan + 1): labels.append("CH" + str(ch_num)) print(row_format.format(*labels)) # Print the data data_index = 0 for index in range(points_per_channel): display_data = [index] for _ in range(num_chans): if ScanOptions.SCALEDATA in scan_options: # If the SCALEDATA ScanOption was used, the values # in the array are already in engineering units. eng_value = ctypes_array[data_index] else: # If the SCALEDATA ScanOption was NOT used, the # values in the array must be converted to # engineering units using ul.to_eng_units(). eng_value = ul.to_eng_units(board_num, ai_range, ctypes_array[data_index]) data_index += 1 display_data.append('{:.3f}'.format(eng_value)) # Print this row print(row_format.format(*display_data)) except ULError as e: util.print_ul_error(e) finally: # Free the buffer in a finally block to prevent errors from causing # a memory leak. ul.win_buf_free(memhandle) if use_device_detection: ul.release_daq_device(board_num)
def run_example(): board_num = 0 rate = 100 file_name = 'scan_data.csv' # The size of the UL buffer to create, in seconds buffer_size_seconds = 2 # The number of buffers to write. After this number of UL buffers are # written to file, the example will be stopped. num_buffers_to_write = 5 if use_device_detection: ul.ignore_instacal() if not util.config_first_detected_device(board_num): print("Could not find device.") return ai_props = AnalogInputProps(board_num) if (ai_props.num_ai_chans < 1 or not ScanOptions.SCALEDATA in ai_props.supported_scan_options): util.print_unsupported_example(board_num) return low_chan = 0 high_chan = min(3, ai_props.num_ai_chans - 1) num_chans = high_chan - low_chan + 1 # Create a circular buffer that can hold buffer_size_seconds worth of # data, or at least 10 points (this may need to be adjusted to prevent # a buffer overrun) points_per_channel = max(rate * buffer_size_seconds, 10) # Some hardware requires that the total_count is an integer multiple # of the packet size. For this case, calculate a points_per_channel # that is equal to or just above the points_per_channel selected # which matches that requirement. if ai_props.continuous_requires_packet_size_multiple: packet_size = ai_props.packet_size remainder = points_per_channel % packet_size if remainder != 0: points_per_channel += packet_size - remainder ul_buffer_count = points_per_channel * num_chans # Write the UL buffer to the file num_buffers_to_write times. points_to_write = ul_buffer_count * num_buffers_to_write # When handling the buffer, we will read 1/10 of the buffer at a time write_chunk_size = int(ul_buffer_count / 10) ai_range = ai_props.available_ranges[0] scan_options = (ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS | ScanOptions.SCALEDATA) memhandle = ul.scaled_win_buf_alloc(ul_buffer_count) # Allocate an array of doubles temporary storage of the data write_chunk_array = (c_double * write_chunk_size)() # Check if the buffer was successfully allocated if not memhandle: print("Failed to allocate memory.") return try: # Start the scan ul.a_in_scan( board_num, low_chan, high_chan, ul_buffer_count, rate, ai_range, memhandle, scan_options) status = Status.IDLE # Wait for the scan to start fully while(status == Status.IDLE): status, _, _ = ul.get_status( board_num, FunctionType.AIFUNCTION) # Create a file for storing the data with open(file_name, 'w') as f: print('Writing data to ' + file_name, end='') # Write a header to the file for chan_num in range(low_chan, high_chan + 1): f.write('Channel ' + str(chan_num) + ',') f.write(u'\n') # Start the write loop prev_count = 0 prev_index = 0 write_ch_num = low_chan while status != Status.IDLE: # Get the latest counts status, curr_count, _ = ul.get_status( board_num, FunctionType.AIFUNCTION) new_data_count = curr_count - prev_count # Check for a buffer overrun before copying the data, so # that no attempts are made to copy more than a full buffer # of data if new_data_count > ul_buffer_count: # Print an error and stop writing ul.stop_background(board_num, FunctionType.AIFUNCTION) print("A buffer overrun occurred") break # Check if a chunk is available if new_data_count > write_chunk_size: wrote_chunk = True # Copy the current data to a new array # Check if the data wraps around the end of the UL # buffer. Multiple copy operations will be required. if prev_index + write_chunk_size > ul_buffer_count - 1: first_chunk_size = ul_buffer_count - prev_index second_chunk_size = ( write_chunk_size - first_chunk_size) # Copy the first chunk of data to the # write_chunk_array ul.scaled_win_buf_to_array( memhandle, write_chunk_array, prev_index, first_chunk_size) # Create a pointer to the location in # write_chunk_array where we want to copy the # remaining data second_chunk_pointer = cast( addressof(write_chunk_array) + first_chunk_size * sizeof(c_double), POINTER(c_double)) # Copy the second chunk of data to the # write_chunk_array ul.scaled_win_buf_to_array( memhandle, second_chunk_pointer, 0, second_chunk_size) else: # Copy the data to the write_chunk_array ul.scaled_win_buf_to_array( memhandle, write_chunk_array, prev_index, write_chunk_size) # Check for a buffer overrun just after copying the data # from the UL buffer. This will ensure that the data was # not overwritten in the UL buffer before the copy was # completed. This should be done before writing to the # file, so that corrupt data does not end up in it. status, curr_count, _ = ul.get_status( board_num, FunctionType.AIFUNCTION) if curr_count - prev_count > ul_buffer_count: # Print an error and stop writing ul.stop_background(board_num, FunctionType.AIFUNCTION) print("A buffer overrun occurred") break for i in range(write_chunk_size): f.write(str(write_chunk_array[i]) + ',') write_ch_num += 1 if write_ch_num == high_chan + 1: write_ch_num = low_chan f.write(u'\n') else: wrote_chunk = False if wrote_chunk: # Increment prev_count by the chunk size prev_count += write_chunk_size # Increment prev_index by the chunk size prev_index += write_chunk_size # Wrap prev_index to the size of the UL buffer prev_index %= ul_buffer_count if prev_count >= points_to_write: break print('.', end='') else: # Wait a short amount of time for more data to be # acquired. time.sleep(0.1) ul.stop_background(board_num, FunctionType.AIFUNCTION) except ULError as e: util.print_ul_error(e) finally: print('Done') # Free the buffer in a finally block to prevent errors from causing # a memory leak. ul.win_buf_free(memhandle) if use_device_detection: ul.release_daq_device(board_num)