def _get_supports_v_in(self, available_ranges): if len(available_ranges) == 0: return False try: ul.v_in(self._board_num, 0, available_ranges[0]) except ULError: return False return True
def supports_v_in(self): v_in_supported = True ai_ranges = self.supported_ranges if not ai_ranges: v_in_supported = False else: try: ul.v_in(self._board_num, 0, ai_ranges[0]) except ULError: v_in_supported = False return v_in_supported
def update_value(self): channel = self.get_channel_num() ai_range = self.get_range() try: # Get a value from the device if self.ai_props.resolution <= 16: # Use the v_in method for devices with a resolution <= 16 # (optional parameter omitted) value = ul.v_in(self.board_num, channel, ai_range) else: # Use the v_in_32 method for devices with a resolution > 16 # (optional parameter omitted) value = ul.v_in_32(self.board_num, channel, ai_range) # Display the raw value self.value_label["text"] = '{:.3f}'.format(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 sample_device(board_num): # Reads an A/D input channel, and returns a voltage value only if the board is on. channel = 2 ai_range = ULRange.BIP10VOLTS try: # Get a value from the device value = ul.v_in(board_num, channel, ai_range) except ULError: return random.random()[0] return value
def sample_device(self, board_num): # Reads an A/D input channel, and returns a voltage value only if the board is on. ai_range = ULRange.BIP10VOLTS try: # Get a value from the device value = ul.v_in(board_num, self.channel_number, ai_range) except ULError: return np.nan newton_value = value * self.volt_to_newton_factor return newton_value
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 v_in method for devices with a resolution <= 16 # (optional parameter omitted) value = ul.v_in(board_num, channel, ai_range) else: # Use the v_in_32 method for devices with a resolution > 16 # (optional parameter omitted) value = ul.v_in_32(board_num, channel, ai_range) # Display the value print('Value:', value) except Exception as e: print('\n', e) finally: if use_device_detection: ul.release_daq_device(board_num)
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 v_in method for devices with a resolution <= 16 # (optional parameter omitted) value = ul.v_in(board_num, channel, ai_range) else: # Use the v_in_32 method for devices with a resolution > 16 # (optional parameter omitted) value = ul.v_in_32(board_num, channel, ai_range) # Display the value print("Value: " + str(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): try: # Read voltage value from each channel global flag global row global col channel = 0 ai_range = ULRange.BIP10VOLTS ser = serial.Serial(SERIAL_PORT, SERIAL_RATE) ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') value1 = ul.v_in(self.board_num, channel, ai_range) value1 = value1 * 2.06 # Number calculated to compensate for voltage divider. value2 = ul.v_in(self.board_num, channel + 1, ai_range) value2 = value2 / -9.99 #step down voltage from op-amp input # value2 = value2 / 1.1 # Calculate current from voltage value value3 = ul.v_in(self.board_num, channel + 2, ai_range) value3 = value3 * 2.06 # to remove voltage divider value4 = ul.v_in(self.board_num, channel + 3, ai_range) value4 = value4 / -10.04 #step down voltage from op-amp input #value4 = value4 / 1.1 # Calculate current from voltage value value5 = ul.v_in(self.board_num, channel + 4, ai_range) value5 = value5 * 2.06 # to remove voltage divider value6 = ul.v_in(self.board_num, channel + 5, ai_range) value6 = value6 / -10.07 #step down voltage from op-amp input #value6 = value6 / 1.1 # Calculate current from voltage value value7 = ul.v_in(self.board_num, channel + 6, ai_range) value7 = value7 * 2.06 # to remove voltage divider value8 = ul.v_in(self.board_num, channel + 7, ai_range) value8 = value8 / -10.03 #step down voltage from op-amp input #value8 = value8 / 1.1 # Calculate current from voltage value # obtain temperature value from thermocouple on Arduino tempValue = ser.readline().decode('utf-8') #Output values on GUI self.BV1["text"] = '{:.2f}'.format(value1) + "V" self.BC1["text"] = '{:.3f}'.format(value2) + "A" self.BV2["text"] = '{:.2f}'.format(value3) + "V" self.BC2["text"] = '{:.3f}'.format(value4) + "A" self.BV3["text"] = '{:.2f}'.format(value5) + "V" self.BC3["text"] = '{:.3f}'.format(value6) + "A" self.BV4["text"] = '{:.2f}'.format(value7) + "V" self.BC4["text"] = '{:.3f}'.format(value8) + "A" self.temperatureLabel["text"] = str(tempValue) # # Write values # worksheet.write(row, col, value1) # worksheet.write(row, col + 1, value2) # worksheet.write(row, col + 2, value3) # worksheet.write(row, col + 3, value4) # worksheet.write(row, col + 4, value5) # worksheet.write(row, col + 5, value6) # worksheet.write(row, col + 6, value7) # worksheet.write(row, col + 7, value8) # worksheet.write(row, col + 8, tempValue) # row += 1 # Write values on to spreadsheet if flag >= 30: #Log every 30 seconds worksheet.write(row, col, value1) worksheet.write(row, col + 1, value2) worksheet.write(row, col + 2, value3) worksheet.write(row, col + 3, value4) worksheet.write(row, col + 4, value5) worksheet.write(row, col + 5, value6) worksheet.write(row, col + 6, value7) worksheet.write(row, col + 7, value8) worksheet.write(row, col + 8, tempValue) worksheet.write(row, col + 9, st) row += 1 flag = 0 else: flag += 1 if self.running: self.after(1000, self.update_value) except ULError as e: self.show_ul_error(e)