def performOpen(self, options={}): """Perform the operation of opening the instrument connection""" # timeout self.timeout_ms = int(1000 * self.dComCfg['Timeout']) # get PXI chassis self.chassis = int(self.comCfg.address) # auto-scan chassis address n_unit = keysightSD1.SD_Module.moduleCount() all_chassis = [ keysightSD1.SD_Module.getChassisByIndex(n) for n in range(n_unit) ] # check if user-given chassis is available if n_unit > 0 and self.chassis not in all_chassis: # if all units are in the same chassis, override given PXI chassis if np.all(np.array(all_chassis) == all_chassis[0]): self.chassis = all_chassis[0] # number of slots in chassis self.n_slot = 18 # supported AWGs and Digitizers self.AWGS = ['M3201', 'M3202', 'M3300', 'M3302'] self.DIGS = ['M3100', 'M3102'] # keep track of current PXI configuration # 0: None, 1: AWG, 2: Digitizer self.units = [0] * self.n_slot self.old_trig_period = -1.0 self.old_dig_delay = -1.0 # Create HVI object self.HVI = keysightSD1.SD_HVI()
def __init__(self, init=1): self.SLOT_NUM = {"CHASSIS": 1, "AWG1": 2, # M3202A AWG1 "AWG2": 3, # M3202A AWG2 "DIG": 4, # M3102A Digitizer "MARK1": 5, # M3201A Marker1 "MARK2": 6} # M3201A Marker1 if init == 1: self.AWG1 = keysightSD1.SD_AOU() AWG1_ID = self.AWG1.openWithSlot("", self.SLOT_NUM["CHASSIS"], self.SLOT_NUM["AWG1"]) if AWG1_ID < 0: raise NameError('Cannot find AWG1') self.MARK1 = keysightSD1.SD_AOU() MARK1_ID = self.MARK1.openWithSlot("", self.SLOT_NUM["CHASSIS"], self.SLOT_NUM["MARK1"]) if MARK1_ID < 0: raise NameError('Cannot find MARK1') else: raise NameError('Plz fix the code') self.Digitizer = keysightSD1.SD_AIN() Digitizer_ID = self.Digitizer.openWithSlot("", self.SLOT_NUM["CHASSIS"], self.SLOT_NUM["DIG"]) if Digitizer_ID < 0: raise NameError('Cannot find Digitizer') self.HVI = keysightSD1.SD_HVI()
def load_HVI_2(AWGs, channel_map, *args,**kwargs): """ load a HVI file on the AWG. Args: AWGS (dict <str, QCoDeS Intrument>) : key is AWGname, value awg object. channel_map (dict <str, (tuple <str, int>)) : key is channelname, value is AWGname, channel number Returns: HVI (SD_HVI) : keyisight HVI object. """ for channel, channel_loc in channel_map.items(): # 6 is the magic number of the arbitary waveform shape. AWGs[channel_loc[0]].awg_stop(channel_loc[1]) AWGs[channel_loc[0]].set_channel_wave_shape(keysightSD1.SD_Waveshapes.AOU_AWG,channel_loc[1]) AWGs[channel_loc[0]].awg_queue_config(channel_loc[1], 1) HVI = keysightSD1.SD_HVI() error = HVI.open(ct.__file__[:-11] + "HVI_single_shot_2qubit_m6.HVI") print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 0",1,2) print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 1",1,3) print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 2",1,4) print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 3",1,5) print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 4",1,6) print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 5",1,7) print(error) error = HVI.assignHardwareWithUserNameAndSlot("Module 6",1,8) print(error) error = HVI.compile() print(error) error = HVI.load() print(error) error = HVI.load() print(error) error = HVI.start() print(error) return HVI
def configureHvi(): config.hvi.handle = key.SD_HVI() hvi = config.hvi.handle log.info("Opening HVI file: {}".format(config.hvi.file_name)) hviID = hvi.open(config.hvi.file_name) if hviID == key.SD_Error.RESOURCE_NOT_READY: #Only for old library log.debug("No Critical Error - {}: {}".format( hviID, key.SD_Error.getErrorMessage(hviID))) log.debug("Using old library -> Need to compile HVI...") elif hviID == key.SD_Error.DEMO_MODULE: #Only for old library log.debug("No Critical Error - {} {}".format( hviID, key.SD_Error.getErrorMessage(hviID))) log.debug("Using old library -> need to assigning HW modules...") elif hviID < 0: log.error("Opening HVI - {}: {}".format( hviID, key.SD_Error.getErrorMessage(hviID))) for hviModule in config.hvi.hviModules: #Find the handle for this module from its slot for module in config.modules: if module.slot == hviModule.slot: hviModule.handle = module.handle log.info("Assigning {} to {} in slot {}".format( hviModule.name, module.model, module.slot)) error = hvi.assignHardwareWithUserNameAndModuleID( hviModule.name, module.handle) if error == -8069: log.debug( "Assigning HVI {}, Spurious Error- {}: {}".format( hviModule.name, error, key.SD_Error.getErrorMessage(error))) log.info("HVI HW assigned for {}, {} in slot {}".format( hviModule.name, module.model, module.slot)) elif error < 0: error_msg = "HVI assign HW AOU Failed for: {} in slot {}, {}: {}".format( hviModule.name, module.model, module.slot, key.SD_Error.getErrorMessage(error)) log.error(error_msg) else: log.info("HVI HW assigned for {}, {} in slot {}".format( hviModule.name, module.model, module.slot)) # if the last module assigned has this error then it is more serious if error == -8069: log.error("Assigning HVI - {}: {}".format( error, key.SD_Error.getErrorMessage(error)))
def __init__(self, awgs, settings, name='virtual_awg', logger=logging, **kwargs): super().__init__(awgs, settings, name, logger, **kwargs) if not keysightSD1: raise ImportError( 'To use the Keysight SD drivers install the keysightSD1 module ' '(http://www.keysight.com/main/software.jspx?ckey=2784055)') if not all( type(awg.fetch_awg).__name__ == KeysightM3601A.__awg_name for awg in self.awgs): raise VirtualAwgError( 'Unusable device added! Not a Keysight M3201A AWG.') self.hvi = keysightSD1.SD_HVI() self.load_hvi_file() self.set_hvi_modules() self.set_awg_settings()
@author: gumcbrid """ import logging import sys import time from collections import namedtuple as namedtuple sys.path.append('C:\Program Files (x86)\Keysight\SD1\Libraries\Python') import keysightSD1 as key constant = namedtuple('constant', 'module, name, value, unit') __log = logging.getLogger(__name__) __hvi = key.SD_HVI() class HviError(Exception): """Basic exception for errors raised by HVI""" _error = None _message = None def __init__(self, error, msg=None): if msg is None: msg = "An error occured with HVI: {}".format(key.SD_Error.getErrorMessage(error)) super(HviError, self).__init__(msg) self._error = error @property def error_message(self): return key.SD_Error.getErrorMessage(self._error)
class Test_HVIexternaltrigger(Test): # Dummy attributes Amplitude = 1 wave_id = 1 prescaler = 0 start_delay = 0 cycles = 0 # Attributes accessible through object initialization test_key = "HVI external trigger" module_a_slot = None module_a_channel = None module_b_slot = None module_b_channel = None # Attributes accessible through class methods module_a = keysightSD1.SD_AOU() module_b = keysightSD1.SD_AOU() waveform = keysightSD1.SD_Wave() hvi = keysightSD1.SD_HVI() def __init__(self, module_dict, module_a_slot, module_a_channel, module_b_slot, module_b_channel): super().__init__(module_dict) self.module_a_slot = module_a_slot self.module_a_channel = module_a_channel self.module_b_slot = module_b_slot self.module_b_channel = module_b_channel self._associate() # This private method associates the module modules (publicly accessible) of this test with the modules # created in the base class def _associate(self): for module in self._module_instances: if module[2][ 1] == self.module_a_slot: # if a module was found in master_slot, assign it to master_module self.module_a = module[0] elif module[2][1] == self.module_b_slot: self.module_b = module[0] else: print( "[ERROR] Associate function: Module found in slot that was not specified as master or slave" ) def send_PXI_trigger_pulse(self, PXI_line_nbr, delay=.2): time.sleep(delay) self.module.PXItriggerWrite(PXI_line_nbr, 0) time.sleep(delay) self.module.PXItriggerWrite(PXI_line_nbr, 1) def set_waveform(self, filestr): self.waveform.newFromFile(filestr) print( "Loaded {} into HVI Trigger Sync Test's waveform".format(filestr)) def set_hvi(self, filestr): self.hvi.open(filestr) self.hvi.compile() self.hvi.load() print("Loaded {}.HVI into HVI Trigger Sync Test".format(filestr))
class Test_FastBranching(Test): # Dummy attributes Amplitude = 1 wave_id_array = [0, 1, 2, 3] prescaler = 0 start_delay = 1 cycles = 1 # Attributes accessible through object initialization test_key = "FastBranching" master_slot = None slave_slot = None master_index = None #index in HVI sequence (might need this if HVI project is built in simulate mode) slave_index = None #index in HVI sequence (might need this if HVI project is built in simulate mode) master_channel = None slave_channel = None # Attributes accessible through class methods master_module = keysightSD1.SD_AOU( ) #assigned with call to associate() method slave_module = keysightSD1.SD_AOU( ) #assigned with call to associate() method waveform_array = [] hvi = keysightSD1.SD_HVI() def __init__(self, module_dict, master_slot, slave_slot, master_channel, slave_channel, master_index=0, slave_index=1): super().__init__(module_dict) self.master_slot = master_slot self.slave_slot = slave_slot self.master_index = master_index self.slave_index = slave_index self.master_channel = master_channel self.slave_channel = slave_channel self._associate() # This private method associates the master & slave modules (publicly accessible) of this test with the modules # created in the base class def _associate(self): for module in self._module_instances: if module[2][ 1] == self.master_slot: # if a module was found in master_slot, assign it to master_module self.master_module = module[0] elif module[2][ 1] == self.slave_slot: # if a module was found in slave_slot, assign it to slave_module self.slave_module = module[0] else: print( "[ERROR] Associate function: Module found in slot that was not specified as master or slave" ) def send_PXI_trigger_pulse(self, PXI_line_nbr, delay=.1): time.sleep(delay) self.master_module.PXItriggerWrite(PXI_line_nbr, 0) time.sleep(delay) self.master_module.PXItriggerWrite(PXI_line_nbr, 1) def add_waveform(self, filestr): wave = keysightSD1.SD_Wave() wave.newFromFile(filestr) self.waveform_array.append(wave) print("Loaded {} into Fast Branching Test's waveform array".format( filestr)) def set_hvi(self, filestr): self.hvi.open(filestr) self.hvi.compile() self.hvi.load() print("Loaded {}.HVI into Fast Branching Test".format(filestr))