-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathxyattenuators.py
131 lines (111 loc) · 3.68 KB
/
xyattenuators.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Copyright (C) 2007 Matthew Neeley, Isaac Storch
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
### BEGIN NODE INFO
[info]
name = XY Attenuator Server
version = 1.0
description =
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
from labrad.gpib import GPIBManagedServer
from labrad.server import setting
from labrad import types as T
from twisted.internet.defer import inlineCallbacks, returnValue
from numpy import floor
class XYAttenuatorServer(GPIBManagedServer):
name = 'XY Attenuator Server'
deviceName = 'Hewlett-Packard 11713A'
deviceIdentFunc = 'identify_device'
@inlineCallbacks
def setAtten(self, c, val, commands):
"""Helper method to set either the X or Y attenuation.
This method looks up the desired attenuation and gpib
command in the provided dictionary.
"""
dev = self.selectedDevice(c)
if val not in commands.keys():
raise Exception('Invalid attenuation value.')
yield dev.write(commands[val])
returnValue(T.Value(val, 'dB'))
# settings
@setting(1000, server='s', address='s', idn='s')
def identify_device(self, c, server, address, idn=None):
devices = [('ADR GPIB Bus', 'GPIB0::28'),
('DR GPIB Bus', 'GPIB0::28'),
('Twins IBCL GPIB Bus', 'ProbeStation GPIB-422CT::28'),
('T1000 IBCL GPIB Bus', 'T1000 GPIB-422CT::28')]
if (server, address) in devices:
return self.deviceName
@setting(10000, "X Atten", data=['v[dB]'], returns=['v[dB]'])
def x_atten(self, c, data):
"""Set the X attenuation.
Allowed values of are 0, 1, 2, ... 11 dB.
"""
val = int(data.value)
return self.setAtten(c, val, XattnDict)
@setting(10001, "Y Atten", data=['v[dB]'], returns=['v[dB]'])
def y_atten(self, c, data):
"""Set the Y attenuation.
Allowed values are 0, 10, 20, ... 70 dB.
"""
val = int(data.value)
return self.setAtten(c, val, YattnDict)
@setting(10002, "Total Atten", data=['v[dB]'], returns=['v[dB]v[dB]'])
def total_atten(self, c, data):
"""Set the total attenuation on X and Y channels (connected in series).
Allowed values of are 0, 1, 2, ... 79 dB.
Note: use x_atten and y_atten to go to 80 and 81 dB
"""
val = int(data.value)
x = yield self.setAtten(c, val%10, XattnDict)
y = yield self.setAtten(c, floor(val/10)*10, YattnDict)
returnValue((x,y))
# commands for X attenuation
XattnDict = {
0: 'B1234',
1: 'A1B234',
2: 'A2B134',
3: 'A12B34',
4: 'A3B124',
5: 'A13B24',
6: 'A23B14',
7: 'A123B4',
8: 'A34B12',
9: 'A134B2',
10: 'A234B1',
11: 'A1234'
}
# commands for Y attenuation
YattnDict = {
0: 'B5678',
10: 'A5B678',
20: 'A6B578',
30: 'A56B78',
40: 'A7B568',
50: 'A57B68',
60: 'A67B58',
70: 'A567B8'
}
__server__ = XYAttenuatorServer()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)