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
|
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# =============================================================================
# Libraries / modules
# =============================================================================
from pymeasure.instruments import Instrument
from pymeasure.instruments.validators import strict_range
from pymeasure.instruments.validators import strict_discrete_set
from pymeasure.instruments.validators import strict_discrete_range
import logging
from time import sleep
import numpy as np
# =============================================================================
# Logging
# =============================================================================
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
# =============================================================================
# Instrument file
# =============================================================================
class TDK_Lambda_Base(Instrument):
"""
This is the base class for TDK Lambda Genesys Series DC power supplies.
Do not directly instantiate an object with this class. Use one of the
TDK-Lambda power supply instrument classes that inherit from this parent
class. Untested commands are noted in docstrings.
"""
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Initializer and important communication methods
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self, adapter, name="TDK-Lambda Base", address=6, **kwargs):
super().__init__(
adapter,
name,
includeSCPI=False,
asrl={'read_termination': "\r", 'write_termination': "\r"},
**kwargs
)
self.address = address
def check_set_errors(self):
"""
Only use this command for setting commands, i.e. non-querying commands.
Any non-querying commands (i.e., a command that does NOT
have the "?" symbol in it like the instrument command "PV 10") will
automatically return an "OK" reply for valid command or an error code.
This is done to confirm that the instrument has received the command.
Any querying commands (i.e., a command that does have the "?" symbol
in it like the instrument command "PV?") will return the requested value,
not the confirmation.
"""
response = self.read()
error_list = []
if response != "OK":
error_list.append(f"Received error: {response}")
return error_list
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Properties
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
address = Instrument.setting(
"ADR %d",
"""Set the address of the power supply.
Valid values are integers between 0 - 30 (inclusive).""",
check_set_errors=True,
validator=strict_discrete_set,
values=range(0, 31)
)
remote = Instrument.control(
"RMT?", "RMT %s",
"""Control the current remote operation of the power supply.
Valid values are ``'LOC'`` for local mode, ``'REM'`` for remote mode,
and ``'LLO'`` for local lockout mode.
""",
check_set_errors=True,
validator=strict_discrete_set,
values=["LOC", "REM", "LLO"]
)
multidrop_capability = Instrument.measurement(
"MDAV?",
"""Get whether the multi-drop option is available on the power supply.
If return value is ``False``, the option is not available, if ``True`` it is available.
Property is UNTESTED.
""",
cast=bool
)
master_slave_setting = Instrument.measurement(
"MS?",
"""Get the master and slave settings.
Possible master return values are 1, 2, 3, and 4. The slave value is 0.
Property is UNTESTED.
"""
)
repeat = Instrument.measurement(
"\\",
"""Measure the last command again.
Returns output of the last command.
"""
)
id = Instrument.measurement(
"IDN?",
"""Get the identity of the instrument.
Returns a list of instrument manufacturer and model in the format: ``["LAMBDA", "GENX-Y"]``
"""
)
version = Instrument.measurement(
"REV?",
"""Get the software version on instrument.
Returns the software version as an ASCII string.
"""
)
serial = Instrument.measurement(
"SN?",
"""Get the serial number of the instrument.
Returns the serial number of of the instrument as an ASCII string.
"""
)
last_test_date = Instrument.measurement(
"DATE?",
"""Get the date of the last test, possibly calibration date.
Returns a string in the format: yyyy/mm/dd.
"""
)
voltage_setpoint = Instrument.control(
"PV?", "PV %g",
"""Control the programmed (set) output voltage.""",
check_set_errors=True,
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01),
values=[0, 40],
dynamic=True
)
voltage = Instrument.measurement(
"MV?",
"""Measure the actual output voltage."""
)
current_setpoint = Instrument.control(
"PC?", "PC %g",
"""Control the programmed (set) output current.""",
check_set_errors=True,
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01),
values=[0, 38],
dynamic=True
)
current = Instrument.measurement(
"MC?",
"""Measure the actual output current.
Returns a float with five digits of precision.
"""
)
mode = Instrument.measurement(
"MODE?",
"""Measure the output mode of the power supply.
When power supply is on, the returned value will be either ``'CV'`` for
control voltage or ``'CC'`` for or control current. If the power supply
is off, the returned value will be ``'OFF'``.
"""
)
display = Instrument.measurement(
"DVC?",
"""Get the displayed voltage and current.
Returns a list of floating point numbers in the order of [ measured voltage,
programmed voltage, measured current, programmed current, over voltage set point,
under voltage set point ].
"""
)
status = Instrument.measurement(
"STT?",
"""Get the power supply status.
Returns a list in the order of [ actual voltage
(MV), the programmed voltage (PV), the actual current (MC), the
programmed current (PC), the status register (SR), and the fault
register (FR) ].
"""
)
pass_filter = Instrument.control(
"FILTER?", "FILTER %d",
"""Control the low pass filter frequency of the A to D converter
for voltage and current measurement.
Valid frequency values are 18, 23, or 46 Hz. Default value is 18 Hz.
""",
check_set_errors=True,
validator=strict_discrete_set,
values=[18, 23, 46]
)
output_enabled = Instrument.control(
"OUT?", "OUT %s",
"""Control the output of the power supply.
Valid values are ``True`` to turn output on and ``False`` to turn output off, shutting down
any voltage or current.
""",
check_set_errors=True,
validator=strict_discrete_set,
values={True: "ON", False: "OFF"},
map_values=True
)
foldback_enabled = Instrument.control(
"FLD?", "FLD %s",
"""Control the fold back protection of the power supply.
Valid values are ``True`` to arm the fold back protection and ``False``
to cancel the fold back protection.
""",
check_set_errors=True,
validator=strict_discrete_set,
values={True: "ON", False: "OFF"},
map_values=True
)
foldback_delay = Instrument.control(
"FBD?", "FBD %g",
"""Control the fold back delay.
Adds an additional delay to the standard fold back delay (250 ms) by
multiplying the set value by 0.1. Valid values are integers between
0 to 255.
""",
check_set_errors=True,
validator=strict_range,
values=[0, 255],
cast=int
)
over_voltage = Instrument.control(
"OVP?", "OVP %g",
"""Control the over voltage protection.
""",
check_set_errors=True,
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01),
values=[2, 44],
dynamic=True
)
under_voltage = Instrument.control(
"UVL?", "UVL %g",
"""Control the under voltage limit.
Property is UNTESTED.
""",
check_set_errors=True,
validator=lambda v, vs: strict_discrete_range(v, vs, step=0.01),
values=[0, 38],
dynamic=True
)
auto_restart_enabled = Instrument.control(
"AST?", "AST %s",
"""Control the auto restart mode, which restores the power supply to the last
output voltage and current settings with output enabled on startup.
Valid values are ``True`` to restore output settings with output enabled on startup
and ``False`` to disable restoration of settings and output disabled on startup.
""",
check_set_errors=True,
validator=strict_discrete_set,
values={True: "ON", False: "OFF"},
map_values=True
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Methods
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def clear(self):
"""Clear FEVE and SEVE registers to zero."""
self.write("CLS")
self.check_errors()
def reset(self):
"""Reset the instrument to default values."""
self.write("RST")
self.check_errors()
def foldback_reset(self):
"""Reset the fold back delay to 0 s, restoring the standard 250 ms
delay.
Property is UNTESTED.
"""
self.write("FDBRST")
self.check_errors()
def save(self):
"""Save current instrument settings."""
self.write("SAV")
self.check_errors()
def recall(self):
"""Recall last saved instrument settings."""
self.write("RCL")
self.check_errors()
def set_max_over_voltage(self):
"""Set the over voltage protection to the maximum level for the power
supply.
"""
self.write("OVM")
self.check_errors()
def ramp_to_current(self, target_current, steps=20, pause=0.2):
"""Ramps to a target current from the set current value over
a certain number of linear steps, each separated by a pause duration.
:param target_current: Target current in amps
:param steps: Integer number of steps
:param pause: Pause duration in seconds to wait between steps
"""
currents = [round(i, 2) for i in np.linspace(self.current_setpoint,
target_current, steps)]
for current in currents:
self.current_setpoint = current
sleep(pause)
def shutdown(self):
"""Safety shutdown the power supply.
Ramps the power supply down to zero current using the
``self.ramp_to_current(0.0)`` method and turns the output off.
"""
log.info("Shutting down %s." % self.name)
self.ramp_to_current(0.0)
self.output_enabled = False
super().shutdown()
|