def save_complex_data_locally(self, filename, format = SaveDataFormat.real_imaginary): extension = ".csv" unique_filename = unique_alphanumeric_string() + extension if not filename.lower().endswith(extension): filename += extension self.save_complex_data(unique_filename, format) self._vna.file.download_file(unique_filename, filename) self._vna.file.delete(unique_filename)
def save_data_locally(self, filename): extension = ".csv" unique_filename = unique_alphanumeric_string() + extension if not filename.lower().endswith(extension): filename += extension self.save_data(unique_filename) self._vna.file.download_file(unique_filename, filename) self._vna.file.delete(unique_filename)
def save_screenshot_locally(self, filename, image_format='JPG'): extension = ".{0}".format(image_format).lower() unique_filename = unique_alphanumeric_string() + extension if not filename.lower().endswith(extension): filename += extension self.save_screenshot(unique_filename, image_format) self._vna.file.download_file(unique_filename, filename) self._vna.file.delete(unique_filename)
def save_measurement_locally(self, filename, ports, format='COMP'): extension = ".s{0}p".format(len(ports)) unique_filename = unique_alphanumeric_string() + extension if not filename.lower().endswith(extension): filename += extension self.save_measurement(unique_filename, ports, format) self._vna.file.download_file(unique_filename, filename) self._vna.file.delete(unique_filename)
def save_screenshot_locally(self, filename, image_format='JPG'): extension = "." + str(image_format).lower() unique_filename = unique_alphanumeric_string() + extension if not filename.lower().endswith(extension): filename += extension if self.save_screenshot(unique_filename, image_format): self.file.download_file(unique_filename, filename) self.file.delete(unique_filename) return True else: return False
def _active_set(self): sets = self.sets if len(sets) == 0: return None if len(sets) == 1: return sets[0] # create unique trace name unique_trace_name = 'Trc' + unique_alphanumeric_string() self.create_trace(unique_trace_name, self.channels[0]) for set in sets: self.active_set = set if unique_trace_name in self.traces: self.delete_trace(unique_trace_name) return set return None
def save_nonblocking_sweep(self, localfile, test_ports): unique_filename = unique_alphanumeric_string() + '.s2p' scpi = ":MMEM:STOR:TRAC:PORT {0},'{1}',{2},{3}" scpi = scpi.format(1, \ unique_filename, \ 'COMP', \ ','.join(map(str, test_ports))) self._vna.write(scpi) # this saves the file on the ZVA in the folder # C:\Rohde&Schwarz\Nwa\ self._vna.pause(5000) self._vna.file.download_file(unique_filename, localfile) self._vna.file.delete(unique_filename)
def save_active_set_locally(self, filename): extension = None if self.properties.is_zvx(): extension = ".zvx" elif self.properties.is_znx(): extension = ".znx" unique_filename = unique_alphanumeric_string() + extension if not filename.lower().endswith(extension): filename += extension self.save_active_set(unique_filename) current_directory = self.file.directory() self.file.cd(Directory.recall_sets) self.file.download_file(unique_filename, filename) self.file.delete(unique_filename) self.file.cd(current_directory)
def save_active_set_locally(self, filename): # must include suffix filename = self.__add_set_suffix(filename) suffix = Path(filename).suffix # save on VNA in RecallSets temp_file = unique_alphanumeric_string() + suffix self.save_active_set(temp_file) # cd into RecallSets restore_dir = self.file.directory() self.file.cd(Directory.recall_sets) # download set file self.file.download_file(temp_file, filename) # delete temp file from VNA self.file.delete(temp_file) # restore dir self.file.cd(restore_dir)
def measure(self, data_dir, Vgs, Rg, comment, stabilise_time, use_vna, use_chuck, init_bilt, **kwargs): print("===================================") print("Starting acquisition script...") chuck_string = '' vna_string = '' # initialise instruments print("Setting up DC sources and voltmeters...") bilt = Bilt('TCPIP0::192.168.0.2::5025::SOCKET') if init_bilt: # source (bilt, channel, range, filter, slope in V/ms, label): self.sourceVg = sourceVg = BiltVoltageSource( bilt, "I1", "12", "1", 0.005, "Vg") else: self.sourceVg = sourceVg = BiltVoltageSource(bilt, "I1", initialise=False) # voltmeter (bilt, channel, filt, label=None) self.meterVg = meterVg = BiltVoltMeter(bilt, "I5;C1", "2", "Vgm") print("DC sources and voltmeters are set up.") if use_chuck: print("Setting up Yokogawa for chuck voltage...") # connect to the Yoko without initialising, this will lead to # an exception if the Yoko is not properly configured (voltage # source, range 30V, output ON) yoko = Yoko7651('GPIB::3::INSTR', initialise=False, rang=30) chuck_string = '_Vchuck={:.1f}'.format(yoko.get_voltage()) print("Yokogawa is set up.") if use_vna: print("Setting up VNA") self.vna = vna = RohdeSchwarzVNA() vna.open('GPIB', '20') c1 = vna.channel(1) sweeptime = c1.total_sweep_time_ms c1.manual_sweep = True c1.s_parameter_group = c1.to_logical_ports((1, 2)) # cf: https://www.rohde-schwarz.com/webhelp/webhelp_zva/program_examples/basic_tasks/typical_stages_of_a_remote_control_program.htm#Command_Synchronization vna.write("*SRE 32") vna.write("*ESE 1") if not c1.sweep_type == 'SEGM': # need to use not == because != is not implemented in Rohde Schwarz library raise Exception('Please use segmented frequency sweep') # check if the RF power is the same on both ports and for all # frequency segments count = int(vna.query(':SENS:SEGM:COUN?').strip()) vna_pow = None for i in range(1, count + 1): seg_pow = float(vna.query(':SENS:SEGM{}:POW?'.format(i))) if vna_pow is None: vna_pow = seg_pow elif vna_pow is not None and seg_pow == vna_pow: continue else: raise Exception( "Please select the same power for all ports and frequency segments" ) port1autoatt = int(vna.query(':SOUR:POW1:ATT:AUTO?').strip()) port2autoatt = int(vna.query(':SOUR:POW2:ATT:AUTO?').strip()) if port1autoatt or port2autoatt: raise Exception("Please do not use automatic attenuators") port1att = float(vna.query(':SOUR:POW1:ATT?').strip()) port2att = float(vna.query(':SOUR:POW2:ATT?').strip()) if port1att == port2att: vna_pow -= port1att else: raise Exception( "Please select the same attenuators for both ports") vna_string = '_pwr={:.0f}'.format(vna_pow) print("VNA is set up.") # prepare saving DC data timestamp = time.strftime('%Y-%m-%d_%Hh%Mm%Ss') filename = timestamp + vna_string + chuck_string + ('_' + comment if comment else '') self.prepare_saving(os.path.join(data_dir, filename + '.txt')) if use_vna: # prepare saving RF data spectra_fol = os.path.join(data_dir, filename) create_path(spectra_fol) with open(os.path.join(spectra_fol, 'VNAconfig'), 'w') as f: f.write( '# Frequency based segmented sweep setup of Rohde&Schwarz ZVA 67\n' ) f.write('# Attenuator Port 1: {}\n'.format(port1att)) f.write('# Attenuator Port 2: {}\n'.format(port2att)) f.write('# Seg no.\tfstart\tfstop\tpoints\tbwidth\tpow\n') count = int(vna.query(':SENS:SEGM:COUN?').strip()) for i in range(1, count + 1): seg_pow = float( vna.query(':SENS:SEGM{}:POW?'.format(i)).strip()) bwidth = float( vna.query(':SENS:SEGM{}:BWID?'.format(i)).strip()) fstart = float( vna.query(':SENS:SEGM{}:FREQ:STAR?'.format(i)).strip()) fstop = float( vna.query(':SENS:SEGM{}:FREQ:STOP?'.format(i)).strip()) points = int( vna.query(':SENS:SEGM{}:SWE:POIN?'.format(i)).strip()) f.write('{:d}\t{:f}\t{:f}\t{:d}\t{:f}\t{:f}\n'.format( i, fstart, fstop, points, bwidth, seg_pow)) for Vg in Vgs: if self.flags['quit_requested']: print("Stopping acquisition.") return locals() print("Setting Vg = {}".format(Vg)) # set Vg sourceVg.set_voltage(Vg) # wait time.sleep(stabilise_time) # read voltages Vgm = meterVg.get_voltage() # do calculations Ileak = (Vg - Vgm) / Rg # save DC data self.save_row(locals()) if use_vna: # save VNA data print("Getting VNA spectra...") vna.write("INIT1:IMM; *OPC") # display sweep progress progressbar_wait(sweeptime / 1e3) # make sure sweep is really done while not int(vna.query("*ESR?").strip()): time.sleep(0.5) timestamp = time.strftime('%Y-%m-%d_%Hh%Mm%Ss') spectrum_file = timestamp + '_Vg=%2.4f' % (Vg) #vna.channel(1).save_measurement_locally(os.path.join(spectra_fol, spectrum_file), (1,2)) spectrum_file = os.path.join(spectra_fol, spectrum_file + '.s2p') unique_filename = unique_alphanumeric_string() + '.s2p' scpi = ":MMEM:STOR:TRAC:PORT {0},'{1}',{2},{3}" scpi = scpi.format(1, \ unique_filename, \ 'COMP', \ '1,2') vna.write(scpi) # this saves the file on the ZVA in the folder # C:\Rohde&Schwarz\Nwa\ vna.pause(5000) vna.file.download_file(unique_filename, spectrum_file) vna.file.delete(unique_filename) print("Acquisition done.") return locals()