def display_values(self, array, range_, total_count, low_chan, high_chan): new_data_frame = tk.Frame(self.results_group) channel_text = [] # Add the headers for chan_num in range(low_chan, high_chan + 1): channel_text.append("Channel " + str(chan_num) + "\n") chan_count = high_chan - low_chan + 1 # Add (up to) the first 10 values for each channel to the text chan_num = low_chan for data_index in range(0, min(chan_count * 10, total_count)): if self.ai_info.resolution <= 16: eng_value = ul.to_eng_units(self.board_num, range_, array[data_index]) else: eng_value = ul.to_eng_units_32(self.board_num, range_, array[data_index]) channel_text[chan_num - low_chan] += ('{:.3f}'.format(eng_value) + "\n") chan_num = low_chan if chan_num == high_chan else chan_num + 1 # Add the labels for each channel for chan_num in range(low_chan, high_chan + 1): chan_label = tk.Label(new_data_frame, justify=tk.LEFT, padx=3) chan_label["text"] = channel_text[chan_num - low_chan] chan_label.grid(row=0, column=chan_num - low_chan) self.data_frame.destroy() self.data_frame = new_data_frame self.data_frame.grid()
def update_value(self): channel = self.get_channel_num() ai_range = self.ai_props.available_ranges[0] try: # Get a value from the device if self.ai_props.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() self.show_ul_error(e)
def run_example(): # By default, the example detects and displays all available devices and # selects the first device listed. Use the dev_id_list variable to filter # detected devices by device ID (see UL documentation for device IDs). # If use_device_detection is set to False, the board_num variable needs to # match the desired board number configured with Instacal. use_device_detection = True dev_id_list = [] board_num = 0 try: if use_device_detection: config_first_detected_device(board_num, dev_id_list) daq_dev_info = DaqDeviceInfo(board_num) if not daq_dev_info.supports_analog_input: raise Exception('Error: The DAQ device does not support ' 'analog input') print('\nActive DAQ device: ', daq_dev_info.product_name, ' (', daq_dev_info.unique_id, ')\n', sep='') ai_info = daq_dev_info.get_ai_info() ai_range = ai_info.supported_ranges[0] channel = 0 # Get a value from the device if ai_info.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:', value) # Display the engineering value print('Engineering Value: {:.3f}'.format(eng_units_value)) except Exception as e: print('\n', e) finally: if use_device_detection: ul.release_daq_device(board_num)
def plot_channel(self): channel = self.get_chan_num() ai_range = self.ai_props.available_ranges[0] y_vec = np.linspace(-10, 10, 10) x_vec = [datetime.datetime.now() + datetime.timedelta(seconds=i) for i in range(len(y_vec))] line1 = [] while True: rand_val = ul.a_in_32(self.board_num, channel, ai_range) value = ul.to_eng_units_32(self.board_num, ai_range, rand_val) y_vec[-1] = value line1 = self.live_plotter(x_vec,y_vec,line1) y_vec = np.append(y_vec[1:],0.0)
def display_input_values(self, range_, curr_index, curr_count): per_channel_display_count = 1 array = self.ctypes_array low_chan = self.input_low_chan high_chan = self.input_high_chan ULAIO01.channel_text = [] # Add the headers for chan_num in range(low_chan, high_chan + 1): ULAIO01.channel_text.append("Channel " + str(chan_num) + "\n") # If no data has been gathered, don't add data to the labels if curr_count > 1: chan_count = high_chan - low_chan + 1 chan_num = low_chan # curr_index points to the start_input of the last completed channel scan that # was transferred between the board and the data buffer. Based on this, # calculate the first index we want to display using subtraction. first_index = max( curr_index - ((per_channel_display_count - 1) * chan_count), 0) # Add (up to) the latest 10 values for each channel to the text for data_index in range( first_index, first_index + min(chan_count * per_channel_display_count, curr_count)): raw_value = array[data_index] if self.ai_props.resolution <= 16: ULAIO01.eng_value = ul.to_eng_units( self.board_num, range_, raw_value) else: ULAIO01.eng_value = ul.to_eng_units_32( self.board_num, range_, raw_value) ULAIO01.channel_text[chan_num - low_chan] += ( '{:.3f}'.format(ULAIO01.eng_value) + "\n") self.datasheet() # custom datahandling if chan_num == high_chan: chan_num = low_chan else: chan_num += 1 # Update the labels for each channel for chan_num in range(low_chan, high_chan + 1): ULAIO01.chan_index = chan_num - low_chan self.chan_labels[ULAIO01.chan_index][ "text"] = ULAIO01.channel_text[ULAIO01.chan_index]
def display_values(self, range_, curr_index, curr_count): per_channel_display_count = 10 array = self.ctypes_array low_chan = self.low_chan high_chan = self.high_chan channel_text = [] # Add the headers for chan_num in range(low_chan, high_chan + 1): channel_text.append("Channel " + str(chan_num) + "\n") # If no data has been gathered, don't add data to the labels if curr_count > 1: chan_count = high_chan - low_chan + 1 chan_num = low_chan # curr_index points to the start of the last completed channel # scan that was transferred between the board and the data # buffer. Based on this, calculate the first index we want to # display using subtraction. first_index = max( curr_index - ((per_channel_display_count - 1) * chan_count), 0) # Add (up to) the latest 10 values for each channel to the text for data_index in range( first_index, first_index + min(chan_count * per_channel_display_count, curr_count)): if self.ai_info.resolution <= 16: eng_value = ul.to_eng_units(self.board_num, range_, array[data_index]) else: eng_value = ul.to_eng_units_32(self.board_num, range_, array[data_index]) channel_text[chan_num - low_chan] += '{:.3f}'.format(eng_value) + "\n" if chan_num == high_chan: chan_num = low_chan else: chan_num += 1 # Update the labels for each channel for chan_num in range(low_chan, high_chan + 1): chan_index = chan_num - low_chan self.chan_labels[chan_index]["text"] = channel_text[chan_index]
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 update_value(self): channel = self.get_chan_num() ai_range = self.ai_props.available_ranges[0] try: if self.ai_props.resolution <= 16: value = ul.a_in(self.board_num, channel, ai_range) eng_value = ul.to_eng_units(self.board_num, ai_range, value) else: value = ul.a_in_32(self.board_num, channel, ai_range) eng_value = ul.to_eng_units_32(self.board_num, ai_range, value) self.value_label["text"] = str(value) self.eng_value_label["text"] = '{:.3f}'.format(eng_value) if self.running: self.after(100, self.update_value) except: pass
def run(): DaqDeviceScan(master=tk.Tk()).mainloop() board_num = 0 rate = 1000 points_per_channel = 30 if use_device_detection: ul.ignore_instacal() if not configDevice(board_num): print("Gerät konnte nicht gefunden werden!") return ai_props = aiProps(board_num) low_channel = 0 high_channel = min(7, ai_props.num_ai_chans - 1) num_channels = high_channel - low_channel + 1 total_amount = points_per_channel * num_channels ai_range = ai_props.available_ranges[0] scan_opt = ScanOptions.FOREGROUND if ScanOptions.SCALEDATA in ai_props.supported_scan_options: scan_opt |= ScanOptions.SCALEDATA memhandle = ul.scaled_win_buf_alloc(total_amount) c_array = memhandle_as_ctypes_array_scaled(memhandle) elif ai_props.resolution <= 16: memhandle = ul.win_buf_alloc(total_amount) c_array = memhandle_as_ctypes_array(memhandle) else: memhandle = ul.win_buf_alloc_32(memhandle) if not memhandle: print("Speicher konnte nicht allokiert werden") restart = False try: wr = csv.writer(open("test5.csv","w"),delimiter=";") ul.a_in_scan(board_num, low_channel, high_channel, total_amount, rate, ai_range, memhandle, scan_opt) print("Scan erfolgreich!") print("Daten: ") test = ul.a_in_32(board_num, 0, ai_range, scan_opt) test = ul.to_eng_units_32(board_num, ai_range, test) print("test value:") print(test) row_format = "{:>5}" + "{:>10}" * num_channels labels = [] labels.append("Index") for ch_num in range(low_channel, high_channel + 1): labels.append("CH" + str(ch_num)) print(row_format.format(*labels)) data_index = 0 for index in range(points_per_channel): display_data = [index] for _ in range(num_channels): if ScanOptions.SCALEDATA in scan_opt: eng_value = c_array[data_index] else: eng_value = ul.to_eng_units( board_num, ai_range, c_array[data_index]) data_index += 1 display_data.append('{:.3f}'.format(eng_value)) wr.writerow(display_data) print(row_format.format(*display_data)) except ULError as e: pass finally: ul.win_buf_free(memhandle) if use_device_detection: ul.release_daq_device(board_num)