camrasdevices.py 1.94 KB
Newer Older
1
2
import hpib
from hpib import HpibDevice
3
4
import astropy.units as u
from astropy.units import Quantity
5
import threading
6

7
8
class CamrasHpibDevice(HpibDevice):
    """Wrapper around HPIB commands"""
9
10
11
12

    _CamrasHpibDevice__port = None
    _CamrasHpibDevice__port_lock = threading.Lock()

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

    @property
    def frequency(self):
21
22
        """Returns the frequency of the device as an astropy Quantity.
        Throws a RuntimeError if no response"""
23
24
25
        freq_str = self.query("freq?")
        if len(freq_str)==0:
            raise RuntimeError("Camras device at address {} is not responding".format(self._hpib_address))
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
26
        return int(float(freq_str)) * u.Hz
27
28
29

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

45
class LocalOscillator(CamrasHpibDevice):
46
47
48
    """Wrapper around HPIB commands for the local oscillator"""

    def __init__(self):
49
        super(LocalOscillator, self).__init__(28)
50

51
52
class ClockGenerator(CamrasHpibDevice):
    """Wrapper around HPIB commands for the clock generator (should be at 140MHz)"""
53
54
55

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