""" .. module:: skrf.vi.vna.hp.hp8720b ================================================= HP 8720B (:mod:`skrf.vi.vna.hp.hp8720b`) ================================================= HP8720B Class ================ .. autosummary:: :nosignatures: :toctree: generated/ """ import numpy as np import skrf import skrf.network from skrf.vi.vna import VNA class HP8720B(VNA): ''' HP 8720B driver, created by modifying the 8510C driver and commenting out the additional sweep options. The instrument natively supports (3/11/21/51/101/201/401/801/1601pts). Segmented sweeps occur automatically when the user requests a short or irregularly spaced sweep (see "Advanced Example" below). The 8510 actually does support sweeps other than 51/101/201/401/801pts, but only in a separate mode (segmented sweep mode) and with significant restrictions. This driver knows how to handle segmented sweep mode to get what it wants. Examples ============ Basic one-port: .. code-block:: python vna = skrf.vi.vna.hp.HP8720B(address='GPIB0::16::INSTR', backend='C:\\WINDOWS\\system32\\visa32.dll') vna.set_frequency_sweep(2e9,3e9,201) vna.get_snp_network(ports=(1,)) Basic two-port: .. code-block:: python vna = skrf.vi.vna.hp.HP8720B(address='GPIB0::16::INSTR', backend='C:\\WINDOWS\\system32\\visa32.dll') vna.set_frequency_sweep(2e9,3e9,201) vna.get_snp_network(ports=(1,2)) Intermediate example -- note that 1001 point sweeps are not natively supported by the instrument; instead uses the analysers frequency segment mode. Based off example 4B in the 8720B programming manual. Sometimes breaks after the first output, for which the analyser requires a hard reset. .. code-block:: python vna = skrf.vi.vna.hp.HP8720B(address='GPIB0::16::INSTR', backend='C:\\WINDOWS\\system32\\visa32.dll') vna.set_frequency_sweep(2e9,3e9,1001) vna.get_snp_network(ports=(1,2)) ''' min_hz = 130E6 #: Minimum frequency supported by instrument max_hz = 20E9 #: Maximum frequency supported by instrument def __init__(self, address : str, backend : str = "@py", **kwargs): super().__init__(address, backend, **kwargs) # Tested 2024-05-29: # HP8720B # NI GPIB to USB # address="gpib0,16::INSTR", backend='C:\\WINDOWS\\system32\\visa32.dll' # 8720s are slow. This check ensures we won't wait 60s for connection error. self._resource.timeout = 2_000 * (3_000 / self.if_bandwidth) # Speed dependent on IF bandwidth selected id_str = self.query('OUTPIDEN;') assert('8720' in id_str) # example: 'HP8720B,0,1.01' self._resource.read_termination = '\n' self.read_raw = self._resource.read_raw self.min_hz = self.freq_start self.max_hz = self.freq_stop self.write('CONT;') self.write('DEBUON;') # Debug HPIB mode ON to displace instrument commands on the instrument screen # DEBUOFF to turn off (or just remove command) # Compound sweeps can be added in the future using the subsweep menu commands @property def id(self): ''' Instrument ID string ''' return self.query("OUTPIDEN;") def reset(self): ''' Preset instrument. ''' self.write("PRES;") self.wait_until_finished() def clear(self): self._resource.clear() def wait_until_finished(self): self.query("OUTPIDEN;") def get_snp_network(self, ports, **kwargs): ''' MAIN METHOD for obtaining S parameters, like get_snp_network((1,)) or get_snp_network((1,2)). ''' ports = tuple(ports) sweep = kwargs.get("sweep", True) if ports==(1,): self.write('S11;') return self.one_port(fresh_sweep=sweep) elif ports==(2,): self.write('S22;') return self.one_port(fresh_sweep=sweep) elif ports==(1,2) or ports==(2,1): return self.two_port(fresh_sweep=sweep) else: raise(ValueError("Invalid ports "+str(ports)+". Options: (1,) (2,) (1,2).")) def get_switch_terms(self, ports=(1, 2), **kwargs): ''' Returns (forward_one_port,reverse_one_port) switch terms. The ports short be connected with a half decent THRU before calling. These measure how much signal is reflected from the imperfect switched termination on the non-stimulated port. ''' raise(NotImplementedError("Not yet implemented for HP8720B")) @property def error(self): ''' Error from OUTPERRO ''' return self.query('OUTPERRO') @property def if_bandwidth(self): ''' Current IF Bandwidth [Hz] ''' return float(self.query('IFBW?')) @if_bandwidth.setter def if_bandwidth(self, if_bw): ''' Allowed values (in Hz): 3000, 1000, 300, 100, 30, and 10''' if if_bw in [3,10,30,100,300,1000,3000]: self.write(f'IFBW {if_bw}') # Changing the timeout due to change IF BW causing the VNA to be slower self._resource.timeout = 2_000 * (3_000 / self.if_bandwidth) else: raise(ValueError('Takes a value from [3,10,30,100,300,1000,3000]')) @property def is_continuous(self): ''' True if sweep mode is continuous. Can be set. ''' answer_dict={'1':False,'0':True} return answer_dict[self.query('TRIG?')] @is_continuous.setter def is_continuous(self, choice): if choice: self.write('CONT;') elif not choice: self.write('SING;') else: raise(ValueError('takes a boolean')) @property def averaging(self): ''' Averaging factor for AVERON ''' return int(float(self.query('AVERFACT?'))) @averaging.setter def averaging(self, factor): if not factor: self.write('AVEROFF') elif isinstance(factor, int): self.write(f'AVERON; AVERFACT {factor};') else: raise(ValueError('takes an interger')) @property def _frequency(self): ''' Frequencies of non-compound sweep ''' freq=skrf.Frequency( self.freq_start, self.freq_stop, self._npoints, unit='hz' ) return freq @property def frequency(self): ''' Frequencies of compound sweep ''' return self._frequency @frequency.setter def frequency(self, frequency_obj: skrf.Frequency): ''' List sweep using hz, an array of frequencies. If hz is too long, multiple sweeps will automatically be performed.''' hz = frequency_obj.f valid = (self.min_hz<=hz) & (hz<=self.max_hz) if not np.all(valid): print("set_frequency called with %i/%i points out of VNA frequency range. Dropping them." %(np.sum(valid),len(valid))) hz = hz[valid] def set_frequency_sweep(self, f_start, f_stop, f_npoints, **kwargs): ''' Interprets units and calls set_frequency_step ''' f_unit = kwargs.get("f_unit", "hz").lower() if f_unit != "hz": hz_start = self.to_hz(f_start, f_unit) hz_stop = self.to_hz(f_stop, f_unit) else: hz_start, hz_stop = f_start, f_stop self.set_frequency_step(hz_start, hz_stop, f_npoints) def set_frequency_step(self, hz_start, hz_stop, npoint=801): ''' Step (slow, synthesized) sweep + logic to handle lots of npoint. ''' if (self._instrument_natively_supports_steps(npoint)): self._set_instrument_step_state(hz_start, hz_stop, npoint) @property def freq_start(self): ''' Start frequency [hz] ''' return float(self.query('STAR;OUTPACTI;')) @freq_start.setter def freq_start(self, new_start_hz): self.write(f'STAR {new_start_hz};') @property def freq_stop(self): ''' Stop frequency [hz] ''' return float(self.query('STOP;OUTPACTI;')) @freq_stop.setter def freq_stop(self, new_stop_hz): self.write(f'STOP {new_stop_hz};') @property def _npoints(self): ''' Number of points in non-compound sweep ''' instrument_ret_val = self.query('POIN;OUTPACTI;') v1 = instrument_ret_val.strip() v2 = float(v1) v3 = int(v2) return v3 @property def npoints(self): ''' Number of points in compound sweep (if programmed) or non-compound sweep ''' return self._npoints @npoints.setter def npoints(self, npoint): ''' Set number of points in sweep''' hz_start, hz_stop = self.freq_start, self.freq_stop if (self._instrument_natively_supports_steps(npoint)): self._set_instrument_step_state(hz_start, hz_stop, npoint) def _instrument_natively_supports_steps(self, npoint): if npoint in [3,11,21,51,101,201,401,801,1601]: return True if npoint<=1601: # Supported with a single native list sweep commented as only work once then breaks connection return True return False def _set_instrument_step_state(self, hz_start, hz_stop, npoint=801): assert(self._instrument_natively_supports_steps(npoint)) if self._resource is not None: self._resource.clear() if npoint in [3,11,21,51,101,201,401,801,1601]: # If it's a directly supported step sweep npoints, use regular sweep self.write(f'STAR {hz_start}; STOP {hz_stop}; POIN {npoint};') elif npoint<=1601: # List sweep lets us support, for example, 401