camrasdevices.py 1.81 KB
Newer Older
1
2
import hpib
from hpib import HpibDevice
3
import threading
4

5
6
class CamrasHpibDevice(HpibDevice):
    """Wrapper around HPIB commands"""
7
8
9
10

    _CamrasHpibDevice__port = None
    _CamrasHpibDevice__port_lock = threading.Lock()

11
    def __init__(self, address):
12
13
14
        if not CamrasHpibDevice._CamrasHpibDevice__port:
            with CamrasHpibDevice._CamrasHpibDevice__port_lock:
                _port = hpib.PrologixGpibUsb()
15
        super(CamrasHpibDevice, self).__init__(address, _port)
16
17
18
19
        self.__frequency = 0

    @property
    def frequency(self):
20
21
22
23
        """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))
24
25
26
27
        return int(float(self.query("freq?")))

    @frequency.setter
    def frequency(self, freq):
28
        """Set the device to the specified frequency. Throws a RuntimeError if failed"""
29
30
        self.command("freq {:d} Hz".format(int(freq)))
        new_freq = self.frequency
31
        if int(new_freq) != int(freq):
32
33
34
35
36
37
38
39
40
            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)

41
class LocalOscillator(CamrasHpibDevice):
42
43
44
    """Wrapper around HPIB commands for the local oscillator"""

    def __init__(self):
45
        super(LocalOscillator, self).__init__(28)
46

47
48
class ClockGenerator(CamrasHpibDevice):
    """Wrapper around HPIB commands for the clock generator (should be at 140MHz)"""
49
50
51

    def __init__(self):
        super(SignalGenerator, self).__init__(14)