def _get_available_ranges(self, ad_resolution): result = [] for ai_range in ULRange: try: if ad_resolution <= 16: ul.a_in(self._board_num, 0, ai_range) else: ul.a_in_32(self._board_num, 0, ai_range) result.append(ai_range) except ULError: pass return result
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 _get_available_ranges(self, ad_resolution): result = [] # Check if the board has a switch-selectable, or only one, range hard_range = ul.get_config( InfoType.BOARDINFO, self._board_num, 0, BoardInfo.RANGE) if hard_range >= 0: result.append(ULRange(hard_range)) else: for ai_range in ULRange: try: if ad_resolution <= 16: ul.a_in(self._board_num, 0, ai_range) else: ul.a_in_32(self._board_num, 0, ai_range) result.append(ai_range) except ULError as e: if (e.errorcode == ErrorCode.NETDEVINUSE or e.errorcode == ErrorCode.NETDEVINUSEBYANOTHERPROC): raise return result
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 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)