import hpib from hpib import HpibDevice import threading class CamrasHpibDevice(HpibDevice): """Wrapper around HPIB commands""" _CamrasHpibDevice__port = None _CamrasHpibDevice__port_lock = threading.Lock() def __init__(self, address): if not CamrasHpibDevice._CamrasHpibDevice__port: with CamrasHpibDevice._CamrasHpibDevice__port_lock: _port = hpib.PrologixGpibUsb() super(CamrasHpibDevice, self).__init__(address, _port) self.__frequency = 0 @property def frequency(self): """Returns the frequency (in Hz) of the device. Throws a RuntimeError if no response""" freq_str = self.query("freq?") if len(freq_str)==0: raise RuntimeError("Camras device at address {} is not responding".format(self._hpib_address)) return int(float(self.query("freq?"))) @frequency.setter def frequency(self, freq): """Set the device to the specified frequency. Throws a RuntimeError if failed""" self.command("freq {:d} Hz".format(int(freq))) new_freq = self.frequency if int(new_freq) != int(freq): raise RuntimeError("Setting frequency failed: tried to set to {}, it is now {}".format( freq, new_freq)) class Receiver(CamrasHpibDevice): """Wrapper around HPIB commands for the Rohde & Schwartz receiver""" def __init__(self): super(Receiver, self).__init__(1) class LocalOscillator(CamrasHpibDevice): """Wrapper around HPIB commands for the local oscillator""" def __init__(self): super(LocalOscillator, self).__init__(28) class ClockGenerator(CamrasHpibDevice): """Wrapper around HPIB commands for the clock generator (should be at 140MHz)""" def __init__(self): super(SignalGenerator, self).__init__(14)