Source code for instruments.thorlabs.sc10

#!/usr/bin/python
"""
Provides the support for the Thorlabs SC10 optical beam shutter controller.

Class originally contributed by Catherine Holloway.
"""

# IMPORTS #####################################################################

from enum import IntEnum

from instruments.abstract_instruments import Instrument
from instruments.thorlabs.thorlabs_utils import check_cmd
from instruments.units import ureg as u
from instruments.util_fns import (
    bool_property,
    enum_property,
    int_property,
    unitful_property,
)

# CLASSES #####################################################################


[docs] class SC10(Instrument): """ The SC10 is a shutter controller, to be used with the Thorlabs SH05 and SH1. The user manual can be found here: http://www.thorlabs.com/thorcat/8600/SC10-Manual.pdf """ def __init__(self, filelike): super().__init__(filelike) self.terminator = "\r" self.prompt = "> " def _ack_expected(self, msg=""): return msg # ENUMS #
[docs] class Mode(IntEnum): """ Enum containing valid output modes of the SC10 """ manual = 1 auto = 2 single = 3 repeat = 4 external = 5
# PROPERTIES # @property def name(self): """ Gets the name and version number of the device. :return: Name and verison number of the device :rtype: `str` """ return self.query("id?") @property def enable(self): """ Gets/sets the shutter enable status, False for disabled, True if enabled If output enable is on (`True`), there is a voltage on the output. :return: Status of the switch. :rtype: `bool` :raises TypeError: Unexpected type given when trying to enable. """ return bool(int(self.query("ens?"))) @enable.setter def enable(self, value): if not isinstance(value, bool): raise TypeError(f"Expected bool, got type {type(value)} instead.") curr_status = self.enable if curr_status is not value: self.sendcmd("ens") repeat = int_property( "rep", valid_set=range(1, 100), set_fmt="{}={}", doc=""" Gets/sets the repeat count for repeat mode. Valid range is [1,99] inclusive. :type: `int` """, ) mode = enum_property( "mode", Mode, input_decoration=int, set_fmt="{}={}", doc=""" Gets/sets the output mode of the SC10 :rtype: `SC10.Mode` """, ) trigger = int_property( "trig", valid_set=range(0, 2), set_fmt="{}={}", doc=""" Gets/sets the trigger source. 0 for internal trigger, 1 for external trigger :type: `int` """, ) out_trigger = int_property( "xto", valid_set=range(0, 2), set_fmt="{}={}", doc=""" Gets/sets the out trigger source. 0 trigger out follows shutter output, 1 trigger out follows controller output :type: `int` """, ) open_time = unitful_property( "open", u.ms, format_code="{:.0f}", set_fmt="{}={}", valid_range=(0, 999999), doc=""" Gets/sets the amount of time that the shutter is open, in ms :units: As specified (if a `~pint.Quantity`) or assumed to be of units milliseconds. :type: `~pint.Quantity` """, ) shut_time = unitful_property( "shut", u.ms, format_code="{:.0f}", set_fmt="{}={}", valid_range=(0, 999999), doc=""" Gets/sets the amount of time that the shutter is closed, in ms :units: As specified (if a `~pint.Quantity`) or assumed to be of units milliseconds. :type: `~pint.Quantity` """, ) @property def baud_rate(self): """ Gets/sets the instrument baud rate. Valid baud rates are 9600 and 115200. :type: `int` """ response = self.query("baud?") return 115200 if int(response) else 9600 @baud_rate.setter def baud_rate(self, newval): if newval != 9600 and newval != 115200: raise ValueError("Invalid baud rate mode") else: self.sendcmd(f"baud={0 if newval == 9600 else 1}") closed = bool_property( "closed", inst_true="1", inst_false="0", readonly=True, doc=""" Gets the shutter closed status. `True` represents the shutter is closed, and `False` for the shutter is open. :rtype: `bool` """, ) interlock = bool_property( "interlock", inst_true="1", inst_false="0", readonly=True, doc=""" Gets the interlock tripped status. Returns `True` if the interlock is tripped, and `False` otherwise. :rtype: `bool` """, ) # Methods #
[docs] def default(self): """ Restores instrument to factory settings. Returns 1 if successful, zero otherwise. :rtype: `int` """ response = self.query("default") return check_cmd(response)
[docs] def save(self): """ Stores the parameters in static memory Returns 1 if successful, zero otherwise. :rtype: `int` """ response = self.query("savp") return check_cmd(response)
[docs] def save_mode(self): """ Stores output trigger mode and baud rate settings in memory. Returns 1 if successful, zero otherwise. :rtype: `int` """ response = self.query("save") return check_cmd(response)
[docs] def restore(self): """ Loads the settings from memory. Returns 1 if successful, zero otherwise. :rtype: `int` """ response = self.query("resp") return check_cmd(response)