| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2022 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, Channel, SCPIUnknownMixin |
| 27 |
from pymeasure.instruments.validators import strict_discrete_set, strict_range |
| 28 |
|
| 29 |
log = logging.getLogger(__name__) |
| 30 |
log.addHandler(logging.NullHandler()) |
| 31 |
|
| 32 |
|
| 33 |
class PSChannel(Channel): |
| 34 |
"""Implementation of a Keithley 2200 channel.""" |
| 35 |
|
| 36 |
VOLTAGE_RANGE = [0, 70] |
| 37 |
CURRENT_RANGE = [0, 45] |
| 38 |
|
| 39 |
output_enabled = Instrument.control( |
| 40 |
"SOURCE:OUTP:ENAB?", |
| 41 |
"SOURCE:OUTP:ENAB %d", |
| 42 |
""" Control the output state.""", |
| 43 |
validator=strict_discrete_set, |
| 44 |
values={True: 1, False: 0}, |
| 45 |
map_values=True, |
| 46 |
) |
| 47 |
|
| 48 |
voltage_setpoint = Instrument.control( |
| 49 |
"VOLT?", |
| 50 |
"VOLT %g", |
| 51 |
""" Control output voltage in Volts.""", |
| 52 |
validator=strict_range, |
| 53 |
values=VOLTAGE_RANGE, |
| 54 |
) |
| 55 |
|
| 56 |
current_limit = Instrument.control( |
| 57 |
"CURR?", |
| 58 |
"CURR %g", |
| 59 |
""" Control output current in Amps.""", |
| 60 |
validator=strict_range, |
| 61 |
values=CURRENT_RANGE, |
| 62 |
) |
| 63 |
|
| 64 |
current = Instrument.measurement( |
| 65 |
"MEAS:CURR?", |
| 66 |
""" Measure the current in Amps.""", |
| 67 |
) |
| 68 |
|
| 69 |
voltage = Instrument.measurement( |
| 70 |
"MEAS:VOLT?", |
| 71 |
""" Measure the voltage in Volts.""", |
| 72 |
) |
| 73 |
|
| 74 |
power = Instrument.measurement( |
| 75 |
"MEAS:POW?", |
| 76 |
""" Measure the power in watts.""", |
| 77 |
) |
| 78 |
|
| 79 |
voltage_limit = Instrument.control( |
| 80 |
"VOLT:LIM?", |
| 81 |
"VOLT:LIM %g", |
| 82 |
""" Control the maximum voltage that can be set.""", |
| 83 |
validator=strict_range, |
| 84 |
values=VOLTAGE_RANGE, |
| 85 |
) |
| 86 |
|
| 87 |
voltage_limit_enabled = Instrument.control( |
| 88 |
"VOLT:LIM:STAT?", |
| 89 |
"VOLT:LIM:STAT %d", |
| 90 |
""" Control whether the maximum voltage limit is enabled.""", |
| 91 |
validator=strict_discrete_set, |
| 92 |
values={True: 1, False: 0}, |
| 93 |
map_values=True, |
| 94 |
) |
| 95 |
|
| 96 |
def insert_id(self, command): |
| 97 |
return f"INST:SEL CH{self.id};{command}" |
| 98 |
|
| 99 |
|
| 100 |
class Keithley2200(SCPIUnknownMixin, Instrument): |
| 101 |
"""Represents the Keithley 2200 Power Supply.""" |
| 102 |
|
| 103 |
def __init__(self, adapter, name="Keithley2200", **kwargs): |
| 104 |
super().__init__(adapter, name, **kwargs) |
| 105 |
|
| 106 |
ch_1 = Instrument.ChannelCreator(PSChannel, 1) |
| 107 |
|
| 108 |
ch_2 = Instrument.ChannelCreator(PSChannel, 2) |
| 109 |
|
| 110 |
ch_3 = Instrument.ChannelCreator(PSChannel, 3) |
| 111 |
|
| 112 |
display_enabled = Instrument.control( |
| 113 |
"DISP?", |
| 114 |
":DISP %d", |
| 115 |
"""Control whether the display is enabled.""", |
| 116 |
validator=strict_discrete_set, |
| 117 |
values={True: 1, False: 0}, |
| 118 |
map_values=True, |
| 119 |
) |
| 120 |
|
| 121 |
display_text_data = Instrument.control( |
| 122 |
":DISP:TEXT:DATA?", |
| 123 |
":DISP:TEXT:DATA '%s'", |
| 124 |
"""Control text to be displayed(32 characters).""", |
| 125 |
get_process=lambda v: v.replace('"', ""), |
| 126 |
) |