| 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, SCPIUnknownMixin |
| 26 |
from pymeasure.instruments.validators import modular_range, truncated_discrete_set, truncated_range |
| 27 |
|
| 28 |
import logging |
| 29 |
log = logging.getLogger(__name__) |
| 30 |
log.addHandler(logging.NullHandler()) |
| 31 |
|
| 32 |
|
| 33 |
def check_read_not_empty(value): |
| 34 |
"""Called by some properties to check if the reply is not an empty string |
| 35 |
that would mean the properties is currently invalid (probably because the reference mode |
| 36 |
is on single or dual)""" |
| 37 |
if value == '': |
| 38 |
raise ValueError('Invalid response from measurement call, ' |
| 39 |
'probably because the reference mode is set on single or dual') |
| 40 |
else: |
| 41 |
return value |
| 42 |
|
| 43 |
|
| 44 |
class Ametek7270(SCPIUnknownMixin, Instrument): |
| 45 |
"""This is the class for the Ametek DSP 7270 lockin amplifier |
| 46 |
|
| 47 |
In this instrument, some measurements are defined only for specific modes, |
| 48 |
called Reference modes, see :meth:`set_reference_mode` and will raise errors |
| 49 |
if called incorrectly |
| 50 |
""" |
| 51 |
|
| 52 |
SENSITIVITIES = [ |
| 53 |
0.0, 2.0e-9, 5.0e-9, 10.0e-9, 20.0e-9, 50.0e-9, 100.0e-9, |
| 54 |
200.0e-9, 500.0e-9, 1.0e-6, 2.0e-6, 5.0e-6, 10.0e-6, |
| 55 |
20.0e-6, 50.0e-6, 100.0e-6, 200.0e-6, 500.0e-6, 1.0e-3, |
| 56 |
2.0e-3, 5.0e-3, 10.0e-3, 20.0e-3, 50.0e-3, 100.0e-3, |
| 57 |
200.0e-3, 500.0e-3, 1.0 |
| 58 |
] |
| 59 |
|
| 60 |
SENSITIVITIES_IMODE = {0: SENSITIVITIES, |
| 61 |
1: [sen * 1e-6 for sen in SENSITIVITIES], |
| 62 |
2: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2e-15, 5e-15, 10e-15, |
| 63 |
20e-15, 50e-15, 100e-15, 200e-15, 500e-15, 1e-12, 2e-12]} |
| 64 |
|
| 65 |
TIME_CONSTANTS = [ |
| 66 |
10.0e-6, 20.0e-6, 50.0e-6, 100.0e-6, 200.0e-6, 500.0e-6, |
| 67 |
1.0e-3, 2.0e-3, 5.0e-3, 10.0e-3, 20.0e-3, 50.0e-3, 100.0e-3, |
| 68 |
200.0e-3, 500.0e-3, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0, |
| 69 |
100.0, 200.0, 500.0, 1.0e3, 2.0e3, 5.0e3, 10.0e3, |
| 70 |
20.0e3, 50.0e3, 100.0e3 |
| 71 |
] |
| 72 |
|
| 73 |
sensitivity = Instrument.control( # NOTE: only for IMODE = 1. |
| 74 |
"SEN", "SEN %d", |
| 75 |
""" A floating point property that controls the sensitivity |
| 76 |
range in Volts, which can take discrete values from 2 nV to |
| 77 |
1 V. This property can be set. """, |
| 78 |
validator=truncated_discrete_set, |
| 79 |
values=SENSITIVITIES, |
| 80 |
map_values=True, |
| 81 |
check_set_errors=True, |
| 82 |
dynamic=True, |
| 83 |
) |
| 84 |
|
| 85 |
slope = Instrument.control( |
| 86 |
"SLOPE", "SLOPE %d", |
| 87 |
""" A integer property that controls the filter slope in |
| 88 |
dB/octave, which can take the values 6, 12, 18, or 24 dB/octave. |
| 89 |
This property can be set. """, |
| 90 |
validator=truncated_discrete_set, |
| 91 |
values=[6, 12, 18, 24], |
| 92 |
map_values=True, |
| 93 |
check_set_errors=True, |
| 94 |
) |
| 95 |
|
| 96 |
time_constant = Instrument.control( # NOTE: only for NOISEMODE = 0 |
| 97 |
"TC", "TC %d", |
| 98 |
""" A floating point property that controls the time constant |
| 99 |
in seconds, which takes values from 10 microseconds to 100,000 |
| 100 |
seconds. This property can be set. """, |
| 101 |
validator=truncated_discrete_set, |
| 102 |
values=TIME_CONSTANTS, |
| 103 |
map_values=True, |
| 104 |
check_set_errors=True, |
| 105 |
) |
| 106 |
|
| 107 |
x = Instrument.measurement("X.", |
| 108 |
""" Reads the X value in Volts """, |
| 109 |
get_process=check_read_not_empty, |
| 110 |
) |
| 111 |
y = Instrument.measurement("Y.", |
| 112 |
""" Reads the Y value in Volts """, |
| 113 |
get_process=check_read_not_empty, |
| 114 |
) |
| 115 |
x1 = Instrument.measurement("X1.", |
| 116 |
""" Reads the first harmonic X value in Volts """, |
| 117 |
get_process=check_read_not_empty, |
| 118 |
) |
| 119 |
y1 = Instrument.measurement("Y1.", |
| 120 |
""" Reads the first harmonic Y value in Volts """, |
| 121 |
get_process=check_read_not_empty, |
| 122 |
) |
| 123 |
x2 = Instrument.measurement("X2.", |
| 124 |
""" Reads the second harmonic X value in Volts """, |
| 125 |
get_process=check_read_not_empty, |
| 126 |
) |
| 127 |
y2 = Instrument.measurement("Y2.", |
| 128 |
""" Reads the second harmonic Y value in Volts """, |
| 129 |
get_process=check_read_not_empty, |
| 130 |
) |
| 131 |
xy = Instrument.measurement("XY.", |
| 132 |
""" Reads both the X and Y values in Volts """, |
| 133 |
get_process=check_read_not_empty, |
| 134 |
) |
| 135 |
mag = Instrument.measurement("MAG.", |
| 136 |
""" Reads the magnitude in Volts """, |
| 137 |
get_process=check_read_not_empty, |
| 138 |
) |
| 139 |
|
| 140 |
theta = Instrument.measurement("PHA.", |
| 141 |
""" Reads the signal phase in degrees """, |
| 142 |
get_process=check_read_not_empty, |
| 143 |
) |
| 144 |
|
| 145 |
harmonic = Instrument.control( |
| 146 |
"REFN", "REFN %d", |
| 147 |
""" An integer property that represents the reference |
| 148 |
harmonic mode control, taking values from 1 to 127. |
| 149 |
This property can be set. """, |
| 150 |
validator=truncated_discrete_set, |
| 151 |
values=list(range(1, 128)), |
| 152 |
check_set_errors=True, |
| 153 |
) |
| 154 |
phase = Instrument.control( |
| 155 |
"REFP.", "REFP. %g", |
| 156 |
""" A floating point property that represents the reference |
| 157 |
harmonic phase in degrees. This property can be set. """, |
| 158 |
validator=modular_range, |
| 159 |
values=[0, 360], |
| 160 |
check_set_errors=True, |
| 161 |
) |
| 162 |
voltage = Instrument.control( |
| 163 |
"OA.", "OA. %g", |
| 164 |
""" A floating point property that represents the voltage |
| 165 |
in Volts. This property can be set. """, |
| 166 |
validator=truncated_range, |
| 167 |
values=[0, 5], |
| 168 |
check_set_errors=True, |
| 169 |
) |
| 170 |
frequency = Instrument.control( |
| 171 |
"OF.", "OF. %g", |
| 172 |
""" A floating point property that represents the lock-in |
| 173 |
frequency in Hz. This property can be set. """, |
| 174 |
validator=truncated_range, |
| 175 |
values=[0, 2.5e5], |
| 176 |
check_set_errors=True, |
| 177 |
) |
| 178 |
dac1 = Instrument.control( |
| 179 |
"DAC. 1", "DAC. 1 %g", |
| 180 |
""" A floating point property that represents the output |
| 181 |
value on DAC1 in Volts. This property can be set. """, |
| 182 |
validator=truncated_range, |
| 183 |
values=[-10, 10], |
| 184 |
check_set_errors=True, |
| 185 |
) |
| 186 |
dac2 = Instrument.control( |
| 187 |
"DAC. 2", "DAC. 2 %g", |
| 188 |
""" A floating point property that represents the output |
| 189 |
value on DAC2 in Volts. This property can be set. """, |
| 190 |
validator=truncated_range, |
| 191 |
values=[-10, 10], |
| 192 |
check_set_errors=True, |
| 193 |
) |
| 194 |
dac3 = Instrument.control( |
| 195 |
"DAC. 3", "DAC. 3 %g", |
| 196 |
""" A floating point property that represents the output |
| 197 |
value on DAC3 in Volts. This property can be set. """, |
| 198 |
validator=truncated_range, |
| 199 |
values=[-10, 10], |
| 200 |
check_set_errors=True, |
| 201 |
) |
| 202 |
dac4 = Instrument.control( |
| 203 |
"DAC. 4", "DAC. 4 %g", |
| 204 |
""" A floating point property that represents the output |
| 205 |
value on DAC4 in Volts. This property can be set. """, |
| 206 |
validator=truncated_range, |
| 207 |
values=[-10, 10], |
| 208 |
check_set_errors=True, |
| 209 |
) |
| 210 |
adc1 = Instrument.measurement("ADC. 1", |
| 211 |
""" Reads the input value of ADC1 in Volts """, |
| 212 |
get_process=check_read_not_empty, |
| 213 |
) |
| 214 |
adc2 = Instrument.measurement("ADC. 2", |
| 215 |
""" Reads the input value of ADC2 in Volts """, |
| 216 |
get_process=check_read_not_empty, |
| 217 |
) |
| 218 |
adc3 = Instrument.measurement("ADC. 3", |
| 219 |
""" Reads the input value of ADC3 in Volts """, |
| 220 |
get_process=check_read_not_empty, |
| 221 |
) |
| 222 |
adc4 = Instrument.measurement("ADC. 4", |
| 223 |
""" Reads the input value of ADC4 in Volts """, |
| 224 |
get_process=check_read_not_empty, |
| 225 |
) |
| 226 |
|
| 227 |
def __init__(self, adapter, name="Ametek DSP 7270", |
| 228 |
read_termination='\x00', |
| 229 |
write_termination='\x00', |
| 230 |
**kwargs): |
| 231 |
|
| 232 |
super().__init__( |
| 233 |
adapter, |
| 234 |
name, |
| 235 |
read_termination=read_termination, |
| 236 |
write_termination=write_termination, |
| 237 |
**kwargs) |
| 238 |
|
| 239 |
def check_set_errors(self): |
| 240 |
"""mandatory to be used for property setter |
| 241 |
|
| 242 |
The Ametek protocol expect the default null character to be read to check the property |
| 243 |
has been correctly set. With default termination character set as Null character, |
| 244 |
this turns out as an empty string to be read. |
| 245 |
""" |
| 246 |
if self.read() == '': |
| 247 |
return [] |
| 248 |
else: |
| 249 |
return ['Incorrect return from previously set property'] |
| 250 |
|
| 251 |
def ask(self, command, query_delay=None): |
| 252 |
"""Send a command and read the response, stripping white spaces. |
| 253 |
|
| 254 |
Usually the properties use the |
| 255 |
:meth:`~pymeasure.instruments.common_base.CommonBase.values` |
| 256 |
method that adds a strip call, however several methods use directly the result from ask to |
| 257 |
be cast into some other types. It should therefore also add the strip here, as all responses |
| 258 |
end with a newline character. |
| 259 |
""" |
| 260 |
return super().ask(command, query_delay).strip() |
| 261 |
|
| 262 |
def set_reference_mode(self, mode: int = 0): |
| 263 |
"""Set the instrument in Single, Dual or harmonic mode. |
| 264 |
|
| 265 |
:param mode: the integer specifying the mode: 0 for Single, 1 for Dual harmonic, and 2 for |
| 266 |
Dual reference. |
| 267 |
|
| 268 |
""" |
| 269 |
if mode not in [0, 1, 2]: |
| 270 |
raise ValueError('Invalid reference mode') |
| 271 |
self.ask(f'REFMODE {mode}') |
| 272 |
|
| 273 |
def set_voltage_mode(self): |
| 274 |
""" Sets instrument to voltage control mode """ |
| 275 |
self.ask("IMODE 0") |
| 276 |
self.sensitivity_values = self.SENSITIVITIES_IMODE[0] |
| 277 |
|
| 278 |
def set_differential_mode(self, lineFiltering=True): |
| 279 |
""" Sets instrument to differential mode -- assuming it is in voltage mode """ |
| 280 |
self.ask("VMODE 3") |
| 281 |
self.ask("LF %d 0" % 3 if lineFiltering else 0) |
| 282 |
|
| 283 |
def set_current_mode(self, low_noise=False): |
| 284 |
""" Sets instrument to current control mode with either low noise or high bandwidth""" |
| 285 |
if low_noise: |
| 286 |
self.ask("IMODE 2") |
| 287 |
self.sensitivity_values = self.SENSITIVITIES_IMODE[2] |
| 288 |
else: |
| 289 |
self.ask("IMODE 1") |
| 290 |
self.sensitivity_values = self.SENSITIVITIES_IMODE[1] |
| 291 |
|
| 292 |
def set_channel_A_mode(self): |
| 293 |
""" Sets instrument to channel A mode -- assuming it is in voltage mode """ |
| 294 |
self.ask("VMODE 1") |
| 295 |
|
| 296 |
@property |
| 297 |
def id(self): |
| 298 |
"""Get the instrument ID and firmware version""" |
| 299 |
return f"{self.ask('ID')}/{self.ask('VER')}" |
| 300 |
|
| 301 |
@property |
| 302 |
def auto_gain(self): |
| 303 |
return int(self.ask("AUTOMATIC")) == 1 |
| 304 |
|
| 305 |
@auto_gain.setter |
| 306 |
def auto_gain(self, setval): |
| 307 |
if setval: |
| 308 |
self.ask("AUTOMATIC 1") |
| 309 |
else: |
| 310 |
self.ask("AUTOMATIC 0") |
| 311 |
|
| 312 |
def shutdown(self): |
| 313 |
""" Ensures the instrument in a safe state """ |
| 314 |
log.info("Shutting down %s" % self.name) |
| 315 |
self.voltage = 0. |
| 316 |
super().shutdown() |