| 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 |
# ============================================================================= |
| 26 |
# Libraries / modules |
| 27 |
# ============================================================================= |
| 28 |
|
| 29 |
from pymeasure.instruments import Instrument |
| 30 |
from pymeasure.instruments.validators import strict_range |
| 31 |
from pymeasure.instruments.validators import strict_discrete_set |
| 32 |
from pymeasure.instruments.validators import strict_discrete_range |
| 33 |
import logging |
| 34 |
from time import sleep |
| 35 |
import numpy as np |
| 36 |
|
| 37 |
# ============================================================================= |
| 38 |
# Logging |
| 39 |
# ============================================================================= |
| 40 |
|
| 41 |
log = logging.getLogger(__name__) |
| 42 |
log.addHandler(logging.NullHandler()) |
| 43 |
|
| 44 |
|
| 45 |
# ============================================================================= |
| 46 |
# Instrument file |
| 47 |
# ============================================================================= |
| 48 |
|
| 49 |
|
| 50 |
class TDK_Lambda_Base(Instrument): |
| 51 |
""" |
| 52 |
This is the base class for TDK Lambda Genesys Series DC power supplies. |
| 53 |
Do not directly instantiate an object with this class. Use one of the |
| 54 |
TDK-Lambda power supply instrument classes that inherit from this parent |
| 55 |
class. Untested commands are noted in docstrings. |
| 56 |
""" |
| 57 |
|
| 58 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 59 |
# Initializer and important communication methods |
| 60 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 61 |
|
| 62 |
def __init__(self, adapter, name="TDK-Lambda Base", address=6, **kwargs): |
| 63 |
super().__init__( |
| 64 |
adapter, |
| 65 |
name, |
| 66 |
includeSCPI=False, |
| 67 |
asrl={'read_termination': "\r", 'write_termination': "\r"}, |
| 68 |
**kwargs |
| 69 |
) |
| 70 |
self.address = address |
| 71 |
|
| 72 |
def check_set_errors(self): |
| 73 |
""" |
| 74 |
Only use this command for setting commands, i.e. non-querying commands. |
| 75 |
|
| 76 |
Any non-querying commands (i.e., a command that does NOT |
| 77 |
have the "?" symbol in it like the instrument command "PV 10") will |
| 78 |
automatically return an "OK" reply for valid command or an error code. |
| 79 |
This is done to confirm that the instrument has received the command. |
| 80 |
Any querying commands (i.e., a command that does have the "?" symbol |
| 81 |
in it like the instrument command "PV?") will return the requested value, |
| 82 |
not the confirmation. |
| 83 |
""" |
| 84 |
response = self.read() |
| 85 |
error_list = [] |
| 86 |
if response != "OK": |
| 87 |
error_list.append(f"Received error: {response}") |
| 88 |
return error_list |
| 89 |
|
| 90 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 91 |
# Properties |
| 92 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 93 |
|
| 94 |
address = Instrument.setting( |
| 95 |
"ADR %d", |
| 96 |
"""Set the address of the power supply. |
| 97 |
|
| 98 |
Valid values are integers between 0 - 30 (inclusive).""", |
| 99 |
check_set_errors=True, |
| 100 |
validator=strict_discrete_set, |
| 101 |
values=range(0, 31) |
| 102 |
) |
| 103 |
|
| 104 |
remote = Instrument.control( |
| 105 |
"RMT?", "RMT %s", |
| 106 |
"""Control the current remote operation of the power supply. |
| 107 |
|
| 108 |
Valid values are ``'LOC'`` for local mode, ``'REM'`` for remote mode, |
| 109 |
and ``'LLO'`` for local lockout mode. |
| 110 |
""", |
| 111 |
check_set_errors=True, |
| 112 |
validator=strict_discrete_set, |
| 113 |
values=["LOC", "REM", "LLO"] |
| 114 |
) |
| 115 |
|
| 116 |
multidrop_capability = Instrument.measurement( |
| 117 |
"MDAV?", |
| 118 |
"""Get whether the multi-drop option is available on the power supply. |
| 119 |
|
| 120 |
If return value is ``False``, the option is not available, if ``True`` it is available. |
| 121 |
|
| 122 |
Property is UNTESTED. |
| 123 |
""", |
| 124 |
cast=bool |
| 125 |
) |
| 126 |
|
| 127 |
master_slave_setting = Instrument.measurement( |
| 128 |
"MS?", |
| 129 |
"""Get the master and slave settings. |
| 130 |
|
| 131 |
Possible master return values are 1, 2, 3, and 4. The slave value is 0. |
| 132 |
|
| 133 |
Property is UNTESTED. |
| 134 |
""" |
| 135 |
) |
| 136 |
|
| 137 |
repeat = Instrument.measurement( |
| 138 |
"\\", |
| 139 |
"""Measure the last command again. |
| 140 |
|
| 141 |
Returns output of the last command. |
| 142 |
""" |
| 143 |
) |
| 144 |
|
| 145 |
id = Instrument.measurement( |
| 146 |
"IDN?", |
| 147 |
"""Get the identity of the instrument. |
| 148 |
|
| 149 |
Returns a list of instrument manufacturer and model in the format: ``["LAMBDA", "GENX-Y"]`` |
| 150 |
""" |
| 151 |
) |
| 152 |
|
| 153 |
version = Instrument.measurement( |
| 154 |
"REV?", |
| 155 |
"""Get the software version on instrument. |
| 156 |
|
| 157 |
Returns the software version as an ASCII string. |
| 158 |
""" |
| 159 |
) |
| 160 |
|
| 161 |
serial = Instrument.measurement( |
| 162 |
"SN?", |
| 163 |
"""Get the serial number of the instrument. |
| 164 |
|
| 165 |
Returns the serial number of of the instrument as an ASCII string. |
| 166 |
""" |
| 167 |
) |
| 168 |
|
| 169 |
last_test_date = Instrument.measurement( |
| 170 |
"DATE?", |
| 171 |
"""Get the date of the last test, possibly calibration date. |
| 172 |
|
| 173 |
Returns a string in the format: yyyy/mm/dd. |
| 174 |
""" |
| 175 |
) |
| 176 |
|
| 177 |
voltage_setpoint = Instrument.control( |
| 178 |
"PV?", "PV %g", |
| 179 |
"""Control the programmed (set) output voltage.""", |
| 180 |
check_set_errors=True, |
| 181 |
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01), |
| 182 |
values=[0, 40], |
| 183 |
dynamic=True |
| 184 |
) |
| 185 |
|
| 186 |
voltage = Instrument.measurement( |
| 187 |
"MV?", |
| 188 |
"""Measure the actual output voltage.""" |
| 189 |
) |
| 190 |
|
| 191 |
current_setpoint = Instrument.control( |
| 192 |
"PC?", "PC %g", |
| 193 |
"""Control the programmed (set) output current.""", |
| 194 |
check_set_errors=True, |
| 195 |
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01), |
| 196 |
values=[0, 38], |
| 197 |
dynamic=True |
| 198 |
) |
| 199 |
|
| 200 |
current = Instrument.measurement( |
| 201 |
"MC?", |
| 202 |
"""Measure the actual output current. |
| 203 |
|
| 204 |
Returns a float with five digits of precision. |
| 205 |
""" |
| 206 |
) |
| 207 |
|
| 208 |
mode = Instrument.measurement( |
| 209 |
"MODE?", |
| 210 |
"""Measure the output mode of the power supply. |
| 211 |
|
| 212 |
When power supply is on, the returned value will be either ``'CV'`` for |
| 213 |
control voltage or ``'CC'`` for or control current. If the power supply |
| 214 |
is off, the returned value will be ``'OFF'``. |
| 215 |
""" |
| 216 |
) |
| 217 |
|
| 218 |
display = Instrument.measurement( |
| 219 |
"DVC?", |
| 220 |
"""Get the displayed voltage and current. |
| 221 |
|
| 222 |
Returns a list of floating point numbers in the order of [ measured voltage, |
| 223 |
programmed voltage, measured current, programmed current, over voltage set point, |
| 224 |
under voltage set point ]. |
| 225 |
""" |
| 226 |
) |
| 227 |
|
| 228 |
status = Instrument.measurement( |
| 229 |
"STT?", |
| 230 |
"""Get the power supply status. |
| 231 |
|
| 232 |
Returns a list in the order of [ actual voltage |
| 233 |
(MV), the programmed voltage (PV), the actual current (MC), the |
| 234 |
programmed current (PC), the status register (SR), and the fault |
| 235 |
register (FR) ]. |
| 236 |
""" |
| 237 |
) |
| 238 |
|
| 239 |
pass_filter = Instrument.control( |
| 240 |
"FILTER?", "FILTER %d", |
| 241 |
"""Control the low pass filter frequency of the A to D converter |
| 242 |
for voltage and current measurement. |
| 243 |
|
| 244 |
Valid frequency values are 18, 23, or 46 Hz. Default value is 18 Hz. |
| 245 |
""", |
| 246 |
check_set_errors=True, |
| 247 |
validator=strict_discrete_set, |
| 248 |
values=[18, 23, 46] |
| 249 |
) |
| 250 |
|
| 251 |
output_enabled = Instrument.control( |
| 252 |
"OUT?", "OUT %s", |
| 253 |
"""Control the output of the power supply. |
| 254 |
|
| 255 |
Valid values are ``True`` to turn output on and ``False`` to turn output off, shutting down |
| 256 |
any voltage or current. |
| 257 |
""", |
| 258 |
check_set_errors=True, |
| 259 |
validator=strict_discrete_set, |
| 260 |
values={True: "ON", False: "OFF"}, |
| 261 |
map_values=True |
| 262 |
) |
| 263 |
|
| 264 |
foldback_enabled = Instrument.control( |
| 265 |
"FLD?", "FLD %s", |
| 266 |
"""Control the fold back protection of the power supply. |
| 267 |
|
| 268 |
Valid values are ``True`` to arm the fold back protection and ``False`` |
| 269 |
to cancel the fold back protection. |
| 270 |
""", |
| 271 |
check_set_errors=True, |
| 272 |
validator=strict_discrete_set, |
| 273 |
values={True: "ON", False: "OFF"}, |
| 274 |
map_values=True |
| 275 |
) |
| 276 |
|
| 277 |
foldback_delay = Instrument.control( |
| 278 |
"FBD?", "FBD %g", |
| 279 |
"""Control the fold back delay. |
| 280 |
|
| 281 |
Adds an additional delay to the standard fold back delay (250 ms) by |
| 282 |
multiplying the set value by 0.1. Valid values are integers between |
| 283 |
0 to 255. |
| 284 |
""", |
| 285 |
check_set_errors=True, |
| 286 |
validator=strict_range, |
| 287 |
values=[0, 255], |
| 288 |
cast=int |
| 289 |
) |
| 290 |
|
| 291 |
over_voltage = Instrument.control( |
| 292 |
"OVP?", "OVP %g", |
| 293 |
"""Control the over voltage protection. |
| 294 |
""", |
| 295 |
check_set_errors=True, |
| 296 |
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01), |
| 297 |
values=[2, 44], |
| 298 |
dynamic=True |
| 299 |
) |
| 300 |
|
| 301 |
under_voltage = Instrument.control( |
| 302 |
"UVL?", "UVL %g", |
| 303 |
"""Control the under voltage limit. |
| 304 |
|
| 305 |
Property is UNTESTED. |
| 306 |
""", |
| 307 |
check_set_errors=True, |
| 308 |
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01), |
| 309 |
values=[0, 38], |
| 310 |
dynamic=True |
| 311 |
) |
| 312 |
|
| 313 |
auto_restart_enabled = Instrument.control( |
| 314 |
"AST?", "AST %s", |
| 315 |
"""Control the auto restart mode, which restores the power supply to the last |
| 316 |
output voltage and current settings with output enabled on startup. |
| 317 |
|
| 318 |
Valid values are ``True`` to restore output settings with output enabled on startup |
| 319 |
and ``False`` to disable restoration of settings and output disabled on startup. |
| 320 |
""", |
| 321 |
check_set_errors=True, |
| 322 |
validator=strict_discrete_set, |
| 323 |
values={True: "ON", False: "OFF"}, |
| 324 |
map_values=True |
| 325 |
) |
| 326 |
|
| 327 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 328 |
# Methods |
| 329 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 330 |
|
| 331 |
def clear(self): |
| 332 |
"""Clear FEVE and SEVE registers to zero.""" |
| 333 |
self.write("CLS") |
| 334 |
self.check_errors() |
| 335 |
|
| 336 |
def reset(self): |
| 337 |
"""Reset the instrument to default values.""" |
| 338 |
self.write("RST") |
| 339 |
self.check_errors() |
| 340 |
|
| 341 |
def foldback_reset(self): |
| 342 |
"""Reset the fold back delay to 0 s, restoring the standard 250 ms |
| 343 |
delay. |
| 344 |
|
| 345 |
Property is UNTESTED. |
| 346 |
""" |
| 347 |
self.write("FDBRST") |
| 348 |
self.check_errors() |
| 349 |
|
| 350 |
def save(self): |
| 351 |
"""Save current instrument settings.""" |
| 352 |
self.write("SAV") |
| 353 |
self.check_errors() |
| 354 |
|
| 355 |
def recall(self): |
| 356 |
"""Recall last saved instrument settings.""" |
| 357 |
self.write("RCL") |
| 358 |
self.check_errors() |
| 359 |
|
| 360 |
def set_max_over_voltage(self): |
| 361 |
"""Set the over voltage protection to the maximum level for the power |
| 362 |
supply. |
| 363 |
""" |
| 364 |
self.write("OVM") |
| 365 |
self.check_errors() |
| 366 |
|
| 367 |
def ramp_to_current(self, target_current, steps=20, pause=0.2): |
| 368 |
"""Ramps to a target current from the set current value over |
| 369 |
a certain number of linear steps, each separated by a pause duration. |
| 370 |
|
| 371 |
:param target_current: Target current in amps |
| 372 |
:param steps: Integer number of steps |
| 373 |
:param pause: Pause duration in seconds to wait between steps |
| 374 |
""" |
| 375 |
|
| 376 |
currents = [round(i, 2) for i in np.linspace(self.current_setpoint, |
| 377 |
target_current, steps)] |
| 378 |
for current in currents: |
| 379 |
self.current_setpoint = current |
| 380 |
sleep(pause) |
| 381 |
|
| 382 |
def shutdown(self): |
| 383 |
"""Safety shutdown the power supply. |
| 384 |
|
| 385 |
Ramps the power supply down to zero current using the |
| 386 |
``self.ramp_to_current(0.0)`` method and turns the output off. |
| 387 |
""" |
| 388 |
log.info("Shutting down %s." % self.name) |
| 389 |
self.ramp_to_current(0.0) |
| 390 |
self.output_enabled = False |
| 391 |
super().shutdown() |