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 read_pressure(): try: # Get a value from the device 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) psi = (eng_units_value - 0.5) * 500 / 3 print 'psi:', psi except ULError as e: # Display the error print("A UL error occurred. Code: " + str(e.errorcode) + " Message: " + e.message)
def daq_connected(): """ daq_connected() --> bool Gets a test value from the USB2020. If there is an error during the process, then the USB2020 is unavailable for use. Returns: True if no errors occurred during test data acquisition. False if errors occurred during test data acquisition. """ from mcculw import ul from mcculw.enums import ULRange from mcculw.ul import ULError board_num = 0 channel = 0 ai_range = ULRange.BIP5VOLTS try: ul.a_in(board_num, channel, ai_range) return True except ULError: return False
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 readVoltage(self, gain=0): # Based on my understanding of the universal library source code and docs # The UL.AbIN gets inupt from the card and the cbtoEngUnits reads the # input as voltage voltageReadings = list() # print self.channelNumber ai_range = ULRange.BIP10VOLTS for i in range(0, self.channelNumber+1): # if i ==1: # voltage = 0 # short = 0 # else: short = ul.a_in(self.deviceNumber, i, ai_range) voltage = float(ul.to_eng_units(self.deviceNumber, gain, short)) voltageReadings.append(voltage) print str(short) + " " + str(voltage) # print UL.cbToEngUnits(self.getDeviceNumber(), 0, UL.cbAIn( # self.getDeviceNumber(), 0, gain)) # print UL.cbToEngUnits(self.getDeviceNumber(), 1, UL.cbAIn( # self.getDeviceNumber(), 1, gain)) time.sleep(.001) return voltageReadings
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 readInductionVoltage(self): ai_range = ULRange.BIPPT156VOLTS value = ul.a_in(0, 2, ai_range) dec_value = ul.to_eng_units(0, ai_range, value) return dec_value * 64.103
def readFotodiode(self): ai_range = ULRange.BIPPT05VOLTS value = ul.a_in(0, 3, ai_range) dec_value = ul.to_eng_units(0, ai_range, value) return dec_value * 200
def readShuntVoltage(self): ai_range = ULRange.BIP1PT67VOLTS value = ul.a_in(0, 1, ai_range) dec_value = ul.to_eng_units(0, ai_range, value) return dec_value * 5.988
def readChannel(self, ch): ai_range = ULRange.BIP5VOLTS value = ul.a_in(0, ch, ai_range) dec_value = ul.to_eng_units(0, ai_range, value) return dec_value * 2
# determines averaging window based on time resolution t_end = time.time() + time_resolution # sample loops until time resolution is met while time.time() < t_end: ts = time.time() # store live values into an empty list bit_values = [] eng_units_values = [] conc_values = [] # convert from analog to digital value bit_value = ul.a_in(board_num, channel, ai_range) # append to our list bit_values.append(bit_value) # convert from digital back to analog eng_units_value = ul.to_eng_units(board_num, ai_range, bit_value) # append to its list eng_units_values.append(eng_units_value) # determine our concentration value based on the V_reference, V_fullscale, and our upper detection limit at fullscale conc_value = (eng_units_value / fullscale) * upper_limit # append these to our list conc_values.append(conc_value)
V = V.reshape(-1, 1) P = P.reshape(-1, 1) regr = linear_model.LinearRegression() # Train the model using the training sets lr = regr.fit(V, P) cf = lr.coef_ inter = lr.intercept_ ####reading from PTB110##### board_num = 0 channel = 0 ai_range = ULRange.UNI5VOLTS input_mode = AnalogInputMode.DIFFERENTIAL value = ul.a_in(board_num, channel, input_mode) leave_loop = False ####reading from Clarity#### import win32com.client as win32 clar = win32.gencache.EnsureDispatch('ClarityII.CloudSensorII') while not leave_loop: try: # Get a value from the device value = ul.a_in(board_num, channel, input_mode) # Convert the raw value to engineering units V = ul.to_eng_units(board_num, input_mode, value) P = V * cf + inter
def analog_read(): return ul.a_in(BOARD_NUM, CH_0, ULRange.BIP5VOLTS)