def __init__(self, rm: visa.ResourceManager): super().__init__() self.rm = rm # Get a list of resources, open comms, and poll them for their ID string self.instruments = rm.list_resources() self.instr_ids = [] for instr in self.instruments: current_instr = self.rm.open_resource(instr) try: self.instr_ids.append(current_instr.query("*IDN?")) except VisaIOError: print( 'Error getting instrument ID string from {}'.format(instr)) current_instr.close() self.instr_combo_box = QComboBox() self.instr_combo_box.addItems(self.instruments) self.instr_id_label = QLabel() self.ok_btn = QPushButton('Ok') self.form_layout = QFormLayout() self.init_layout() self.init_connections()
def list_instruments(): """Get a list of all power supplies currently attached""" paramsets = [] search_string = "ASRL?*" rm = ResourceManager() raw_spec_list = rm.list_resources(search_string) for spec in raw_spec_list: try: inst = rm.open_resource(spec, read_termination='\n', write_termination='\n') idn = inst.query("*IDN?") manufacturer, model, serial, version = idn.rstrip().split(',', 4) if re.match('DP7[0-9]{2}', model): paramsets.append( ParamSet(DP700, asrl=spec, manufacturer=manufacturer, serial=serial, model=model, version=version)) except pyvisa.errors.VisaIOError as vio: # Ignore unknown serial devices pass return paramsets
def update_devices(self): rm = ResourceManager('@py') try: self._resources = [x for x in rm.list_resources() if 'GPIB' in x] except: self._resources = [] self._combobox.clear() for item in self._resources: self._combobox.addItem(item) rm.close()
def list_instruments(): """Get a list of all spectrometers currently attached""" paramsets = [] search_string = "USB?*?{VI_ATTR_MANF_ID==0x1313 && ((VI_ATTR_MODEL_CODE==0x8081) || (VI_ATTR_MODEL_CODE==0x8083) || (VI_ATTR_MODEL_CODE==0x8085) || (VI_ATTR_MODEL_CODE==0x8087) || (VI_ATTR_MODEL_CODE==0x8089))}" rm = ResourceManager() try: raw_spec_list = rm.list_resources(search_string) except: return paramsets for spec in raw_spec_list: _, _, model, serial, _ = spec.split('::', 4) model = SpecTypes(int(model, 0)) paramsets.append(ParamSet(CCS, usb=spec, serial=serial, model=model)) return paramsets
def list_instruments(): """Get a list of all spectrometers currently attached""" paramsets = [] model_string = '|'.join('{:04X}'.format(spec.value) for spec in SpecTypes) search_string = "USB[0-9]*::0x{:04X}::0x({})".format(MANUFACTURER_ID, model_string) rm = ResourceManager() try: raw_spec_list = rm.list_resources(search_string) except: return paramsets for spec in raw_spec_list: _, _, model, serial, _ = spec.split('::', 4) model = SpecTypes(int(model, 0)) paramsets.append(ParamSet(DG800, usb=spec, serial=serial, model=model)) return paramsets
def list_instruments(): """ Get a list of all spectrometers currently attached. """ spectrometers = [] search_string = "USB?*?{VI_ATTR_MANF_ID==0x1313 && ((VI_ATTR_MODEL_CODE==0x8081) || (VI_ATTR_MODEL_CODE==0x8083) || (VI_ATTR_MODEL_CODE==0x8085) || (VI_ATTR_MODEL_CODE==0x8087) || (VI_ATTR_MODEL_CODE==0x8089))}" rm = ResourceManager() try: raw_spec_list = rm.list_resources(search_string) except: return spectrometers for spec in raw_spec_list: _, _, model, serial_number, _ = spec.split("::") model = SpecTypes(int(model, 0)) params = _ParamDict("<Thorlabs_CCS_Spectrometer '{}-{}'>".format( model.name, serial_number)) params.module = 'spectrometers.thorlabs_ccs' params['ccs_usb_address'] = spec params['ccs_model'] = model params['ccs_serial_number'] = serial_number spectrometers.append(params) return spectrometers
def list_instruments(): """Get a list of all spectrometers currently attached""" paramsets = [] model_string = '' for spec in SpecTypes: model_string += '(VI_ATTR_MODEL_CODE==0x{:04X}) || '.format(spec.value) model_string = model_string.rstrip(' || ') search_string = "USB?*?{{VI_ATTR_MANF_ID==0x{:04X} && ({})}}".format( MANUFACTURER_ID, model_string) rm = ResourceManager() try: raw_spec_list = rm.list_resources(search_string) except: return paramsets for spec in raw_spec_list: _, _, model, serial, _ = spec.split('::', 4) model = SpecTypes(int(model, 0)) paramsets.append(ParamSet(DG800, usb=spec, serial=serial, model=model)) return paramsets
class ScopeFinder: def __init__(self): """ Constructor """ self.logger = logging.getLogger('scopeout.utilities.ScopeFinder') self.logger.info('ScopeFinder Initialized') self.resource_manager = ResourceManager() self.resources = [] self.instruments = [] self.scopes = [] self.blacklist = set() self.refresh() def __enter__(self): # Entry point for the *with* statement, which allows this object to close properly on program exit. return self def __exit__(self, type, value, traceback): # Exit point for with statement pass def query(self, inst, command): """ Issues query to instrument and returns response. Parameters: :inst: the instrument to be queried. :command: the command to be issued. :Returns: the response of inst as a string. """ return inst.query(command).strip() # strip newline def get_scopes(self): """ Getter for array of connected oscilloscopes. :Returns: an array of PyVisa instrument objects representing USB oscilloscopes connected to the computer. """ return self.scopes def refresh(self): """ Re-run scope acquisition to update scope array. :Returns: the ScopeFinder object, for convenience. """ self.scopes = [] self.resources = [] try: self.resources = self.resource_manager.list_resources() except VisaIOError as e: self.resources = [] if self.resources: self.logger.info("%d VISA Resource(s) found", len(self.resources)) self.instruments = [] for resource in set(self.resources) - self.blacklist: try: inst = self.resource_manager.open_resource(resource) self.instruments.append(inst) self.logger.info('Resource {} converted to instrument'.format(resource)) except Exception as e: self.logger.error(e) self.blacklist.add(resource) for ins in self.instruments: try: info = self.query(ins, '*IDN?').split(',') # Parse identification string if info[1] == 'TDS 2024B': # TDS 2024B oscilloscope info.append(info.pop().split()[1][3:]) # get our identification string into array format scope = oscilloscopes.TDS2024B(ins, info[1], info[2], info[3]) self.scopes.append(scope) self.logger.info("Found %s", str(scope)) elif re.match('GDS-1.*A', info[1]): scope = oscilloscopes.GDS1000A(ins, info[1], info[2], info[3]) self.scopes.append(scope) self.logger.info("Found %s", str(scope)) elif re.match('GDS-2.*A', info[1]): scope = oscilloscopes.GDS2000A(ins, info[1], info[2], info[3]) self.scopes.append(scope) self.logger.info("Found %s", str(scope)) # Support for other scopes to be implemented here! except VisaIOError or IndexError: self.logger.error('{} could not be converted to an oscilloscope'.format(ins)) return self def check_scope(self, scope_index): """ Check if the scope at scopeIndex is still connected. Parameters: :scopeIndex: the index of the scopes array to check. :Returns: True if connected, false otherwise """ try: if self.scopes[scope_index].getTriggerStatus(): return True else: return False except: return False