File: srs570.py

package info (click to toggle)
python-pyepics 3.5.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,336 kB
  • sloc: python: 10,539; makefile: 112; javascript: 104; sh: 53
file content (91 lines) | stat: -rwxr-xr-x 3,057 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python 
"""Epics Support for
Stanford Research Systems 570 current amplifier
"""
from .. import Device

VALID_STEPS = [1, 2, 5, 10, 20, 50, 100, 200, 500]
VALID_UNITS = ['pA/V', 'nA/V','uA/V', 'mA/V']

class SRS570(Device):
    """ 
    SRS (Stanford Research Systems) 570 current amplifier
    """

    attrs = ('sens_num', 'sens_unit', 'offset_num', 'offset_unit',
             'offset_sign', 'offset_on', 'off_u_put', 'bias_put',
             'gain_mode', 'filter_type', 'invert_on', 'init.PROC')
    
    _nonpvs = ('_prefix', '_pvs', '_delim', '_nchan', '_chans')
    
    def __init__(self, prefix):
        Device.__init__(self, prefix, delim='',
                        attrs=self.attrs, mutable=False)
        self.initialize()

    def initialize(self, bias=0, gain_mode=0, filter_type=0,
                   invert=False):
        """set initial values"""
        inv_val = 0
        if invert: inv_val = 1
        self.put('gain_mode', gain_mode) # 0 = low noise
        self.put('filter_type', filter_type) # 0  no filter
        self.put('invert_on', inv_val)
        self.put('bias_put', bias)
           
    def set_sensitivity(self, value, units, offset=None, 
                        scale_offset=True):
        "set sensitivity"
        if value not in VALID_STEPS or units not in VALID_UNITS:
            print('invalid input')
            return
        
        ival = VALID_STEPS.index(value)
        uval = VALID_UNITS.index(units)

        self.put('sens_num', ival)
        self.put('sens_unit', uval)
        if scale_offset:
            # scale offset to by 0.1 x sensitivity
            # i.e, a sensitivity of 200 nA/V should 
            # set set the input offset to 20 nA.
            ioff = ival - 3
            uoff = uval
            if ioff < 0:
                ioff = ival + 6
                uoff = uval - 1
            self.put('offset_num',  ioff)
            self.put('offset_unit', uoff)
        if offset is not None:
            self.set_offset(offset)
        self.put('init.PROC', 1)

    def set_offset(self, value):
        self.put('off_u_put', value)

    def increase_sensitivity(self):
        "increase sensitivity by 1 step"
        snum  = self.get('sens_num')
        sunit = self.get('sens_unit')
        if snum == 0:
            snum = 9
            sunit = sunit - 1
            if sunit < 0:
                # was at highest sensitivity
                snum, sunit = 1, 0
        snum = snum - 1
        self.set_sensitivity(VALID_STEPS[snum], VALID_UNITS[sunit])

    def decrease_sensitivity(self):
        "decrease sensitivity by 1 step"
        snum  = self.get('sens_num')
        sunit = self.get('sens_unit')
        if snum == 8:
            snum = -1
            sunit = sunit + 1
            if sunit > 3:
                # was at lowest sensitivity
                snum, sunit = 7, 3
        snum = snum + 1
        self.set_sensitivity(VALID_STEPS[snum], VALID_UNITS[sunit])