camrasdevices.py 1.54 KB
Newer Older
1
2
3
import hpib
from hpib import HpibDevice

4
5
_port = hpib.PrologixGpibUsb()

6
7
8
class CamrasHpibDevice(HpibDevice):
    """Wrapper around HPIB commands"""
    def __init__(self, address):
9
        super(CamrasHpibDevice, self).__init__(address, _port)
10
11
12
13
        self.__frequency = 0

    @property
    def frequency(self):
14
15
16
17
        """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))
18
19
20
21
        return int(float(self.query("freq?")))

    @frequency.setter
    def frequency(self, freq):
22
        """Set the device to the specified frequency. Throws a RuntimeError if failed"""
23
24
25
26
27
28
29
30
31
32
33
34
        self.command("freq {:d} Hz".format(int(freq)))
        new_freq = self.frequency
        if new_freq != 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)

35
class LocalOscillator(CamrasHpibDevice):
36
37
38
    """Wrapper around HPIB commands for the local oscillator"""

    def __init__(self):
39
        super(LocalOscillator, self).__init__(28)
40
41
42
43
44
45

class SignalGenerator(CamrasHpibDevice):
    """Wrapper around HPIB commands for the signal generator"""

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