| 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 |
|
| 27 |
from pymeasure.instruments import Instrument, SCPIUnknownMixin |
| 28 |
from pymeasure.instruments.validators import strict_discrete_set |
| 29 |
from pyvisa.constants import Parity |
| 30 |
from enum import IntEnum |
| 31 |
|
| 32 |
log = logging.getLogger(__name__) |
| 33 |
log.addHandler(logging.NullHandler()) |
| 34 |
|
| 35 |
|
| 36 |
class LakeShore211(SCPIUnknownMixin, Instrument): |
| 37 |
""" Represents the Lake Shore 211 Temperature Monitor and provides |
| 38 |
a high-level interface for interacting with the instrument. |
| 39 |
|
| 40 |
Untested properties and methods will be noted in their docstrings. |
| 41 |
|
| 42 |
.. code-block:: python |
| 43 |
|
| 44 |
controller = LakeShore211("GPIB::1") |
| 45 |
|
| 46 |
print(controller.temperature_celsius) # Print the sensor temperature in celsius |
| 47 |
|
| 48 |
""" |
| 49 |
|
| 50 |
class AnalogMode(IntEnum): |
| 51 |
VOLTAGE = 0 |
| 52 |
CURRENT = 1 |
| 53 |
|
| 54 |
class AnalogRange(IntEnum): |
| 55 |
RANGE_20K = 0 |
| 56 |
RANGE_100K = 1 |
| 57 |
RANGE_200K = 2 |
| 58 |
RANGE_325K = 3 |
| 59 |
RANGE_475K = 4 |
| 60 |
RANGE_1000K = 5 |
| 61 |
|
| 62 |
class RelayNumber(IntEnum): |
| 63 |
RELAY_ONE = 1 |
| 64 |
RELAY_TWO = 2 |
| 65 |
|
| 66 |
class RelayMode(IntEnum): |
| 67 |
OFF = 0 |
| 68 |
ON = 1 |
| 69 |
ALARMS = 2 |
| 70 |
|
| 71 |
alarm_keys = ['on', 'high_value', 'low_value', 'deadband', 'latch'] |
| 72 |
|
| 73 |
def __init__(self, adapter, name="Lake Shore 211 Temperature Monitor", **kwargs): |
| 74 |
super().__init__( |
| 75 |
adapter, |
| 76 |
name, |
| 77 |
asrl={'data_bits': 7, 'parity': Parity.odd}, |
| 78 |
**kwargs |
| 79 |
) |
| 80 |
|
| 81 |
analog_configuration = Instrument.control( |
| 82 |
"ANALOG?", "ANALOG %d,%d", |
| 83 |
""" |
| 84 |
Control the analog mode and analog range. |
| 85 |
Values need to be supplied as a tuple of (analog mode, analog range) |
| 86 |
Analog mode can be 0 or 1 |
| 87 |
|
| 88 |
+--------+--------+ |
| 89 |
| setting| mode | |
| 90 |
+--------+--------+ |
| 91 |
| 0 | voltage| |
| 92 |
+--------+--------+ |
| 93 |
| 1 | current| |
| 94 |
+--------+--------+ |
| 95 |
|
| 96 |
Analog range can be 0 through 5 |
| 97 |
|
| 98 |
+--------+----------+ |
| 99 |
| setting| range | |
| 100 |
+--------+----------+ |
| 101 |
| 0 | 0 – 20 K | |
| 102 |
+--------+----------+ |
| 103 |
| 1 | 0 – 100 K| |
| 104 |
+--------+----------+ |
| 105 |
| 2 | 0 – 200 K| |
| 106 |
+--------+----------+ |
| 107 |
| 3 | 0 – 325 K| |
| 108 |
+--------+----------+ |
| 109 |
| 4 | 0 – 475 K| |
| 110 |
+--------+----------+ |
| 111 |
| 5 |0 – 1000 K| |
| 112 |
+--------+----------+ |
| 113 |
""", |
| 114 |
# Validate and return tuple v |
| 115 |
validator=lambda v, vs: ( |
| 116 |
strict_discrete_set(v[0], vs[0]), strict_discrete_set(v[1], vs[1])), |
| 117 |
values=[list(AnalogMode), list(AnalogRange)], |
| 118 |
# These are the vs values in the validator lambda |
| 119 |
get_process=lambda x: (LakeShore211.AnalogMode(x[0]), LakeShore211.AnalogRange(x[1])), |
| 120 |
cast=int |
| 121 |
) |
| 122 |
|
| 123 |
analog_out = Instrument.measurement( |
| 124 |
"AOUT?", |
| 125 |
"""Measure the percentage of output of the analog output. |
| 126 |
""" |
| 127 |
) |
| 128 |
|
| 129 |
display_units = Instrument.control( |
| 130 |
"DISPFLD?", "DISPFLD %d", |
| 131 |
""" |
| 132 |
Control the input data to display. Valid entries: |
| 133 |
|
| 134 |
+-------------+--------------+ |
| 135 |
| setting | units | |
| 136 |
+-------------+--------------+ |
| 137 |
| 'kelvin' | Kelvin | |
| 138 |
+-------------+--------------+ |
| 139 |
| 'celsius' | Celsius | |
| 140 |
+-------------+--------------+ |
| 141 |
| 'sensor' | Sensor Units | |
| 142 |
+-------------+--------------+ |
| 143 |
| 'fahrenheit'| Fahrenheit | |
| 144 |
+-------------+--------------+ |
| 145 |
""", |
| 146 |
values={'kelvin': 0, 'celsius': 1, 'sensor': 2, 'fahrenheit': 3}, |
| 147 |
map_values=True |
| 148 |
) |
| 149 |
|
| 150 |
temperature_celsius = Instrument.measurement( |
| 151 |
"CRDG?", |
| 152 |
"""Measure the temperature of the sensor in celsius |
| 153 |
""" |
| 154 |
) |
| 155 |
|
| 156 |
temperature_fahrenheit = Instrument.measurement( |
| 157 |
"FRDG?", |
| 158 |
"""Measure the temperature of the sensor in fahrenheit |
| 159 |
""" |
| 160 |
) |
| 161 |
|
| 162 |
temperature_sensor = Instrument.measurement( |
| 163 |
"SRDG?", |
| 164 |
"""Measure the temperature of the sensor in sensor units |
| 165 |
""" |
| 166 |
) |
| 167 |
|
| 168 |
temperature_kelvin = Instrument.measurement( |
| 169 |
"KRDG?", |
| 170 |
"""Measure the temperature of the sensor in kelvin |
| 171 |
""" |
| 172 |
) |
| 173 |
|
| 174 |
def get_relay_mode(self, relay): |
| 175 |
""" |
| 176 |
Get the status of a relay |
| 177 |
|
| 178 |
Property is UNTESTED |
| 179 |
|
| 180 |
:param RelayNumber relay: Specify which relay to query |
| 181 |
:return: Current RelayMode of queried relay |
| 182 |
""" |
| 183 |
relay = strict_discrete_set(relay, list(self.RelayNumber)) |
| 184 |
return int(self.ask("RELAY? %d" % relay)) |
| 185 |
|
| 186 |
def configure_relay(self, relay, mode): |
| 187 |
""" |
| 188 |
Configure the relay mode of a relay |
| 189 |
|
| 190 |
Property is UNTESTED |
| 191 |
|
| 192 |
:param RelayNumber relay: Specify which relay to configure |
| 193 |
:param RelayMode mode: Specify which mode to assign |
| 194 |
""" |
| 195 |
relay = strict_discrete_set(relay, list(self.RelayNumber)) |
| 196 |
mode = strict_discrete_set(mode, list(self.RelayMode)) |
| 197 |
self.write('RELAY %d %d' % (relay, mode)) |
| 198 |
|
| 199 |
def get_alarm_status(self): |
| 200 |
""" |
| 201 |
Query the current alarm status |
| 202 |
|
| 203 |
:return: Dictionary of current status [on, high_value, low_value, deadband, latch] |
| 204 |
""" |
| 205 |
|
| 206 |
status = self.values('ALARM?') |
| 207 |
return dict(zip(self.alarm_keys, |
| 208 |
[int(status[0]), float(status[1]), float(status[2]), float(status[3]), |
| 209 |
int(status[4])])) |
| 210 |
|
| 211 |
def configure_alarm(self, on=True, high_value=270.0, low_value=0.0, deadband=0, latch=False): |
| 212 |
"""Configures the alarm parameters for the input. |
| 213 |
|
| 214 |
:param on: Boolean setting of alarm, default True |
| 215 |
:param high_value: High value the temperature is checked against to activate the alarm |
| 216 |
:param low_value: Low value the temperature is checked against to activate the alarm |
| 217 |
:param deadband: Value that the temperature must change outside of an alarm condition |
| 218 |
:param latch: Specifies if the alarm should latch or not |
| 219 |
""" |
| 220 |
|
| 221 |
command_string = "ALARM %d,%g,%g,%g,%d" % (on, high_value, low_value, deadband, latch) |
| 222 |
self.write(command_string) |
| 223 |
|
| 224 |
def reset_alarm(self): |
| 225 |
"""Resets the alarm of the Lakeshore 211 |
| 226 |
""" |
| 227 |
self.write('ALMRST') |