def open_by_address(addr, csv_dir=None, csv_folder='tester', instr_class='TestInstrument', cmd_name='commands.csv', lookup_name='lookup.csv', **kwargs): """ Open an instrument by address and optionally use the system config file Parameters ---------- addr : dict The address of the instrument as a dict; e.g. {'pyvisa': 'USB0::0x0957::0x17A9::MY52160418::INSTR'} csv_dir : str Base directory to the csv instrument command input files csv_folder : str Folder for the commands.csv and lookup.csv files instr_class : str The name of the class in instruments.py cmd_name : The name of the csv file with commands lookup_name : The name of the csv file with a lookup map Returns ------- typical usage (for pytests) t = open_by_address({'no_interface': 'no_address'}) An instrument object """ configs = {} configs['csv_directory'] = csv_dir configs['cmd_name'] = cmd_name configs['lookup_name'] = lookup_name cmd_map = os.path.join(configs['csv_directory'], csv_folder, configs['cmd_name']) lookup_file = os.path.join(configs['csv_directory'], csv_folder, configs['lookup_name']) cmd_list, inst_comm, unconnected = init_instrument(cmd_map, addr=addr, lookup=lookup_file, **kwargs) InstrumentClass = getattr(instruments, instr_class) name = 'tester' return InstrumentClass(cmd_list, inst_comm, name, unconnected)
def open_by_name(name, name_attached=None, filename='config.yaml', **kwargs): """ Use the system configuration file to open an instrument by name Parameters ---------- name : str The name of the instrument in the configuration file name_attached : str (optional) The name attached to the returned object. If not provided the name in the configuration file is used filename : str The YAML configuration filename Returns ------- An instrument object """ yaml_config = open(os.path.join(home, filename), 'r') configs = yaml.safe_load(yaml_config) # confirm name is in the configs if name not in configs['instruments']: print('Error: {} is not a named instrument in the configuration file') cmd_map = os.path.join(configs['csv_directory'], configs['instruments'][name]['csv_folder'], configs['cmd_name']) lookup_file = os.path.join(configs['csv_directory'], configs['instruments'][name]['csv_folder'], configs['lookup_name']) cmd_list, inst_comm, unconnected = init_instrument( cmd_map, addr=configs['instruments'][name]['address'], lookup=lookup_file, **kwargs) if name_attached is not None: name = name_attached InstrumentClass = getattr(instruments, configs['instruments'][name]['python_class']) return InstrumentClass(cmd_list, inst_comm, name, unconnected)