-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathips_120_10.py
281 lines (232 loc) · 7.66 KB
/
ips_120_10.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
# 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 = IPS 120_10 Superconducting Magnet Power Supply
version = 1.0
description =
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
import platform
global serial_server_name
serial_server_name = platform.node() + '_serial_server'
from labrad.server import setting
from labrad.gpib import GPIBManagedServer, GPIBDeviceWrapper
from twisted.internet.defer import inlineCallbacks, returnValue
import labrad.units as units
from labrad.types import Value
TIMEOUT = Value(5,'s')
BAUD = 9600
class IPS120Wrapper(GPIBDeviceWrapper):
@inlineCallbacks
def set_control(self,mode):
ans = yield self.query("C%i"%mode)
returnValue(ans)
@inlineCallbacks
def set_comm_protocol(self,comm):
yield self.write("Q%i"%comm)
@inlineCallbacks
def read_parameter(self,parameter):
ans = yield self.query("R%i"%parameter)
returnValue(ans)
@inlineCallbacks
def unlock(self,key):
ans = yield self.query("U%i"%key)
returnValue(ans)
@inlineCallbacks
def version(self):
ans = yield self.query("V")
returnValue(ans)
@inlineCallbacks
def wait(self,time):
ans = yield self.query("W%i"%time)
returnValue(ans)
@inlineCallbacks
def status(self):
ans = yield self.query("X")
returnValue(ans)
@inlineCallbacks
def set_activity(self,activity):
ans = yield self.query("A%i"%activity)
returnValue(ans)
@inlineCallbacks
def set_panelDisplay(self,parameter):
ans = yield self.query("F%i"%parameter)
returnValue(ans)
@inlineCallbacks
def set_switchHeater(self,mode):
ans = yield self.query("H%i"%mode)
returnValue(ans)
@inlineCallbacks
def set_targetCurrent(self,current):
ans = yield self.query("I%i"%current)
returnValue(ans)
@inlineCallbacks
def set_targetField(self,field):
ans = yield self.query("J%i"%field)
returnValue(ans)
@inlineCallbacks
def set_mode(self,mode):
ans = yield self.query("M%i"%mode)
returnValue(ans)
@inlineCallbacks
def set_polarity(self,polarity):
ans = yield self.query("P%i"%polarity)
returnValue(ans)
@inlineCallbacks
def set_currentSweep_rate(self,rate):
ans = yield self.query("S%i"%rate)
returnValue(ans)
@inlineCallbacks
def set_fieldSweep_rate(self,rate):
ans = yield self.query("T%i"%rate)
returnValue(ans)
@inlineCallbacks
def load_ram(self,nKbytes):
ans = yield self.query("Y%i"%nKbytes)
returnValue(ans)
@inlineCallbacks
def dump_ram(self,nKbytes):
ans = yield self.query("Z%i"%nKbytes)
returnValue(ans)
class IPS120Server(GPIBManagedServer):
name = 'ips120_power_supply'
deviceName = 'IPS120 Power Supply'
deviceIdentFunc = 'identify_device'
deviceWrapper = IPS120Wrapper
@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('V')
p.read()
p.write('V')
p.read()
ans = yield p.send()
resp = ans.read[1]
print 'got ident response:', resp
if resp == 'IPS120-10 Version 3.07 (c) OXFORD 1996':
returnValue(self.deviceName)
except Exception, e:
print 'failed:', e
raise
@setting(101, mode='i',returns='s')
def set_control(self,c,mode):
dev=self.selectedDevice(c)
ans = yield dev.set_control(mode)
returnValue(ans)
@setting(102, comm='i')
def set_comm_protocol(self,c,comm):
dev=self.selectedDevice(c)
yield dev.set_comm_protocol(comm)
@setting(103, parameter='i', returns='s')
def read_parameter(self,c,parameter):
dev=self.selectedDevice(c)
ans = yield dev.read_parameter(parameter)
returnValue(ans)
@setting(104, key='i', returns='s')
def unlock(self,c,key):
dev=self.selectedDevice(c)
ans = yield dev.unlock(key)
returnValue(ans)
@setting(105, returns='s')
def version(self,c):
dev=self.selectedDevice(c)
ans = yield dev.version()
returnValue(ans)
@setting(106, time='i', returns='s')
def wait(self,c,time):
dev=self.selectedDevice(c)
ans = yield dev.wait(time)
returnValue(ans)
@setting(107, returns='s')
def status(self,c):
dev=self.selectedDevice(c)
ans = yield dev.status()
returnValue(ans)
@setting(108, activity='i', returns='s')
def set_activity(self,c,activity):
dev=self.selectedDevice(c)
ans = yield dev.set_activity(activity)
returnValue(ans)
@setting(109, parameter='i', returns='s')
def set_panelDisplay(self,c,parameter):
dev=self.selectedDevice(c)
ans = yield dev.set_panelDisplay(parameter)
returnValue(ans)
@setting(110, mode='i', returns='s')
def set_switchHeater(self,c,mode):
dev=self.selectedDevice(c)
ans = yield dev.set_switchHeater(mode)
returnValue(ans)
@setting(111, current='v', returns='s')
def set_targetCurrent(self,c,current):
dev=self.selectedDevice(c)
ans = yield dev.set_targetCurrent(current)
returnValue(ans)
@setting(112, field='v', returns='s')
def set_targetField(self,c,field):
dev=self.selectedDevice(c)
ans = yield dev.set_targetField(field)
returnValue(ans)
@setting(113, mode='i', returns='s')
def set_mode(self,c,mode):
dev=self.selectedDevice(c)
ans = yield dev.set_mode(mode)
returnValue(ans)
@setting(114, polarity='i', returns='s')
def set_polarity(self,c,polarity):
dev=self.selectedDevice(c)
ans = yield dev.set_polarity(polarity)
returnValue(ans)
@setting(115, rate='v', returns='s')
def set_currentSweep_rate(self,c,rate):
dev=self.selectedDevice(c)
ans = yield dev.set_currentSweep_rate(rate)
returnValue(ans)
@setting(116, rate='v', returns='s')
def set_fieldSweep_rate(self,c,rate):
dev=self.selectedDevice(c)
ans = yield dev.set_fieldSweep_rate(rate)
returnValue(ans)
@setting(117, nKbytes='i', returns='s')
def load_ram(self,c,nKbytes):
dev=self.selectedDevice(c)
ans = yield dev.load_ram(nKbytes)
returnValue(ans)
@setting(118, nKbytes='i', returns='s')
def dump_ram(self,c,nKbytes):
dev=self.selectedDevice(c)
ans = yield dev.dump_ram(nKbytes)
returnValue(ans)
@setting(9001,v='v')
def do_nothing(self,c,v):
pass
__server__ = IPS120Server()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)