Debian Codegraph @

pymeasure/instruments/ami/ami430.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25 from pymeasure.instruments import Instrument, SCPIMixin
26 from time import sleep, time
27
28 import logging
29 log = logging.getLogger(__name__)
30 log.addHandler(logging.NullHandler())
31
32
33 class AMI430(SCPIMixin, Instrument):
34 """ Represents the AMI 430 Power supply
35 and provides a high-level for interacting with the instrument.
36
37 .. code-block:: python
38
39 magnet = AMI430("TCPIP::web.address.com::7180::SOCKET")
40
41
42 magnet.coilconst = 1.182 # kGauss/A
43 magnet.voltage_limit = 2.2 # Sets the voltage limit in V
44
45 magnet.target_current = 10 # Sets the target current to 10 A
46 magnet.target_field = 1 # Sets target field to 1 kGauss
47
48 magnet.ramp_rate_current = 0.0357 # Sets the ramp rate in A/s
49 magnet.ramp_rate_field = 0.0422 # Sets the ramp rate in kGauss/s
50 magnet.ramp # Initiates the ramping
51 magnet.pause # Pauses the ramping
52 magnet.status # Returns the status of the magnet
53
54 magnet.ramp_to_current(5) # Ramps the current to 5 A
55
56 magnet.shutdown() # Ramps the current to zero and disables output
57
58 """
59
60 def __init__(self, adapter, name="AMI superconducting magnet power supply.", **kwargs):
61 kwargs.setdefault('read_termination', '\n')
62 super().__init__(
63 adapter,
64 name,
65 **kwargs
66 )
67 # Read twice in order to remove welcome/connect message
68 self.read()
69 self.read()
70
71 maximumfield = 1.00
72 maximumcurrent = 50.63
73
74 coilconst = Instrument.control(
75 "COIL?", "CONF:COIL %g",
76 """Control the coil constant in kGauss/A. (float)"""
77 )
78
79 voltage_limit = Instrument.control(
80 "VOLT:LIM?", "CONF:VOLT:LIM %g",
81 """Control the voltage limit for charging/discharging the magnet. (float)"""
82 )
83
84 target_current = Instrument.control(
85 "CURR:TARG?", "CONF:CURR:TARG %g",
86 """Control the target current in A for the magnet. (float)"""
87 )
88
89 target_field = Instrument.control(
90 "FIELD:TARG?", "CONF:FIELD:TARG %g",
91 """Control the target field in kGauss for the magnet. (float)"""
92 )
93
94 ramp_rate_current = Instrument.control(
95 "RAMP:RATE:CURR:1?", "CONF:RAMP:RATE:CURR 1,%g",
96 """Control the current ramping rate in A/s. (float)"""
97 )
98
99 ramp_rate_field = Instrument.control(
100 "RAMP:RATE:FIELD:1?", "CONF:RAMP:RATE:FIELD 1,%g,1.00",
101 """Control the field ramping rate in kGauss/s. (float)"""
102 )
103
104 magnet_current = Instrument.measurement("CURR:MAG?",
105 """Get the current in Amps of the magnet.
106 """
107 )
108
109 supply_current = Instrument.measurement("CURR:SUPP?",
110 """Get the current in Amps of the power supply.
111 """
112 )
113
114 field = Instrument.measurement("FIELD:MAG?",
115 """Get the field in kGauss of the magnet.
116 """
117 )
118
119 state = Instrument.measurement("STATE?",
120 """Get the field in kGauss of the magnet.
121 """
122 )
123
124 def zero(self):
125 """ Initiates the ramping of the magnetic field to zero
126 current/field with ramping rate previously set. """
127 self.write("ZERO")
128
129 def pause(self):
130 """ Pauses the ramping of the magnetic field. """
131 self.write("PAUSE")
132
133 def ramp(self):
134 """ Initiates the ramping of the magnetic field to set
135 current/field with ramping rate previously set.
136 """
137 self.write("RAMP")
138
139 def has_persistent_switch_enabled(self):
140 """ Returns a boolean if the persistent switch is enabled. """
141 return bool(self.ask("PSwitch?"))
142
143 def enable_persistent_switch(self):
144 """ Enables the persistent switch. """
145 self.write("PSwitch 1")
146
147 def disable_persistent_switch(self):
148 """ Disables the persistent switch. """
149 self.write("PSwitch 0")
150
151 @property
152 def magnet_status(self):
153 """Get the magnet status."""
154 STATES = {
155 1: "RAMPING",
156 2: "HOLDING",
157 3: "PAUSED",
158 4: "Ramping in MANUAL UP",
159 5: "Ramping in MANUAL DOWN",
160 6: "ZEROING CURRENT in progress",
161 7: "QUENCH!!!",
162 8: "AT ZERO CURRENT",
163 9: "Heating Persistent Switch",
164 10: "Cooling Persistent Switch"
165 }
166 return STATES[self.state]
167
168 def ramp_to_current(self, current, rate):
169 """ Heats up the persistent switch and
170 ramps the current with set ramp rate.
171 """
172 self.enable_persistent_switch()
173
174 self.target_current = current
175 self.ramp_rate_current = rate
176
177 self.wait_for_holding()
178
179 self.ramp()
180
181 def ramp_to_field(self, field, rate):
182 """ Heats up the persistent switch and
183 ramps the current with set ramp rate.
184 """
185 self.enable_persistent_switch()
186
187 self.target_field = field
188
189 self.ramp_rate_field = rate
190
191 self.wait_for_holding()
192
193 self.ramp()
194
195 def wait_for_holding(self, should_stop=lambda: False,
196 timeout=800, interval=0.1):
197 """
198 """
199 t = time()
200 while self.state != 2 and self.state != 3 and self.state != 8:
201 sleep(interval)
202 if should_stop():
203 return
204 if (time() - t) > timeout:
205 raise Exception("Timed out waiting for AMI430 switch to warm up.")
206
207 def shutdown(self, ramp_rate=0.0357):
208 """ Turns on the persistent switch,
209 ramps down the current to zero, and turns off the persistent switch.
210 """
211 self.enable_persistent_switch()
212 self.wait_for_holding()
213 self.ramp_rate_current = ramp_rate
214 self.zero()
215 self.wait_for_holding()
216 self.disable_persistent_switch()
217 super().shutdown()