1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 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, SCPIUnknownMixin
from pymeasure.instruments.channel import Channel
from pymeasure.instruments.validators import (strict_discrete_range,
strict_discrete_set,
truncated_range
)
from enum import IntFlag
log = logging.getLogger(__name__) # https://docs.python.org/3/howto/logging.html#library-config
log.addHandler(logging.NullHandler())
class SystemStatusCode(IntFlag):
"""System status enums based on ``IntFlag``
Used in conjunction with :attr:`~.system_status_code`.
====== ======
Value Enum
====== ======
256 WAVEFORM_DISPLAY
64 TIMER_ENABLED
32 FOUR_WIRE
16 OUTPUT_ENABLED
1 CONSTANT_CURRENT
0 CONSTANT_VOLTAGE
====== ======
"""
WAVEFORM_DISPLAY = 256 # bit 8 -- waveform display enabled
TIMER_ENABLED = 64 # bit 6 -- timer enabled
FOUR_WIRE = 32 # bit 5 -- four-wire mode enabled
OUTPUT_ENABLED = 16 # bit 4 -- output enabled
CONSTANT_CURRENT = 1 # bit 0 -- constant current mode
CONSTANT_VOLTAGE = 0 # bit 0 -- constant voltage mode
class SPDChannel(Channel):
""" The channel class for Siglent SPDxxxxX instruments.
"""
def __init__(self, parent, id,
voltage_range: list = [0, 16],
current_range: list = [0, 8]):
super().__init__(parent, id)
self.voltage_range = voltage_range
self.current_range = current_range
voltage = Instrument.measurement(
"MEAS:VOLT? CH{ch}",
"""Measure the channel output voltage.
:type: float
"""
)
current = Instrument.measurement(
"MEAS:CURR? CH{ch}",
"""Measure the channel output current.
:type: float
"""
)
power = Instrument.measurement(
"MEAS:POWE? CH{ch}",
"""Measure the channel output power.
:type: float
"""
)
current_limit = Instrument.control(
"CH{ch}:CURR?", "CH{ch}:CURR %g",
"""Control the output current configuration of the channel.
:type : float
""",
validator=truncated_range,
values=[0, 8],
dynamic=True
)
voltage_setpoint = Instrument.control(
"CH{ch}:VOLT?", "CH{ch}:VOLT %g",
"""Control the output voltage configuration of the channel.
:type : float
""",
validator=truncated_range,
values=[0, 16],
dynamic=True
)
def enable_output(self, enable: bool = True):
"""Enable the channel output.
:type: bool
``True``: enables the output
``False``: disables it
"""
self.parent.selected_channel = self.id
self.write('OUTP CH{ch},' + ("ON" if enable else "OFF"))
def enable_timer(self, enable: bool = True):
"""Enable the channel timer.
:type: bool
``True``: enables the timer
``False``: disables it
"""
self.write('TIME CH{ch},' + ("ON" if enable else "OFF"))
def configure_timer(self, step, voltage, current, duration):
"""Configure the timer step.
:param step:
int: index of the step to save the configuration
:param voltage:
float: voltage setpoint of the step
:param current:
float: current limit of the step
:param duration:
int: duration of the step in seconds
"""
step = strict_discrete_range(step, [1, 5], 1)
voltage = truncated_range(voltage, self.voltage_range)
current = truncated_range(current, self.current_range)
duration = truncated_range(duration, [0, 10000])
self.write(f'TIME:SET CH{{ch}},{step:d},{voltage:1.3f},{current:1.3f},{duration:d}')
class SPDBase(SCPIUnknownMixin, Instrument):
""" The base class for Siglent SPDxxxxX instruments.
Uses :class:`SPDChannel` for measurement channels.
"""
def __init__(self, adapter, name="Siglent SPDxxxxX instrument Base Class", **kwargs):
super().__init__(
adapter,
name,
usb=dict(write_termination='\n',
read_termination='\n'),
tcpip=dict(write_termination='\n',
read_termination='\n'),
**kwargs
)
error = Instrument.measurement(
"SYST:ERR?",
"""Get the error code and information of the instrument.
:type: string
"""
)
fw_version = Instrument.measurement(
"SYST:VERS?",
"""Get the software version of the instrument.
:type: string
"""
)
system_status_code = Instrument.measurement(
"SYST:STAT?",
"""Get the system status register.
:type: :class:`.SystemStatusCode`
""",
get_process=lambda v: SystemStatusCode(int(v, base=16)),
)
selected_channel = Instrument.control(
"INST?", "INST %s",
"""Control the selected channel of the instrument.
:type : int
""",
validator=strict_discrete_set,
values={1: "CH1"}, # This dynamic property should be updated for multi-channel instruments
map_values=True,
dynamic=True
)
def save_config(self, index):
"""Save the current config to memory.
:param index:
int: index of the location to save the configuration
"""
index = strict_discrete_range(index, [1, 5], 1)
self.write(f"*SAV {index:d}")
def recall_config(self, index):
"""Recall a config from memory.
:param index:
int: index of the location from which to recall the configuration
"""
index = strict_discrete_range(index, [1, 5], 1)
self.write(f"*RCL {index:d}")
def enable_local_interface(self, enable: bool = True):
"""Configure the availability of the local interface.
:type: bool
``True``: enables the local interface
``False``: disables it.
"""
self.write("*UNLOCK" if enable else "*LOCK")
def shutdown(self):
""" Ensure that the voltage is turned to zero
and disable the output. """
for ch in self.channels.values():
ch.voltage_setpoint = 0
ch.enable_output(False)
super().shutdown()
class SPDSingleChannelBase(SPDBase):
def enable_4W_mode(self, enable: bool = True):
"""Enable 4-wire mode.
:type: bool
``True``: enables 4-wire mode
``False``: disables it.
"""
self.write(f'MODE:SET {"4W" if enable else "2W"}')
|