-
Notifications
You must be signed in to change notification settings - Fork 1
/
ami_430.py
673 lines (601 loc) · 22.5 KB
/
ami_430.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
# 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 = AMI 430
version = 1.0
description =
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
from labrad.server import setting
from labrad.devices import DeviceServer,DeviceWrapper
from twisted.internet.defer import inlineCallbacks, returnValue
import labrad.units as units
from labrad.types import Value
TIMEOUT = Value(5,'s')
BAUD = 115200
STOP_BITS = 1
BYTESIZE= 8
RTS = 1
maxRate = 10
class AMI430Wrapper(DeviceWrapper):
@inlineCallbacks
def connect(self, server, port):
"""Connect to a device."""
print('connecting to "%s" on port "%s"...' % (server.name, port), end=' ')
self.server = server
self.ctx = server.context()
self.port = port
p = self.packet()
p.open(port)
p.stopbits(STOP_BITS)
p.bytesize(BYTESIZE)
p.rts(bool(RTS))
print('opened on port "%s"' %self.port)
p.baudrate(BAUD)
p.read() # clear out the read buffer
p.timeout(TIMEOUT)
print(" CONNECTED ")
yield p.send()
def packet(self):
"""Create a packet in our private context."""
return self.server.packet(context=self.ctx)
def shutdown(self):
"""Disconnect from the serial port when we shut down."""
return self.packet().close().send()
@inlineCallbacks
def write(self, code):
"""Write a data value to the heat switch."""
yield self.packet().write(code).send()
@inlineCallbacks
def read(self):
p=self.packet()
p.read_line()
ans=yield p.send()
returnValue(ans.read_line)
@inlineCallbacks
def query(self, code):
""" Write, then read. """
p = self.packet()
p.write_line(code)
p.read_line()
ans = yield p.send()
returnValue(ans.read_line)
class AMI430Server(DeviceServer):
name = 'AMI_430'
deviceName = 'AMI_430 Programmer'
deviceWrapper = AMI430Wrapper
@inlineCallbacks
def initServer(self):
print('loading config info...', end=' ')
self.reg = self.client.registry()
yield self.loadConfigInfo()
print('done.')
print(self.serialLinks)
yield DeviceServer.initServer(self)
@inlineCallbacks
def loadConfigInfo(self):
"""Load configuration information from the registry."""
# reg = self.client.registry
# p = reg.packet()
# p.cd(['', 'Servers', 'Heat Switch'], True)
# p.get('Serial Links', '*(ss)', key='links')
# ans = yield p.send()
# self.serialLinks = ans['links']
reg = self.reg
yield reg.cd(['', 'Servers', 'ami_430', 'Links'], True)
dirs, keys = yield reg.dir()
p = reg.packet()
print(" created packet")
print("printing all the keys",keys)
if keys:
for k in keys:
print("k=",k)
p.get(k, key=k)
ans = yield p.send()
print("ans=",ans,ans[k])
self.serialLinks = dict((k, ans[k]) for k in keys)
else:
self.serialLinks = dict()
# yield reg.cd(['', 'Servers', 'ami_430', 'Max Rates'], True)
# dirs, keys = yield reg.dir()
# p = reg.packet()
# for k in keys:
# p.get(k, key=k)
# ans = yield p.send()
# self.maxRates = dict((k, ans[k]) for k in keys)
@inlineCallbacks
def findDevices(self):
"""Find available devices from list stored in the registry."""
devs = []
# for name, port in self.serialLinks:
# if name not in self.client.servers:
# continue
# server = self.client[name]
# ports = yield server.list_serial_ports()
# if port not in ports:
# continue
# devName = '%s - %s' % (name, port)
# devs += [(devName, (server, port))]
# returnValue(devs)
for name, (serServer, port) in list(self.serialLinks.items()):
if serServer not in self.client.servers:
continue
server = self.client[serServer]
print(name)
print(server)
print(port)
ports = yield server.list_serial_ports()
print(ports)
if port not in ports:
continue
devName = '%s - %s' % (serServer, port)
devs += [(devName, (server, port))]
# devs += [(0,(3,4))]
returnValue(devs)
@inlineCallbacks
def get_max_rate(self,dev):
pass
@setting(100)
def connect(self,c,server,port):
dev=self.selectedDevice(c)
yield dev.connect(server,port)
@setting(101,returns='s')
def id(self,c):
dev=self.selectedDevice(c)
yield dev.write('*IDN?\r')
ans = yield dev.read()
returnValue(ans)
@setting(102,returns='s')
def system_error(self,c):
'''
Queries the error buffer of the Model 430 Programmer. Up to 10 errors are
stored in the error buffer. Errors are retrieved in first-in-first-out (FIFO)
order. The error buffer is cleared by the *CLS (clear status) command or
when the power is cycled. Errors are also cleared as they are read. See
page 153 for a complete description of the error buffer and messages.
'''
dev=self.selectedDevice(c)
yield dev.write("*SYST:ERR?\r")
ans = yield dev.read()
returnValue(ans)
@setting(103,returns='s')
def clear(self,c):
'''
Clears the Standard Event register and the error buffer.
'''
dev=self.selectedDevice(c)
yield dev.write("*CLS\r")
ans = yield dev.read()
returnValue(ans)
@setting(104,voltage='v[]')
def conf_volt_lim(self,c,voltage):
'''
Sets the ramping Voltage Limit in volts. The ramping Voltage Limit may
not exceed the maximum output voltage of the power supply.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:VOLT:LIM %f\r"%voltage)
@setting(105,returns='s')
def get_volt_lim(self,c):
'''
Returns the ramping Voltage Limit in volts.
'''
dev=self.selectedDevice(c)
yield dev.write("VOLT:LIM?\r")
ans = yield dev.read()
returnValue(ans)
@setting(106,current='v[]')
def conf_curr_targ(self,c,current):
'''
Sets the target current in amperes.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:CURR:TARG %f\r"%current)
@setting(107,returns='s')
def get_curr_targ(self,c):
'''
Returns the target current setting in amperes.
'''
dev=self.selectedDevice(c)
yield dev.write("CURR:TARG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(108,units='v[]')
def conf_field_units(self,c,units):
'''
Sets the preferred field units. Sending "0" selects kilogauss. A "1" selects
tesla. "0" is the default value. The selected field units are applied to both
the Model 430 Programmer display and the applicable remote commands.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:FIELD:UNITS %f\r"%units)
@setting(109,returns='s')
def get_field_units(self,c):
'''
Returns "0" for field values displayed/specified in terms of kilogauss, or "1"
for tesla.
'''
dev=self.selectedDevice(c)
yield dev.write("FIELD:UNITS?\r")
ans = yield dev.read()
returnValue(ans)
@setting(110,field='v[]')
def conf_field_targ(self,c,field):
'''
Sets the target field in units of kilogauss or tesla, per the selected field
units. This command requires that a coil constant be defined, otherwise an
error is generated.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:FIELD:TARG %f\r"%field)
@setting(111,returns='s')
def get_field_targ(self,c):
'''
Returns the target current setting in amperes.
'''
dev=self.selectedDevice(c)
yield dev.write("FIELD:TARG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(112,nSegments='i')
def conf_ramp_rate_seg(self,c,nSegments):
'''
Sets the number of ramp segments (see section 3.7.1 for details of the use
of ramp segments).
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:RAMP:RATE:SEG %u\r"%nSegments)
@setting(113,returns='s')
def get_ramp_rate_seg(self,c):
'''
Returns the number of ramp segments.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMP:RATE:SEG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(114,units='i')
def conf_ramp_rate_units(self,c,units):
'''
Sets the preferred ramp rate time units. Sending "0" selects seconds. A "1"
selects minutes. "0" is the default value. The selected units are applied to
both the Model 430 Programmer display and the appropriate remote
commands.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:RAMP:RATE:UNITS %u\r"%units)
@setting(115,returns='s')
def get_ramp_rate_units(self,c):
'''
Returns "0" for ramp rates displayed/specified in terms of seconds, or "1"
for minutes.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMP:RATE:UNITS?\r")
ans = yield dev.read()
returnValue(ans)
@setting(116,segment='i', rate = 'v[]', upper_bound = 'v[]')
def conf_ramp_rate_curr(self,c,segment,rate,upper_bound):
'''
Sets the ramp rate for the specified segment (values of 1 through the
defined number of ramp segments are valid) in units of A/sec or A/min (per
the selected ramp rate units), and defines the current upper bound for that
segment in amperes (see section 3.7.1 for details of the use of ramp
segments).
'''
dev=self.selectedDevice(c)
rate = min(rate,maxRate)
yield dev.write("CONF:RAMP:RATE:CURR %u,%f,%f\r"%(segment,rate,upper_bound))
@setting(117,segment='i',returns='s')
def get_ramp_rate_curr(self,c,segment):
'''
Returns the ramp rate setting for the specified segment (values of 1
through the defined number of ramp segments are valid) in units of A/sec
or A/min (per the selected ramp rate units) and the current upper bound
for that range in amperes. The two return values are separated by a
comma.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMP:RATE:CURR:%u?\r"%segment)
ans = yield dev.read()
returnValue(ans)
@setting(118,segment='i', rate = 'v[]', upper_bound = 'v[]')
def conf_ramp_rate_field(self,c,segment,rate,upper_bound):
'''
Sets the ramp rate for the specified segment (values of 1 through the
defined number of ramp segments are valid) in units of kilogauss/second or
minute, or tesla/second or minute (per the selected field units and ramp
rate units), and defines the field upper bound for that segment in
kilogauss or tesla (see section 3.7.1 for details of the use of ramp
segments). This command requires that a coil constant be defined;
otherwise, an error is generated.
'''
dev=self.selectedDevice(c)
rate = min(rate,maxRate)
yield dev.write("CONF:RAMP:RATE:FIELD %u,%f,%f\r"%(segment,rate,upper_bound))
@setting(119,segment='i',returns='s')
def get_ramp_rate_field(self,c,segment):
'''
Returns the ramp rate setting for the specified segment (values of 1
through the defined number of ramp segments are valid) in units of
kilogauss/second or minute, or tesla/second or minute (per the selected
field units and ramp rate units) and the current upper bound for that
range in kilogauss or tesla (per the selected field units). This command
requires that a coil constant be defined; otherwise, an error is generated.
The two return values are separated by a comma.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMP:RATE:FIELD:%u?\r"%segment)
ans = yield dev.read()
returnValue(ans)
@setting(120,returns='s')
def get_volt_mag(self,c):
'''
Returns the magnet voltage in volts. Requires voltage taps to be installed
across the magnet terminals.
'''
dev=self.selectedDevice(c)
yield dev.write("VOLT:MAG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(121,returns='s')
def get_volt_supp(self,c):
'''
Returns the power supply voltage commanded by the Model 430
Programmer in volts.
'''
dev=self.selectedDevice(c)
yield dev.write("VOLT:SUPP?\r")
ans = yield dev.read()
returnValue(ans)
@setting(122,returns='s')
def get_curr_mag(self,c):
'''
Returns the current flowing in the magnet in amperes, expressed as a
number with four significant digits past the decimal point, such as 5.2320.
If the magnet is in persistent mode, the command returns the current that
was flowing in the magnet when persistent mode was entered.
'''
dev=self.selectedDevice(c)
yield dev.write("CURR:MAG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(123,returns='s')
def get_curr_supp(self,c):
'''
Returns the measured power supply current in amperes.
'''
dev=self.selectedDevice(c)
yield dev.write("CURR:SUPP?\r")
ans = yield dev.read()
returnValue(ans)
@setting(124,returns='s')
def get_field_mag(self,c):
'''
Returns the calculated field in kilogauss or tesla, per the selected field
units. This query requires that a coil constant be defined; otherwise, an
error is generated. The field is calculated by multiplying the measured
magnet current by the coil constant. If the magnet is in persistent mode,
the command returns the field that was present when persistent mode was
entered.
'''
dev=self.selectedDevice(c)
yield dev.write("FIELD:MAG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(125,returns='s')
def get_ind(self,c):
'''
Returns the measured magnet inductance in henries. Note that the
magnet must be ramping when this command is executed. Refer to section
3.10.2.5 on page 78.
'''
dev=self.selectedDevice(c)
yield dev.write("IND?\r")
ans = yield dev.read()
returnValue(ans)
@setting(126,units='i')
def conf_rampDown_enab(self,c,units):
'''
Enables the external rampdown function. "1" enables while "0" disables.
"0" is the default value.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:RAMPD:ENAB %u\r"%units)
@setting(127,returns='s')
def get_rampDown_enab(self,c):
'''
Queries whether the external rampdown function is enabled. Returns "1"
for enabled while "0" for disabled. "0" is the default value.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMPD:ENAB\r")
ans = yield dev.read()
returnValue(ans)
@setting(128,nSegments='i')
def conf_rampDown_rate_seg(self,c,nSegments):
'''
Sets the number of external rampdown segments.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:RAMPD:RATE:SEG %u\r"%nSegments)
@setting(129,returns='s')
def get_rampDown_rate_seg(self,c):
'''
Returns the number of external rampdown segments.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMPD:RATE:SEG?\r")
ans = yield dev.read()
returnValue(ans)
@setting(130,segment='i', rate = 'v[]', upper_bound = 'v[]')
def conf_rampDown_rate_curr(self,c,segment,rate,upper_bound):
'''
Sets the external rampdown rate for the specified segment (values of 1
through the defined number of rampdown segments are valid) in units of
A/sec or A/min (per the selected rampdown rate units), and defines the
current upper bound for that segment in amperes.
'''
dev=self.selectedDevice(c)
rate = min(rate,maxRate)
yield dev.write("CONF:RAMPD:RATE:CURR %u,%f,%f\r"%(segment,rate,upper_bound))
@setting(131,segment='i',returns='s')
def get_rampDown_rate_curr(self,c,segment):
'''
Returns the external rampdown rate setting for the specified segment
(values of 1 through the defined number of rampdown segments are valid)
in units of A/sec or A/min (per the selected rampdown rate units) and the
current upper bound for that range in amperes. The two return values are
separated by a comma.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMPD:RATE:CURR:%u?\r"%segment)
ans = yield dev.read()
returnValue(ans)
@setting(132,segment='i', rate = 'v[]', upper_bound = 'v[]')
def conf_rampDown_rate_field(self,c,segment,rate,upper_bound):
'''
Sets the external rampdown rate for the specified segment (values of 1
through the defined number of rampdown segments are valid) in units of
A/sec or A/min (per the selected rampdown rate units), and defines the
current upper bound for that segment in amperes.
'''
dev=self.selectedDevice(c)
rate = min(rate,maxRate)
yield dev.write("CONF:RAMPD:RATE:Field %u,%f,%f\r"%(segment,rate,upper_bound))
@setting(133,segment='i',returns='s')
def get_rampDown_rate_field(self,c,segment):
'''
Returns the external rampdown rate setting for the specified segment
(values of 1 through the defined number of rampdown segments are valid)
in units of kilogauss/second or minute, or tesla/second or minute (per the
selected field units and rampdown rate units) and the current upper bound
for that range in kilogauss or tesla (per the selected field units). This
command requires that a coil constant has been defined; otherwise, an
error is generated.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMPD:RATE:CURR:%u?\r"%segment)
ans = yield dev.read()
returnValue(ans)
@setting(134)
def ramp(self,c):
'''
Places the Model 430 Programmer in automatic ramping mode. The Model
430 will continue to ramp at the configured ramp rate(s) until the target
field/current is achieved.
'''
dev=self.selectedDevice(c)
yield dev.write("RAMP\r")
@setting(135)
def pause(self,c):
'''
Pauses the Model 430 Programmer at the present operating field/current.
'''
dev=self.selectedDevice(c)
yield dev.write("PAUSE\r")
@setting(136)
def incr(self,c):
'''
Places the Model 430 Programmer in the MANUAL UP ramping mode.
Ramping continues at the ramp rate until the Current Limit is achieved.
'''
dev=self.selectedDevice(c)
yield dev.write("INCR\r")
@setting(137)
def decr(self,c):
'''
Places the Model 430 Programmer in the MANUAL DOWN ramping
mode. Ramping continues at the ramp rate until the Current Limit is
achieved (or zero current is achieved for unipolar power supplies).
'''
dev=self.selectedDevice(c)
yield dev.write("DECR\r")
@setting(138)
def zero(self,c):
'''
Places the Model 430 Programmer in ZEROING CURRENT mode.
Ramping automatically initiates and continues at the ramp rate until the
power supply output current is less than 0.1% of Imax, at which point the
AT ZERO status becomes active.
'''
dev=self.selectedDevice(c)
yield dev.write("ZERO\r")
@setting(139)
def state(self,c, returns='i'):
'''
Returns an integer value corresponding to the ramping state:
1 RAMPING to target field/Current
2 HOLDING at the target field/current
3 PAUSED
4 Ramping in MANUAL UP mode
5 Ramping in MANUAL DOWN mode
6 ZEROING CURRENT (in progress)
7 Quench detected
8 At ZERO current
9 Heating persistent switch
10 Cooling persistent switch
'''
dev=self.selectedDevice(c)
yield dev.write("STATE?\r")
ans = yield dev.read()
returnValue(int(ans))
@setting(140,name='s')
def conf_ipname(self,c,name):
'''
Sets the system name (also known as host name or computer name), the
name by which the Model 430 Programmer is identified on a network.
'''
dev=self.selectedDevice(c)
yield dev.write("CONF:IPNAME %s\r"%name)
@setting(141,returns='s')
def get_ipname(self,c):
'''
Returns the system name (also known as host name or computer name).
'''
dev=self.selectedDevice(c)
yield dev.write("IPNAME?\r"%segment)
ans = yield dev.read()
returnValue(ans)
@setting(9001,v='v')
def do_nothing(self,c,v):
pass
@setting(9002)
def read(self,c):
dev=self.selectedDevice(c)
ret=yield dev.read()
returnValue(ret)
@setting(9003)
def write(self,c,phrase):
dev=self.selectedDevice(c)
yield dev.write(phrase)
@setting(9004)
def query(self,c,phrase):
dev=self.selectedDevice(c)
yield dev.write(phrase)
ret = yield dev.read()
returnValue(ret)
__server__ = AMI430Server()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)