| 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 |
import logging |
| 26 |
from pymeasure.instruments import Instrument, SCPIUnknownMixin |
| 27 |
from pymeasure.instruments.validators import ( |
| 28 |
strict_discrete_set, truncated_discrete_set, truncated_range |
| 29 |
) |
| 30 |
|
| 31 |
log = logging.getLogger(__name__) |
| 32 |
log.addHandler(logging.NullHandler()) |
| 33 |
|
| 34 |
MIN_RAMP_TIME = 0.1 # seconds |
| 35 |
|
| 36 |
|
| 37 |
class YokogawaGS200(SCPIUnknownMixin, Instrument): |
| 38 |
""" Represents the Yokogawa GS200 source and provides a high-level interface for interacting |
| 39 |
with the instrument. """ |
| 40 |
|
| 41 |
source_enabled = Instrument.control( |
| 42 |
"OUTPut:STATe?", |
| 43 |
"OUTPut:STATe %d", |
| 44 |
"""Control whether the source is enabled. (bool)""", |
| 45 |
validator=strict_discrete_set, |
| 46 |
values={True: 1, False: 0}, |
| 47 |
map_values=True |
| 48 |
) |
| 49 |
|
| 50 |
source_mode = Instrument.control( |
| 51 |
":SOURce:FUNCtion?", |
| 52 |
":SOURce:FUNCtion %s", |
| 53 |
"""Control the source mode. Can be either 'current' or 'voltage'.""", |
| 54 |
validator=strict_discrete_set, |
| 55 |
values={'current': 'CURR', 'voltage': 'VOLT'}, |
| 56 |
get_process=lambda s: s.strip() |
| 57 |
) |
| 58 |
|
| 59 |
source_range = Instrument.control( |
| 60 |
":SOURce:RANGe?", |
| 61 |
"SOURce:RANGe %g", |
| 62 |
"""Control the range (either in voltage or current) |
| 63 |
of the output. "Range" refers to the maximum source level. (float)""", |
| 64 |
validator=truncated_discrete_set, |
| 65 |
values=[1e-3, 10e-3, 100e-3, 200e-3, 1, 10, 30] |
| 66 |
) |
| 67 |
|
| 68 |
voltage_limit = Instrument.control( |
| 69 |
"SOURce:PROTection:VOLTage?", |
| 70 |
"SOURce:PROTection:VOLTage %g", |
| 71 |
"""Control the voltage limit. "Limit" refers to maximum |
| 72 |
value of the electrical value that is conjugate to the mode (current is conjugate to |
| 73 |
voltage, and vice versa). Thus, voltage limit is only applicable when in 'current' mode""", |
| 74 |
validator=truncated_range, |
| 75 |
values=[1, 30] |
| 76 |
) |
| 77 |
|
| 78 |
current_limit = Instrument.control( |
| 79 |
"SOURce:PROTection:CURRent?", |
| 80 |
"SOURce:PROTection:CURRent %g", |
| 81 |
"""Control the current limit. "Limit" refers to maximum value |
| 82 |
of the electrical value that is conjugate to the mode (current is conjugate to voltage, |
| 83 |
and vice versa). Thus, current limit is only applicable when in 'voltage' mode""", |
| 84 |
validator=truncated_range, |
| 85 |
values=[1e-3, 200e-3] |
| 86 |
) |
| 87 |
|
| 88 |
def __init__(self, adapter, name="Yokogawa GS200 Source", **kwargs): |
| 89 |
super().__init__( |
| 90 |
adapter, name, **kwargs |
| 91 |
) |
| 92 |
|
| 93 |
@property |
| 94 |
def source_level(self): |
| 95 |
""" Control the output level, either a voltage or a current, |
| 96 |
depending on the source mode. (float) |
| 97 |
""" |
| 98 |
return float(self.ask(":SOURce:LEVel?")) |
| 99 |
|
| 100 |
@source_level.setter |
| 101 |
def source_level(self, level): |
| 102 |
if level > self.source_range * 1.2: |
| 103 |
raise ValueError( |
| 104 |
"Level must be within 1.2 * source_range, otherwise the Yokogawa will produce an " |
| 105 |
"error." |
| 106 |
) |
| 107 |
else: |
| 108 |
self.write("SOURce:LEVel %g" % level) |
| 109 |
|
| 110 |
def trigger_ramp_to_level(self, level, ramp_time): |
| 111 |
""" |
| 112 |
Ramp the output level from its current value to "level" in time "ramp_time". This method |
| 113 |
will NOT wait until the ramp is finished (thus, it will not block further code evaluation). |
| 114 |
|
| 115 |
:param float level: final output level |
| 116 |
:param float ramp_time: time in seconds to ramp |
| 117 |
:return: None |
| 118 |
""" |
| 119 |
if not self.source_enabled: |
| 120 |
raise ValueError( |
| 121 |
"YokogawaGS200 source must be enabled in order to ramp to a specified level. " |
| 122 |
"Otherwise, the Yokogawa will reject the ramp." |
| 123 |
) |
| 124 |
if ramp_time < MIN_RAMP_TIME: |
| 125 |
log.warning( |
| 126 |
f"Ramp time of {ramp_time}s is below the minimum ramp time of {MIN_RAMP_TIME}s, " |
| 127 |
f"so the Yokogawa will instead be instantaneously set to the desired level." |
| 128 |
) |
| 129 |
self.source_level = level |
| 130 |
else: |
| 131 |
# Use the Yokogawa's "program" mode to create the ramp |
| 132 |
ramp_program = ( |
| 133 |
f":program:edit:start;" |
| 134 |
f":source:level {level};" |
| 135 |
f":program:edit:end;" |
| 136 |
) |
| 137 |
# set "interval time" equal to "slope time" to make a continuous ramp |
| 138 |
ramp_program += ( |
| 139 |
f":program:interval {ramp_time};" |
| 140 |
f":program:slope {ramp_time};" |
| 141 |
) |
| 142 |
# run it once |
| 143 |
ramp_program += ( |
| 144 |
":program:repeat 0;" |
| 145 |
":program:run" |
| 146 |
) |
| 147 |
self.write(ramp_program) |