Skip to content

Commit

Permalink
Restructure the Lakeshore instrument drivers , add Lakeshore 224. (#870)
Browse files Browse the repository at this point in the history
Use the new channels feature.
Add a driver for the model 224 which uses the temperature input channel class.
  • Loading branch information
samcondon4 committed Mar 11, 2023
1 parent eb9ee9c commit 55752c0
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 77 deletions.
16 changes: 16 additions & 0 deletions docs/api/instruments/lakeshore/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ Lake Shore Cryogenics
#####################

This section contains specific documentation on the Lake Shore Cryogenics instruments that are implemented. If you are interested in an instrument not included, please consider :doc:`adding the instrument </dev/adding_instruments/index>`.
Several Lakeshore instruments are channel based and make use of the :ref:`Channel Interface <channels>`. For temperature monitoring and controller instruments the
following common :class:`Channel Classes <pymeasure.instruments.Channel>` are utilized:

.. _LakeShoreChannels:

LakeShore Channel Classes
--------------------------

.. autoclass:: pymeasure.instruments.lakeshore.lakeshore_base.LakeShoreTemperatureChannel
:members:
:show-inheritance:

.. autoclass:: pymeasure.instruments.lakeshore.lakeshore_base.LakeShoreHeaterChannel
:members:
:show-inheritance:

.. toctree::
:maxdepth: 2

lakeshore224
lakeshore331
lakeshore421
lakeshore425
7 changes: 7 additions & 0 deletions docs/api/instruments/lakeshore/lakeshore224.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##################################
Lake Shore 224 Temperature Monitor
##################################

.. autoclass:: pymeasure.instruments.lakeshore.LakeShore224
:members:
:show-inheritance:
2 changes: 1 addition & 1 deletion pymeasure/instruments/lakeshore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from .lakeshore224 import LakeShore224
from .lakeshore331 import LakeShore331
from .lakeshore421 import LakeShore421
from .lakeshore425 import LakeShore425
62 changes: 62 additions & 0 deletions pymeasure/instruments/lakeshore/lakeshore224.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2023 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.
#

import logging
from pymeasure.instruments import Instrument
from pymeasure.instruments.lakeshore.lakeshore_base import LakeShoreTemperatureChannel

log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())


class LakeShore224(Instrument):
""" Represents the Lakeshore 224 Temperature monitor and provides a high-level interface
for interacting with the instrument. Note that the 224 provides 12 temperature input channels
(A, B, C1-5, D1-5). This driver makes use of the :ref:`LakeShoreChannels`
.. code-block:: python
monitor = LakeShore224('GPIB::1')
print(monitor.input_A.kelvin) # Print the temperature in kelvin on sensor A
monitor.input_A.wait_for_temperature() # Wait for the temperature on sensor A to stabilize.
"""

i_ch = Instrument.ChannelCreator(LakeShoreTemperatureChannel,
['0', 'A', 'B',
'C1', 'C2', 'C3', 'C4', 'C5',
'D1', 'D2', 'D3', 'D4', 'D5'],
prefix='input_')

def __init__(self, adapter, **kwargs):
name = 'Lakeshore Model 224 Temperature Controller' if 'name' not in kwargs.keys() \
else kwargs.pop('name')
read_termination = '\r\n' if 'read_termination' not in kwargs.keys() \
else kwargs.pop('read_termination')
super().__init__(
adapter,
name,
read_termination=read_termination,
**kwargs
)
94 changes: 18 additions & 76 deletions pymeasure/instruments/lakeshore/lakeshore331.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,99 +24,41 @@

import logging

from time import sleep, time

from pymeasure.instruments import Instrument
from pymeasure.instruments.validators import strict_discrete_set
from pymeasure.instruments.lakeshore.lakeshore_base import LakeShoreTemperatureChannel, \
LakeShoreHeaterChannel

log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())


class LakeShore331(Instrument):
""" Represents the Lake Shore 331 Temperature Controller and provides
a high-level interface for interacting with the instrument.
a high-level interface for interacting with the instrument. Note that the
331 provides two input channels (A and B) and two output channels (1 and 2).
This driver makes use of the :ref:`LakeShoreChannels`.
.. code-block:: python
controller = LakeShore331("GPIB::1")
print(controller.setpoint_1) # Print the current setpoint for loop 1
controller.setpoint_1 = 50 # Change the setpoint to 50 K
controller.heater_range = 'low' # Change the heater range to Low
controller.wait_for_temperature() # Wait for the temperature to stabilize
print(controller.temperature_A) # Print the temperature at sensor A
print(controller.output_1.setpoint) # Print the current setpoint for loop 1
controller.output_1.setpoint = 50 # Change the loop 1 setpoint to 50 K
controller.output_1.heater_range = 'low' # Change the heater range to low.
controller.input_A.wait_for_temperature() # Wait for the temperature to stabilize.
print(controller.input_A.temperature) # Print the temperature at sensor A.
"""

temperature_A = Instrument.measurement(
"KRDG? A",
""" Reads the temperature of the sensor A in Kelvin. """
)
temperature_B = Instrument.measurement(
"KRDG? B",
""" Reads the temperature of the sensor B in Kelvin. """
)
setpoint_1 = Instrument.control(
"SETP? 1", "SETP 1, %g",
""" A floating point property that controls the setpoint temperature
in Kelvin for Loop 1. """
)
setpoint_2 = Instrument.control(
"SETP? 2", "SETP 2, %g",
""" A floating point property that controls the setpoint temperature
in Kelvin for Loop 2. """
)
heater_range = Instrument.control(
"RANGE?", "RANGE %d",
""" A string property that controls the heater range, which
can take the values: off, low, medium, and high. These values
correlate to 0, 0.5, 5 and 50 W respectively. """,
validator=strict_discrete_set,
values={'off': 0, 'low': 1, 'medium': 2, 'high': 3},
map_values=True
)
i_ch = Instrument.ChannelCreator(LakeShoreTemperatureChannel, ('A', 'B'), prefix='input_')
o_ch = Instrument.ChannelCreator(LakeShoreHeaterChannel, (1, 2), prefix='output_')

def __init__(self, adapter, **kwargs):
name = 'Lakeshore Model 336 Temperature Controller' if 'name' not in kwargs.keys() \
else kwargs.pop('name')
read_termination = '\r\n' if 'read_termination' not in kwargs.keys() \
else kwargs.pop('read_termination')
super().__init__(
adapter,
"Lake Shore 331 Temperature Controller",
name,
read_termination=read_termination,
**kwargs
)

def disable_heater(self):
""" Turns the :attr:`~.heater_range` to :code:`off` to disable the heater. """
self.heater_range = 'off'

def wait_for_temperature(self, accuracy=0.1,
interval=0.1, sensor='A', setpoint=1, timeout=360,
should_stop=lambda: False):
""" Blocks the program, waiting for the temperature to reach the setpoint
within the accuracy (%), checking this each interval time in seconds.
:param accuracy: An acceptable percentage deviation between the
setpoint and temperature
:param interval: A time in seconds that controls the refresh rate
:param sensor: The desired sensor to read, either A or B
:param setpoint: The desired setpoint loop to read, either 1 or 2
:param timeout: A timeout in seconds after which an exception is raised
:param should_stop: A function that returns True if waiting should stop, by
default this always returns False
"""
temperature_name = 'temperature_%s' % sensor
setpoint_name = 'setpoint_%d' % setpoint
# Only get the setpoint once, assuming it does not change
setpoint_value = getattr(self, setpoint_name)

def percent_difference(temperature):
return abs(100 * (temperature - setpoint_value) / setpoint_value)
t = time()
while percent_difference(getattr(self, temperature_name)) > accuracy:
sleep(interval)
if (time() - t) > timeout:
raise Exception((
"Timeout occurred after waiting %g seconds for "
"the LakeShore 331 temperature to reach %g K."
) % (timeout, setpoint))
if should_stop():
return
114 changes: 114 additions & 0 deletions pymeasure/instruments/lakeshore/lakeshore_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2023 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.
#

import logging
import numpy as np
from time import sleep, time

from pymeasure.instruments import Instrument, Channel
from pymeasure.instruments.validators import strict_discrete_set

log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())


class LakeShoreTemperatureChannel(Channel):
""" Temperature input channel on a lakeshore temperature monitor. Reads the temperature in
kelvin, celcius, or sensor units. Also provides a method to block the program until a given
stable temperature is reached.
"""

kelvin = Instrument.measurement(
'KRDG? {ch}',
"""Read the temperature in kelvin from a channel."""
)
celcius = Instrument.measurement(
'CRDG? {ch}',
"""Read the temperature in celcius from a channel."""
)
sensor = Instrument.measurement(
'SRDG? {ch}',
"""Read the temperature in sensor units from a channel."""
)

def wait_for_temperature(self, target, unit='kelvin', accuracy=0.1,
interval=1, timeout=360,
should_stop=lambda: False):
""" Blocks the program, waiting for the temperature to reach the target
within the accuracy (%), checking this each interval time in seconds.
:param target: Target temperature in kelvin, celcius, or sensor units.
:param unit: 'kelvin', 'celcius', or 'sensor' specifying the unit
for queried temperature values.
:param accuracy: An acceptable percentage deviation between the
target and temperature.
:param interval: Interval time in seconds between queries.
:param timeout: A timeout in seconds after which an exception is raised
:param should_stop: A function that returns True if waiting should stop, by
default this always returns False
"""
abs_tolerance = target * (accuracy / 100)
target_reached = False
t = time()
while not target_reached:
reading = np.array([getattr(self, unit)])
target_reached = np.allclose(reading, target, atol=abs_tolerance)
sleep(interval)
if (time() - t) > timeout:
raise Exception((
"Timeout occurred after waiting %g seconds for "
"the LakeShore 331 temperature to reach %g %s."
) % (timeout, target, unit))
if should_stop():
return


class LakeShoreHeaterChannel(Channel):
""" Heater output channel on a lakeshore temperature controller. Provides properties to query
the output power in percent of the max, set the manual output power, heater range, and PID
temperature setpoint.
"""

output = Instrument.measurement(
'HTR? {ch}',
"""Query the heater output in percent of the max."""
)
mout = Instrument.control(
'MOUT? {ch}',
'MOUT {ch},%f',
"""Manual heater output in percent."""
)
range = Instrument.control(
'RANGE? {ch}',
'RANGE {ch},%i',
"""String property controlling heater range, which can take the
values: off, low, medium, and high.""",
validator=strict_discrete_set,
values={'off': 0, 'low': 1, 'medium': 2, 'high': 3},
map_values=True)
setpoint = Instrument.control(
'SETP? {ch}', 'SETP {ch},%f',
"""A floating point property that control the setpoint temperature
in the preferred units of the control loop sensor."""
)

0 comments on commit 55752c0

Please sign in to comment.