-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsr860.py
910 lines (805 loc) · 28.8 KB
/
sr860.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# Copyright (C) 2011 Peter O'Malley/Charles Neill
#
# 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 = sr860
version = 2.7
description =
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
from math import log10
from labrad import types as T, gpib, units
from labrad.server import setting
from labrad.gpib import GPIBManagedServer, GPIBDeviceWrapper
from twisted.internet.defer import inlineCallbacks, returnValue
import numpy as np
def getTC(i):
''' converts from the integer label used by the SR860 to a time '''
if i < 0:
return getTC(0)
elif i > 21:
return getTC(21)
elif i % 2 == 0:
return 10**(-6 + i/2)
else:
return 3*10**(-6 + i/2)
def getSensitivity(i):
''' converts form the integer label used by the SR860 to a sensitivity '''
if i < 0:
return getSensitivity(0)
elif i > 27:
return getSensitvity(27)
elif i % 3 == 0:
return 10**(-i/3)
elif i % 3 == 1:
return 5 * 10**(-i/3)
else:
return 2 * 10**(-i/3)
def getSensitivityInt(v, mode):
''' converty from real sensitivity to an integer value taken by the sr860'''
if mode == 0:
sens = int(round(3*log10(v)))+26
else:
sens = int(round(3*log10(v)))+2
return sens
def getTCInt(t):
''' convert from real sensitivity values to an integer value taken by the sr860'''
timeconstant = int(2+round(2*log10(t)))+10
return timeconstant
def getSensitivityInt(v, mode):
''' converty from real sensitivity to an integer value taken by the sr860'''
if mode == 0:
sens = -int(round(3*log10(v)))
else:
sens = -int(round(3*log10(v*1e6)))
return sens
class sr860Wrapper(GPIBDeviceWrapper):
@inlineCallbacks
def inputMode(self):
mode = yield self.query('ISRC?')
returnValue(int(mode))
@inlineCallbacks
def tbmode(self, mode = None):
if mode is None:
resp = yield self.query('TBMODE?')
returnValue(int(resp))
else:
yield self.write('TBMODE ' + str(mode))
resp = yield self.query('TBMODE?')
returnValue(int(resp))
@inlineCallbacks
def freqext(self):
resp = yield self.query('FREQEXT?')
returnValue(float(resp))
@inlineCallbacks
def phase(self, ph = None):
if ph is None:
resp = yield self.query('PHAS?')
returnValue(float(resp))
else:
yield self.write('PHAS ' + str(ph))
resp = yield self.query('PHAS?')
returnValue(float(resp))
@inlineCallbacks
def reference(self,ref = None):
if ref is None:
resp = yield self.query('RSRC?')
returnValue(int(resp))
else:
yield self.write('RSRC ' + str(ref))
resp = yield self.query('RSRC?')
returnValue(int(resp))
@inlineCallbacks
def frequency(self, f = None):
if f is None:
resp = yield self.query('FREQ?')
returnValue(float(resp))
else:
yield self.write('FREQ ' + str(f))
resp = yield self.query('FREQ?')
returnValue(float(resp))
@inlineCallbacks
def external_reference_slope(self, ers = None):
if ers is None:
resp = yield self.query('RSLP?')
returnValue(int(resp))
else:
yield self.write('RSLP ' + str(ers))
resp = yield self.query('RSLP?')
returnValue(resp)
@inlineCallbacks
def harmonic(self, h = None):
if h is None:
resp = yield self.query('HARM?')
returnValue(int(resp))
else:
yield self.write('HARM ' + str(h))
resp = yield self.query('HARM?')
returnValue(int(resp))
@inlineCallbacks
def gnd_mode(self, mode = None):
if mode is None:
resp = yield self.query('IGND?')
returnValue(int(resp))
else:
yield self.write('IGND ' + str(mode))
resp = yield self.query('IGND?')
returnValue(int(resp))
@inlineCallbacks
def curr_gain(self, gain = None):
if gain is None:
resp = yield self.query('ICUR?')
returnValue(int(resp))
else:
yield self.write('ICUR ' + str(gain))
resp = yield self.query('ICUR?')
returnValue(int(resp))
@inlineCallbacks
def sig_lvl(self):
resp = yield self.query('ILVL?')
returnValue(int(resp))
@inlineCallbacks
def sine_out_amplitude(self, amp = None):
if amp is None:
resp = yield self.query('SLVL?')
returnValue(float(resp))
else:
yield self.write('SLVL ' + str(amp))
resp = yield self.query('SLVL?')
returnValue(float(resp))
@inlineCallbacks
def sine_offset(self,offset = None):
if offset is None:
resp = yield self.query('SOFF?')
returnValue(float(resp))
else:
if float(offset) < -5 or float(offset) > 5:
raise ValueError("Offset must be between -5 and +5")
else:
yield self.write('SOFF ' + str(offset))
resp = yield self.query('SOFF?')
returnValue(float(resp))
@inlineCallbacks
def sine_ref(self, ref = None):
if ref is None:
resp = yield self.query('REFM?')
returnValue(int(resp))
else:
yield self.write('REFM ' + str(ref))
resp = yield self.query('REFM?')
returnValue(int(resp))
@inlineCallbacks
def trigger_sign(self, sign = None):
if sign is None:
resp = yield self.query('RTRG?')
returnValue(int(resp))
else:
yield self.write('RTRG ' + str(sign))
resp = yield self.query('RTRG?')
returnValue(int(resp))
@inlineCallbacks
def trigger_z(self, z_in = None):
if z_in is None:
resp = yield self.query('REFZ?')
returnValue(int(resp))
else:
yield self.write('REFZ ' + str(z_in))
resp = yield self.query('REFZ?')
returnValue(int(resp))
@inlineCallbacks
def input_mode(self, mode = None):
if mode is None:
resp = yield self.query('IVMD?')
returnValue(int(resp))
else:
yield self.write('IVMD ' + str(mode))
resp = yield self.query('IVMD?')
returnValue(int(resp))
@inlineCallbacks
def voltage_mode(self, mode = None):
if mode is None:
resp = yield self.query('ISRC?')
returnValue(int(resp))
else:
yield self.write('ISRC ' + str(mode))
resp = yield self.query('ISRC?')
returnValue(int(resp))
@inlineCallbacks
def voltage_coupling(self, mode = None):
if mode is None:
resp = yield self.query('ICPL?')
returnValue(int(resp))
else:
yield self.write('ICPL ' + str(mode))
resp = yield self.query('ICPL?')
returnValue(int(resp))
@inlineCallbacks
def input_rng(self, mode = None):
if mode is None:
resp = yield self.query('IRNG?')
returnValue(int(resp))
else:
yield self.write('IRNG ' + str(mode))
resp = yield self.query('IRNG?')
returnValue(int(resp))
@inlineCallbacks
def aux_input(self, n):
resp = yield self.query('OAUX? ' + str(n))
returnValue(float(resp))
@inlineCallbacks
def aux_output(self, n, v = None):
if v is None:
resp = yield self.query('AUXV? ' + str(n))
returnValue(float(resp))
else:
yield self.write('AUXV ' + str(n) + ', ' + str(v));
returnValue(v)
@inlineCallbacks
def x(self):
resp = yield self.query('OUTP? 0')
returnValue(float(resp))
@inlineCallbacks
def y(self):
resp = yield self.query('OUTP? 1')
returnValue(float(resp))
@inlineCallbacks
def r(self):
resp = yield self.query('OUTP? 2')
returnValue(float(resp))
@inlineCallbacks
def theta(self):
resp = yield self.query('OUTP? 3')
returnValue(float(resp))
@inlineCallbacks
def xnoise(self):
resp = yield self.query('OUTP? 8')
returnValue(float(resp))
@inlineCallbacks
def ynoise(self):
resp = yield self.query('OUTP? 9')
returnValue(float(resp))
@inlineCallbacks
def get_xy(self):
resp = yield self.query('SNAP? 0,1')
returnValue(resp)
@inlineCallbacks
def get_rt(self):
resp = yield self.query('SNAP? 2,3')
returnValue(resp)
@inlineCallbacks
def autorange(self):
resp = yield self.write('ARNG')
returnValue(resp)
@inlineCallbacks
def autoscale(self):
resp = yield self.write('ASCL')
returnValue(resp)
@inlineCallbacks
def cout_xy_rt(self, chn, set = None):
if set is None:
resp = yield self.query('COUT? ' + str(chn))
returnValue(resp)
else:
yield self.write('COUT ' + str(chn) + ',' + str(set))
resp = yield self.query('COUT? ' + str(chn))
returnValue(resp)
@inlineCallbacks
def cout_exp(self,axis, exp = None):
if exp is None:
resp = yield self.query('CEXP? ' + str(axis))
returnValue(resp)
else:
yield self.write('CEXP ' + str(axis) + ',' + str(exp))
resp = yield self.query('CEXP? ' + str(axis))
returnValue(resp)
@inlineCallbacks
def time_constant(self, i=None):
if i is None:
resp = yield self.query("OFLT?")
returnValue(getTC(int(resp)))
else:
yield self.write('OFLT ' + str(i))
returnValue(getTC(i))
@inlineCallbacks
def sensitivity(self, i=None):
if i is None:
resp = yield self.query("SCAL?")
returnValue(getSensitivity(int(resp)))
else:
yield self.write('SCAL ' + str(i))
resp = yield self.query("SCAL?")
returnValue(getSensitivity(int(resp)))
@inlineCallbacks
def auto_gain(self):
yield self.write("AGAN");
done = False
resp = yield self.query("*STB? 1")
while resp != '0':
resp = yield self.query("*STB? 1")
print "Waiting for auto gain to finish..."
@inlineCallbacks
def filter_slope(self, i=None):
if i is None:
resp = yield self.query("OFSL?")
returnValue(int(resp))
else:
yield self.write('OFSL ' + str(i))
returnValue(i)
class sr860Server(GPIBManagedServer):
name = 'sr860'
deviceName = 'Stanford_Research_Systems SR860'
# deviceIdentFunc = 'identify_device'
deviceWrapper = sr860Wrapper
# @setting(9988, 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_termination('\r')
# p.read_termination('\r')
# p.write('*IDN?')
# p.read()
# p.write('*IDN?')
# p.read()
# ans = yield p.send()
# resp = ans.read[1]
# print 'got ident response:', resp
# if resp == 'Stanford_Research_Systems,SR860,003329,V1.47':
# returnValue(self.deviceName)
# except Exception, e:
# print 'failed:', e
# print 'what what...'
# raise
@setting(99, 'outputUnit', returns='?')
def outputUnit(self, c):
''' returns a labrad unit, V or A, for what the main output type is. (R, X, Y) '''
dev = self.selectedDevice(c)
mode = yield dev.input_mode()
if int(mode) == 0:
returnValue(units.V)
elif int(mode) == 1:
returnValue(units.A)
@setting(101, 'tb_Mode', mode='i', returns='i')
def tb_mode(self, c, mode = None):
''' sets/gets the timebase mode (auto = 0 ; internal = 1) '''
dev = self.selectedDevice(c)
if mode is None:
resp = yield dev.tbmode()
returnValue(int(resp))
else:
resp = yield dev.tbmode(mode)
returnValue(int(resp))
@setting(102, 'freq_ext', returns='v')
def freqext(self, c):
''' gets the external refernce frequncy '''
dev = self.selectedDevice(c)
resp = yield dev.freqext()
returnValue(float(resp))
@setting(103, 'Phase', ph=[': query phase offset', 'v: set phase offset'], returns='v')
def phase(self, c, ph = None):
''' sets/gets the phase offset to a value in degrees
'''
dev = self.selectedDevice(c)
if ph is None:
resp = yield dev.phase()
returnValue(float(resp))
else:
resp = yield dev.phase(ph)
returnValue(float(resp))
@setting(104, 'Reference', ref=[': query reference source', 'i: set external (0) or internal (1) reference source'], returns='i')
def reference(self, c, ref = None):
"""
sets/gets the reference source. (internal source = 0 ; external source = 1 ; dual = 2 ; chop = 3)
"""
dev = self.selectedDevice(c)
if ref is None:
resp = yield dev.reference()
returnValue(int(resp))
else:
resp = yield dev.reference(ref)
returnValue(int(resp))
@setting(105, 'Frequency', f=[': query frequency', 'v: set frequency'], returns='v')
def frequency(self, c, f = None):
""" Sets/gets the frequency of the internal reference. """
dev = self.selectedDevice(c)
if f is None:
resp = yield dev.frequency()
returnValue(float(resp))
else:
resp = yield dev.frequency(f)
returnValue(float(resp))
@setting(106, 'external_reference_slope', ers=[': query', 'i: set'], returns='i')
def external_reference_slope(self, c, ers = None):
"""
Get/set the external reference slope.
0 = Sine, 1 = TTL Rising, 2 = TTL Falling
"""
dev = self.selectedDevice(c)
if ers is None:
resp = yield dev.external_reference_slope()
returnValue(int(resp))
else:
resp = yield dev.external_reference_slope(ers)
returnValue(resp)
@setting(107, 'Harmonic', h=[': query harmonic', 'i: set harmonic'], returns='i')
def harmonic(self, c, h = None):
"""
Get/set the harmonic.
Harmonic can be set as high as 19999 but is capped at a frequency of 102kHz.
"""
dev = self.selectedDevice(c)
if h is None:
resp = yield dev.harmonic()
returnValue(int(resp))
else:
resp = yield dev.harmonic(h)
returnValue(resp)
@setting(108, 'sine_out_amplitude', amp=[': query', 'v: set'], returns='v')
def sine_out_amplitude(self, c, amp = None):
"""
Set/get the amplitude of the sine out.
Accepts values between .004 and 5.0 V.
"""
dev = self.selectedDevice(c)
if amp is None:
resp = yield dev.sine_out_amplitude()
returnValue(float(resp))
else:
resp = yield dev.sine_out_amplitude(amp)
returnValue(float(resp))
@setting(109, 'Sine Offset', offset = 'v', returns='v')
def sine_offset(self, c, offset = None):
'''
gets/sets the sine out dc offset level in volts, can be programmed from -5.00 to +5.00 volts
'''
dev = self.selectedDevice(c)
if offset is None:
resp = yield dev.sine_offset()
returnValue(float(resp))
else:
if float(offset) < -5 or float(offset) > 5:
raise ValueError("Offset must be between -5 and +5")
else:
resp = yield dev.sine_offset(offset)
returnValue(float(resp))
@setting(110, 'Sine ref', ref = 'i', returns='i')
def sine_ref(self, c, ref = None):
''' gets/sets the sine output refernce mode (common = 0 ; differential = 1)
'''
dev = self.selectedDevice(c)
if ref is None:
resp = yield dev.sine_ref()
returnValue(int(resp))
else:
resp = yield dev.sine_ref(ref)
returnValue(int(resp))
@setting(111, 'Trigger Sign', sign = 'i', returns='i')
def trigger_sign(self, c, sign = None):
'''
gets/sets the external refernce trigger mode (sine = 0 ; positive TLL = 1 ; negative TLL = 2)
'''
dev = self.selectedDevice(c)
if sign is None:
resp = yield dev.trigger_sign()
returnValue(int(resp))
else:
resp = yield dev.trigger_sign(sign)
returnValue(int(resp))
@setting(112, 'Trigger Z', z_in = 'i', returns='i')
def trigger_z(self, c, z_in = None):
''' gets/sets the external refernce trigger input impedance (50Ohm = 0 ; 1MOhm = 1 )
'''
dev = self.selectedDevice(c)
if z_in is None:
resp = yield dev.trigger_z()
returnValue(int(resp))
else:
resp = yield dev.trigger_z(z_in)
returnValue(int(resp))
@setting(113, 'inputMode', mode = 'i', returns='i')
def inputMode(self, c, mode = None):
''' gets/sets the signal input to voltage (0) or current (1)
'''
dev = self.selectedDevice(c)
if mode is None:
resp = yield dev.input_mode()
returnValue(int(resp))
else:
resp = yield dev.input_mode(mode)
returnValue(int(resp))
@setting(114, 'Voltage Input Mode', mode = 'i', returns='i')
def voltage_mode(self, c, mode = None):
''' gets/sets the signal input to voltage mode to A (0) or A - B (1)
'''
dev = self.selectedDevice(c)
if mode is None:
resp = yield dev.voltage_mode()
returnValue(int(resp))
else:
resp = yield dev.voltage_mode(mode)
returnValue(int(resp))
@setting(115, 'voltage_coupling', mode = 'i', returns='i')
def voltage_coupling(self, c, mode = None):
''' gets/sets the signal input to voltage coupling mode to AC (0) or DC (1)
'''
dev = self.selectedDevice(c)
if mode is None:
resp = yield dev.voltage_coupling()
returnValue(int(resp))
else:
resp = yield dev.voltage_coupling(mode)
returnValue(int(resp))
@setting(116, 'input_rng', mode = 'i', returns='i')
def input_rng(self, c, mode = None):
''' gets/sets the signal input to voltage range to 1V (0), 300mV (1), 100mV (2), 30mV (3), or 10mV (4)
'''
dev = self.selectedDevice(c)
if mode is None:
resp = yield dev.input_rng()
returnValue(int(resp))
else:
resp = yield dev.input_rng(mode)
returnValue(int(resp))
@setting(117, 'Aux Input', n='i', returns='v')
def aux_input(self, c, n):
"""Query the value of Aux Input n (1,2,3,4)"""
dev = self.selectedDevice(c)
if int(n) < 1 or int(n) > 4:
raise ValueError("n must be 1,2,3, or 4!")
else:
n = int(n) - 1
resp = yield dev.aux_input(n)
returnValue(float(resp))
@setting(118, 'Aux Output', n='i', v=['v'], returns='v')
def aux_output(self, c, n, v = None):
"""Get/set the value of Aux Output n (1,2,3,4). v can be from -10.5 to 10.5 V."""
dev = self.selectedDevice(c)
if int(n) < 1 or int(n) > 4:
raise ValueError("n must be 1,2,3, or 4!")
else:
n = int(n) - 1
if v is None:
resp = yield dev.aux_output(n)
returnValue(float(resp))
else:
resp = yield dev.aux_output(n, v);
returnValue(resp)
@setting(119, 'x', returns='v')
def x(self, c):
"""Query the value of X"""
dev = self.selectedDevice(c)
resp = yield dev.x()
returnValue(float(resp))
@setting(120, 'y', returns='v')
def y(self, c):
"""Query the value of Y"""
dev = self.selectedDevice(c)
resp = yield dev.y()
returnValue(float(resp))
@setting(121, 'r', returns='v')
def r(self, c):
"""Query the value of R"""
dev = self.selectedDevice(c)
resp = yield dev.r()
returnValue(float(resp))
@setting(122, 'theta', returns='v')
def theta(self, c):
"""Query the value of theta """
dev = self.selectedDevice(c)
resp = yield dev.theta()
returnValue(float(resp))
@setting(123, 'XNoise', returns='v')
def xnoise(self, c):
"""Query the value of the voltage noise in X """
dev = self.selectedDevice(c)
resp = yield dev.xnoise()
returnValue(float(resp))
@setting(124, 'YNoise', returns='v')
def ynoise(self, c):
"""Query the value of the voltage noise in Y """
dev = self.selectedDevice(c)
resp = yield dev.ynoise()
returnValue(float(resp))
@setting(125, 'Autorange')
def autorange(self, c):
"""Autoranges the device """
dev = self.selectedDevice(c)
yield dev.autorange()
@setting(126, 'Autoscale')
def autoscale(self, c):
"""Autoscales the device, automatically adjusts the sensitivity """
dev = self.selectedDevice(c)
yield dev.autoscale()
@setting(127, 'cout_xy_rt', chn = 'i', set = 'i', returns = 'i')
def cout_xy_rt(self, c, chn, set = None):
"""Sets/gets the output setting for a given output (X/Y = 0; RTheta = 1). For example cout_xy_rt(1,1) sets channel 1 output to r/theta."""
dev = self.selectedDevice(c)
if set is None:
resp = yield dev.cout_xy_rt(chn)
returnValue(int(resp))
else:
resp = yield dev.cout_xy_rt(chn,set)
returnValue(int(resp))
@setting(128, 'cout_exp', axis = 'i', exp = 'i', returns = 'i')
def cout_exp(self, c, axis, exp = None):
"""Sets/gets the output expand for an output axis (X = 0 ; Y = 1; R = 2). For example cout_xy_rt(1,1) sets channel 1 output to r/theta."""
dev = self.selectedDevice(c)
if exp is None:
resp = yield dev.cout_exp(axis)
returnValue(int(resp))
else:
resp = yield dev.cout_exp(axis, exp)
returnValue(int(resp))
@setting(129, 'Time Constant', tc='v', returns='v')
def time_constant(self, c, tc=None):
""" Set/get the time constant. i=0 --> 1 us; 1-->3us, 2-->10us, 3-->30us, ..., 21 --> 30ks """
dev = self.selectedDevice(c)
if tc is not None:
tc = getTCInt(tc)
yield dev.write('OFLT {}'.format(tc))
resp = yield dev.query("OFLT?")
returnValue(getTC(int(resp)))
@setting(130, 'Sensitivity', i='v', returns='v')
def sensitivity(self, c, i=None):
""" Set/get the sensitivity. To set the sensitivity, input the voltage sensitivity in Volts or the current sensitivity in Amps.
Lookup table in the manual: i=27 --> 1 nV/fA; 26-->5nV/fA, 25-->10nV/fA, 24-->20nV/fA, ..., 0 --> 1V/uA
"""
dev = self.selectedDevice(c)
iv_mode = yield dev.input_mode()
if int(iv_mode) == 0:
u = units.V
elif int(iv_mode) == 1:
u = units.A
else:
u = 'none'
if i is None:
resp = yield dev.sensitivity()
if u != 'none':
returnValue(resp)
else:
returnValue(resp)
else:
jj = getSensitivityInt(i, int(iv_mode))
resp = yield dev.sensitivity(jj)
if u != 'none':
returnValue(resp )
else:
returnValue(resp)
@setting(131, 'Filter Slope', i='i', returns='i')
def filter_slope(self, c, i=None):
'''
Sets/gets the low pass filter slope. 0=>6, 1=>12, 2=>18, 3=>24 dB/oct
'''
dev = self.selectedDevice(c)
if i is None:
resp = yield dev.filter_slope()
returnValue(resp)
else:
resp = yield dev.filter_slope(i)
returnValue(resp)
@setting(132, 'Get XY', returns='*v')
def get_xy(self, c):
"""Query the value of the X and Y outputs simultaneously """
dev = self.selectedDevice(c)
resp = yield dev.get_xy()
ans = [resp.split(',')[0], resp.split(',')[1]]
returnValue(ans)
@setting(133, 'get_rt', returns='*v')
def get_rt(self, c):
"""Query the value of the R and Theta outputs simultaneously """
dev = self.selectedDevice(c)
resp = yield dev.get_rt()
ans = [resp.split(',')[0], resp.split(',')[1]]
returnValue(ans)
@setting(134, 'gnd_mode', mode='i', returns='i')
def gnd_mode(self, c, mode = None):
'''
Sets/gets voltage input shield grounding setting (grounded = 1 ; floating = 0)
'''
dev = self.selectedDevice(c)
if mode is None:
resp = yield dev.gnd_mode()
returnValue(resp)
else:
resp = yield dev.gnd_mode(mode)
returnValue(resp)
@setting(135, 'sig_lvl', returns='i')
def sig_lvl(self, c):
'''
Queries the signal strength and returns an integer from 0 (low signal strength) to 4 (overload)
'''
dev = self.selectedDevice(c)
resp = yield dev.sig_lvl()
returnValue(resp)
@setting(136, 'curr_gain', gain='i', returns='i')
def curr_gain(self, c, gain=None):
'''
Sets/gets intput current gain (0 = 1MOhm [1uA] ; 1 = 100MOhm [10nA])
'''
dev = self.selectedDevice(c)
if gain is None:
resp = yield dev.curr_gain()
returnValue(resp)
else:
resp = yield dev.curr_gain(gain)
returnValue(resp)
@setting(137, 'sensitivity_up', returns='v')
def sensitivity_up(self, c):
""" Increases the sensitivity one increment
"""
dev = self.selectedDevice(c)
sens = yield dev.query('SCAL?')
sens = getSensitivity(int(sens)-1)
sens = yield self.sensitivity(c, sens)
returnValue(sens)
@setting(138, 'sensitivity_down', returns='v')
def sensitivity_down(self, c):
""" Decreases the sensitivity one increment
"""
dev = self.selectedDevice(c)
sens = yield dev.query('SCAL?')
sens = getSensitivity(int(sens)+1)
sens = yield self.sensitivity(c, sens)
returnValue(sens)
@setting(139, 'Wait Time', returns='v')
def wait_time(self, c):
"""Returns the recommended wait time given current time constant and low-pass filter slope."""
dev = self.selectedDevice(c)
tc = yield dev.query("OFLT?")
tc = getTC(int(tc))
slope = yield dev.query("OFSL?")
slope = int(slope)
if slope == 0:
returnValue(5*tc) # recommended 5
elif slope == 1:
returnValue(7*tc) # 7
elif slope == 2:
returnValue(9*tc)
else:# slope == 3:
returnValue(10*tc) # 10 etc.
@setting(140, "Auto Sensitivity")
def auto_sensitivity(self, c):
"""Automatically adjusts sensitivity until signal is between 35% and 95% of full range."""
waittime = yield self.wait_time(c)
r = yield self.r(c)
sens = yield self.sensitivity(c)
mode = yield self.inputMode(c)
while r == 0:
sens = getSensitivity(getSensitivityInt(sens, mode)-5)
sens = yield self.sensitivity(c, sens)
r = yield self.r(c)
if r/sens < 0.35:
sens = getSensitivity(getSensitivityInt(r/0.35, mode))
sens = yield self.sensitivity(c, sens)
r = yield self.r(c)
while r/sens > 0.35:
yield self.sensitivity_up(c)
yield util.wakeupCall(waittime)
r = yield self.r(c)
sens = yield self.sensitivity(c)
__server__ = sr860Server()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)
## working versions