-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsr7280.py
384 lines (317 loc) · 10.6 KB
/
sr7280.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# Copyright []
#
# 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 = Amatek 7280 Lock-in amplifier
version = 0.1
description =
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
from labrad.server import setting
from labrad.gpib import GPIBManagedServer, GPIBDeviceWrapper
from twisted.internet.defer import inlineCallbacks, returnValue
import labrad.units as units
class SR7280Wrapper(GPIBDeviceWrapper):
@inlineCallbacks
def set_imode(self,n):
yield self.write("IMODE %i" %n)
@inlineCallbacks
def get_imode(self):
mode = yield self.query('IMODE')
returnValue(mode)
@inlineCallbacks
def set_vmode(self,n):
yield self.write("VMODE %i" %n)
@inlineCallbacks
def get_vmode(self):
mode = yield self.query('VMODE')
returnValue(mode)
@inlineCallbacks
def set_cp(self,n):
yield self.write("CP %i" %n)
@inlineCallbacks
def get_cp(self):
cp = yield self.query('CP')
returnValue(cp)
@inlineCallbacks
def set_float(self,n):
yield self.write("FLOAT %i" %n)
@inlineCallbacks
def get_float(self):
flt = yield self.query("FLOAT")
returnValue(flt)
@inlineCallbacks
def get_sens(self):
sen = yield self.query("SEN.")
returnValue(sen)
@inlineCallbacks
def get_sens_num(self):
sen = yield self.query("SEN")
returnValue(sen)
@inlineCallbacks
def channel_set_sensitivity(self, n): #SEN
yield self.write('SEN %i' % n)
@inlineCallbacks
def do_auto_sensitivity(self):
yield self.write('AS')
@inlineCallbacks
def do_auto_measure(self):
yield self.write('ASM')
@inlineCallbacks
def set_ac_gain(self,n):
yield self.write("ACGAIN %i" %n)
@inlineCallbacks
def get_ac_gain(self):
gain = yield self.query("ACGAIN")
returnValue(gain)
@inlineCallbacks
def set_is_acgain_automatic(self,n):
yield self.write("AUTOMATIC %i" %n)
@inlineCallbacks
def get_is_acgain_automatic(self):
is_auto = yield self.query("AUTOMATIC")
returnValue(is_auto)
@inlineCallbacks
def set_line_frequency_filter(self,n1,n2):
yield self.write("LF %i %i" %(n1,n2))
@inlineCallbacks
def get_line_frequency_filter(self):
lf = yield self.query("LF")
returnValue(lf)
@inlineCallbacks
def read_freq(self,flt):
suf = '.' if flt else ''
frq = yield self.query("FRQ%s"%suf)
returnValue(frq)
@inlineCallbacks
def read_x(self,float_mode=False):
suffix = '.' if float_mode else ''
x_out = yield self.query("X%s" %suffix)
returnValue(x_out)
@inlineCallbacks
def read_y(self,float_mode=False):
suffix = '.' if float_mode else ''
y_out = yield self.query("Y%s" %suffix)
returnValue(y_out)
@inlineCallbacks
def read_mag(self,flt):
suf = '.' if flt else ''
mag = yield self.query("MAG%s"%suf)
returnValue(mag)
@inlineCallbacks
def read_phase(self,flt):
suf = '.' if flt else ''
pha = yield self.query("PHA%s"%suf)
returnValue(pha)
# overload
@inlineCallbacks
def get_overload(self):
ovld = yield self.query("N")
returnValue(int(ovld))
# auxiliary inputs
@inlineCallbacks
def read_adc(self,n):
value = yield self.query("ADC.%i"%n)
returnValue(value)
class SR7280Server(GPIBManagedServer):
name = 'sr_7280_lockin'
deviceName = '7280 DSP Lock-In'
deviceIdentFunc = 'identify_device'
deviceWrapper = SR7280Wrapper
@setting(9001, server='s', address='s')
def identify_device(self, c, server, address):
print 'identifying:', server, address
try:
s = self.client[server]
p = s.packet()
p.address(address)
p.write('ID\n')
p.read()
ans = yield p.send()
resp = ans.read
print 'got ident response:', resp
if resp == '7280':
returnValue(self.deviceName)
except Exception, e:
print 'failed:', e
raise
@setting(101, n=['i'],returns=[])
def set_imode(self,c,n=1):
if not (n in [0,1,2,3]):
print("Invalid Imode setting")
raise
dev = self.selectedDevice(c)
yield dev.set_imode(n)
@setting(102,returns='i')
def get_imode(self,c):
dev = self.selectedDevice(c)
imode = yield dev.get_imode()
returnValue(int(imode))
@setting(103,'set_voltage_input_mode',n=['i'],returns=[])
def set_vmode(self,c,n=1):
if not (n in [0,1,2,3]):
print("Invalid Vmode setting")
raise
dev = self.selectedDevice(c)
yield dev.set_vmode(n)
@setting(104,'get_voltage_input_mode',returns='i')
def get_vmode(self,c):
dev = self.selectedDevice(c)
vmode = yield dev.get_vmode()
returnValue(int(vmode))
@setting(105,'set_coupling_mode',n=['i'],returns=[])
def set_cp(self,c,n=1):
if not (n in [0,1]):
print("Invalid CP setting")
raise
dev = self.selectedDevice(c)
yield dev.set_cp(n)
@setting(106,'get_coupling_mode',returns='i')
def get_cp(self,c):
dev = self.selectedDevice(c)
cp = yield dev.get_cp()
returnValue(int(cp))
@setting(107,'set_ground_float',n=['i'],returns=[])
def set_float(self,c,n):
if not (n in [0,1]):
print("Invalid Float setting")
raise
dev = self.selectedDevice(c)
yield dev.set_float(n)
@setting(108,'get_ground_float',returns='i')
def get_float(self,c):
dev = self.selectedDevice(c)
flt = yield dev.get_float()
returnValue(int(flt))
@setting(109, n=['i'], returns=[])
def set_sensitivity(self,c,n=3):
if not (n in range(3,28)):
print("Invalid sensitivity setting")
raise
dev = self.selectedDevice(c)
yield dev.channel_set_sensitivity(n)
@setting(110,returns=['v[V]','v[A]'])
def get_sensitivity(self,c):
dev = self.selectedDevice(c)
sens = yield dev.get_sens()
mode = yield dev.get_imode()
ans = float(sens) * units.V if mode=='0' else float(sens) * units.A # Units are volts only in mode 0
returnValue(ans)
@setting(111,returns='i')
def get_sensitivity_number(self,c):
dev = self.selectedDevice(c)
sen = yield dev.get_sens_num()
returnValue(int(sen))
@setting(112,returns=[])
def do_auto_sensitivity(self,c):
dev = self.selectedDevice(c)
yield dev.do_auto_sensitivity()
@setting(113,returns=[])
def do_auto_measure(self,c):
dev = self.selectedDevice(c)
yield dev.do_auto_measure()
@setting(114,n=['i'],returns=[])
def set_ac_gain(self,c,n):
if not (n in range(11)):
print("Invalid AC range setting")
raise
dev = self.selectedDevice(c)
yield dev.set_ac_gain(n)
@setting(115,returns='i')
def get_ac_gain(self,c):
dev = self.selectedDevice(c)
gain = yield dev.get_ac_gain()
returnValue(int(gain))
@setting(116,n=['i'],returns=[])
def set_is_acgain_automatic(self,c,n):
if not (n in [0,1]):
print("Invalid AC Gain automatic setting")
raise
dev = self.selectedDevice(c)
yield dev.set_is_acgain_automatic(n)
@setting(117,returns='i')
def get_is_acgain_automatic(self,c):
dev = self.selectedDevice(c)
is_auto =yield dev.get_is_acgain_automatic()
returnValue(int(is_auto))
@setting(118,n1=['i'],n2=['i'],returns=[])
def set_line_frequency_filter(self,c,n1,n2):
if not (n1 in [0,1,2,3] and n2 in [0,1]):
print("Invalid line filter setting")
raise
dev = self.selectedDevice(c)
yield dev.set_line_frequency_filter(n1,n2)
@setting(119,returns='*i')
def get_line_frequency_filter(self,c):
dev = self.selectedDevice(c)
nf = yield dev.get_line_frequency_filter()
returnValue([int(nf[0]),int(nf[2])])
@setting(200,float_mode='b',returns=[])
def freq(self,c,float_mode=True):
dev = self.selectedDevice(c)
frq = yield dev.read_freq(float_mode)
ans = float(frq) if float_mode else int(frq)
returnValue(ans)
@setting(501,float_mode='b',returns=['i','v'])
def x(self,c,float_mode=True):
dev = self.selectedDevice(c)
x_out = yield dev.read_x(float_mode)
if not float_mode:
returnValue(int(x_out))
else:
returnValue(float(x_out))
@setting(502,float_mode='b',returns=['i','v')
def y(self,c,float_mode=True):
dev = self.selectedDevice(c)
y_out = yield dev.read_y(float_mode)
if not float_mode:
returnValue(int(y_out))
else:
returnValue(float(y_out))
@setting(503,float_mode='b',returns=['v','i'])
def theta(self,c,float_mode=True):
dev=self.selectedDevice(c)
phs=yield dev.read_phase(float_mode)
val=float(phs) if float_mode else int(phs)
returnValue(val)
@setting(504,float_mode='b',returns=['i','v'])
def r(self,c,float_mode=True):
dev = self.selectedDevice(c)
mag = yield dev.read_mag(float_mode)
if not float_mode:
returnValue(int(mag))
else:
returnValue(float(mag))
@setting(800,n='i',returns='v')
def read_adc(self,c,n):
dev = self.selectedDevice(c)
value = yield dev.read_adc(n)
returnValue(float(value))
@setting(1000,returns='i')
def get_overload(self, c):
dev=self.selectedDevice(c)
overload = yield dev.get_overload()
returnValue(overload)
__server__ = SR7280Server()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)