| 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 pymeasure.instruments.validators import strict_discrete_set |
| 27 |
|
| 28 |
import logging |
| 29 |
from warnings import warn |
| 30 |
|
| 31 |
log = logging.getLogger(__name__) |
| 32 |
log.addHandler(logging.NullHandler()) |
| 33 |
|
| 34 |
|
| 35 |
class Keithley2260B(SCPIMixin, Instrument): |
| 36 |
""" Represents the Keithley 2260B Power Supply (minimal implementation) |
| 37 |
and provides a high-level interface for interacting with the instrument. |
| 38 |
|
| 39 |
For a connection through tcpip, the device only accepts |
| 40 |
connections at port 2268, which cannot be configured otherwise. |
| 41 |
example connection string: 'TCPIP::xxx.xxx.xxx.xxx::2268::SOCKET' |
| 42 |
the read termination for this interface is \n |
| 43 |
|
| 44 |
.. code-block:: python |
| 45 |
|
| 46 |
source = Keithley2260B("GPIB::1") |
| 47 |
source.voltage = 1 |
| 48 |
print(source.voltage) |
| 49 |
print(source.current) |
| 50 |
print(source.power) |
| 51 |
print(source.applied) |
| 52 |
""" |
| 53 |
|
| 54 |
def __init__(self, adapter, name="Keithley 2260B DC Power Supply", |
| 55 |
read_termination="\n", **kwargs): |
| 56 |
super().__init__( |
| 57 |
adapter, |
| 58 |
name, |
| 59 |
read_termination=read_termination, |
| 60 |
**kwargs |
| 61 |
) |
| 62 |
|
| 63 |
output_enabled = Instrument.control( |
| 64 |
"OUTPut?", |
| 65 |
"OUTPut %d", |
| 66 |
"""Control whether the source is enabled, takes values True or False. (bool)""", |
| 67 |
validator=strict_discrete_set, |
| 68 |
values={True: 1, False: 0}, |
| 69 |
map_values=True, |
| 70 |
) |
| 71 |
|
| 72 |
current_limit = Instrument.control( |
| 73 |
":SOUR:CURR?", |
| 74 |
":SOUR:CURR %g", |
| 75 |
"""Control the source current in amps. This is not checked against the allowed range. |
| 76 |
Depending on whether the instrument is in constant current or constant voltage mode, |
| 77 |
this might differ from the actual current achieved. (float)""", |
| 78 |
) |
| 79 |
|
| 80 |
voltage_setpoint = Instrument.control( |
| 81 |
":SOUR:VOLT?", |
| 82 |
":SOUR:VOLT %g", |
| 83 |
"""Control the source voltage in volts. This is not checked against the allowed range. |
| 84 |
Depending on whether the instrument is in constant current or constant voltage mode, |
| 85 |
this might differ from the actual voltage achieved. (float)""", |
| 86 |
) |
| 87 |
|
| 88 |
power = Instrument.measurement( |
| 89 |
":MEAS:POW?", |
| 90 |
"""Get the power (in Watt) the dc power supply is putting out. |
| 91 |
""", |
| 92 |
) |
| 93 |
|
| 94 |
voltage = Instrument.measurement( |
| 95 |
":MEAS:VOLT?", |
| 96 |
"""Get the voltage (in Volt) the dc power supply is putting out. |
| 97 |
""", |
| 98 |
) |
| 99 |
|
| 100 |
current = Instrument.measurement( |
| 101 |
":MEAS:CURR?", |
| 102 |
"""Get the current (in Ampere) the dc power supply is putting out. |
| 103 |
""", |
| 104 |
) |
| 105 |
|
| 106 |
applied = Instrument.control( |
| 107 |
":APPly?", |
| 108 |
":APPly %g,%g", |
| 109 |
"""Control voltage (volts) and current (amps) simultaneously. |
| 110 |
Values need to be supplied as tuple of (voltage, current). Depending on |
| 111 |
whether the instrument is in constant current or constant voltage mode, |
| 112 |
the values achieved by the instrument will differ from the ones set. |
| 113 |
""", |
| 114 |
) |
| 115 |
|
| 116 |
@property |
| 117 |
def error(self): |
| 118 |
"""Get the next error of the instrument (list of code and message).""" |
| 119 |
warn("Deprecated to use `error`, use `next_error` instead.", FutureWarning) |
| 120 |
return self.next_error |
| 121 |
|
| 122 |
@property |
| 123 |
def enabled(self): |
| 124 |
"""Control whether the output is enabled, see :attr:`output_enabled`.""" |
| 125 |
log.warning('Deprecated property name "enabled", use the identical "output_enabled", ' |
| 126 |
'instead.', FutureWarning) |
| 127 |
return self.output_enabled |
| 128 |
|
| 129 |
@enabled.setter |
| 130 |
def enabled(self, value): |
| 131 |
log.warning('Deprecated property name "enabled", use the identical "output_enabled", ' |
| 132 |
'instead.', FutureWarning) |
| 133 |
self.output_enabled = value |
| 134 |
|
| 135 |
def shutdown(self): |
| 136 |
""" Disable output, call parent function""" |
| 137 |
self.output_enabled = False |
| 138 |
super().shutdown() |