| 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 |
import logging |
| 26 |
|
| 27 |
from pymeasure.instruments import Instrument, Channel, SCPIMixin |
| 28 |
from pymeasure.instruments.validators import strict_discrete_set, strict_range |
| 29 |
|
| 30 |
from .buffer import KeithleyBuffer |
| 31 |
|
| 32 |
|
| 33 |
log = logging.getLogger(__name__) |
| 34 |
log.addHandler(logging.NullHandler()) |
| 35 |
|
| 36 |
|
| 37 |
class Keithley2182Channel(Channel): |
| 38 |
"""Implementation of a Keithley 2182 channel. |
| 39 |
|
| 40 |
Channel 1 is the fundamental measurement channel, while channel 2 provides |
| 41 |
sense measurements. Channel 2 inputs are referenced to Channel 1 LO. |
| 42 |
Possible configurations are |
| 43 |
|
| 44 |
Voltage (Channel 1) |
| 45 |
Temperature (Channel 1) |
| 46 |
Voltage (Channel 1) and Voltage (Channel 2) |
| 47 |
Voltage (Channel 1) and Temperature (Channel 2) |
| 48 |
""" |
| 49 |
|
| 50 |
def __init__(self, parent, id): |
| 51 |
"""Set max voltage depending on channel.""" |
| 52 |
if id == 1: |
| 53 |
self.voltage_range_values = (0, 120) |
| 54 |
self.voltage_offset_values = (-120, 120) |
| 55 |
else: |
| 56 |
self.voltage_range_values = (0, 12) |
| 57 |
self.voltage_offset_values = (-12, 12) |
| 58 |
super().__init__(parent, id) |
| 59 |
|
| 60 |
voltage_range = Channel.control( |
| 61 |
":SENS:VOLT:CHAN{ch}:RANG?", ":SENS:VOLT:CHAN{ch}:RANG %g", |
| 62 |
"""Control the positive full-scale measurement voltage range in Volts. |
| 63 |
The Keithley 2182 selects a measurement range based on the expected voltage. |
| 64 |
DCV1 has five ranges: 10 mV, 100 mV, 1 V, 10 V, and 100 V. |
| 65 |
DCV2 has three ranges: 100 mV, 1 V, and 10 V. |
| 66 |
Valid limits are from 0 to 120 V for Ch. 1, and 0 to 12 V for Ch. 2. |
| 67 |
Auto-range is automatically disabled when this property is set.""", |
| 68 |
validator=strict_range, |
| 69 |
values=(0, 120), |
| 70 |
dynamic=True, |
| 71 |
) |
| 72 |
|
| 73 |
voltage_range_auto_enabled = Channel.control( |
| 74 |
":SENS:VOLT:CHAN{ch}:RANG:AUTO?", ":SENS:VOLT:CHAN{ch}:RANG:AUTO %d", |
| 75 |
"""Control the auto voltage ranging option (bool).""", |
| 76 |
validator=strict_discrete_set, |
| 77 |
values={True: 1, False: 0}, |
| 78 |
map_values=True, |
| 79 |
) |
| 80 |
|
| 81 |
voltage_offset = Channel.control( |
| 82 |
":SENS:VOLT:CHAN{ch}:REF?", ":SENS:VOLT:CHAN{ch}:REF %g", |
| 83 |
"""Control the relative offset for measuring voltage. |
| 84 |
Displayed value = actual value - offset value. |
| 85 |
Valid ranges are -120 V to +120 V for Ch. 1, and -12 V to +12 V for Ch. 2.""", |
| 86 |
validator=strict_range, |
| 87 |
values=(-120, 120), |
| 88 |
dynamic=True, |
| 89 |
) |
| 90 |
|
| 91 |
temperature_offset = Channel.control( |
| 92 |
":SENS:TEMP:CHAN{ch}:REF?", ":SENS:TEMP:CHAN{ch}:REF %g", |
| 93 |
"""Control the relative offset for measuring temperature. |
| 94 |
Displayed value = actual value - offset value. |
| 95 |
Valid values are -273 C to 1800 C.""", |
| 96 |
validator=strict_range, |
| 97 |
values=(-273, 1800), |
| 98 |
) |
| 99 |
|
| 100 |
voltage_offset_enabled = Channel.control( |
| 101 |
":SENS:VOLT:CHAN{ch}:REF:STAT?", ":SENS:VOLT:CHAN{ch}:REF:STAT %s", |
| 102 |
"""Control whether voltage is measured as a relative or absolute value (bool). |
| 103 |
Enabled by default for Ch. 2 voltage, which is measured relative to Ch. 1 |
| 104 |
voltage.""", |
| 105 |
validator=strict_discrete_set, |
| 106 |
values={False: 0, True: 1}, |
| 107 |
map_values=True |
| 108 |
) |
| 109 |
|
| 110 |
temperature_offset_enabled = Channel.control( |
| 111 |
":SENS:TEMP:CHAN{ch}:REF:STAT?", ":SENS:TEMP:CHAN{ch}:REF:STAT %s", |
| 112 |
"""Control whether temperature is measured as a relative or absolute value (bool). |
| 113 |
Disabled by default.""", |
| 114 |
validator=strict_discrete_set, |
| 115 |
values={False: 0, True: 1}, |
| 116 |
map_values=True |
| 117 |
) |
| 118 |
|
| 119 |
def setup_voltage(self, auto_range=True, nplc=5): |
| 120 |
"""Set active channel and configure channel for voltage measurement. |
| 121 |
|
| 122 |
:param auto_range: Enables auto_range if True, else uses set voltage |
| 123 |
range |
| 124 |
:param nplc: Number of power line cycles (NPLC) from 0.01 to 50/60 |
| 125 |
""" |
| 126 |
self.write(":SENS:CHAN {ch};" |
| 127 |
":SENS:FUNC 'VOLT';" |
| 128 |
f":SENS:VOLT:NPLC {nplc};") |
| 129 |
if auto_range: |
| 130 |
self.write(":SENS:VOLT:RANG:AUTO 1") |
| 131 |
self.check_errors() |
| 132 |
|
| 133 |
def setup_temperature(self, nplc=5): |
| 134 |
"""Change active channel and configure channel for temperature measurement. |
| 135 |
|
| 136 |
:param nplc: Number of power line cycles (NPLC) from 0.01 to 50/60 |
| 137 |
""" |
| 138 |
self.write(":SENS:CHAN {ch};" |
| 139 |
":SENS:FUNC 'TEMP';" |
| 140 |
f":SENS:TEMP:NPLC {nplc}") |
| 141 |
self.check_errors() |
| 142 |
|
| 143 |
def acquire_temperature_reference(self): |
| 144 |
"""Acquire a temperature measurement and store it as the relative offset value. |
| 145 |
|
| 146 |
Only acquires reference if temperature offset is enabled. |
| 147 |
""" |
| 148 |
self.write(":SENS:TEMP:CHAN{ch}:REF:ACQ") |
| 149 |
|
| 150 |
def acquire_voltage_reference(self): |
| 151 |
"""Acquire a voltage measurement and store it as the relative offset value. |
| 152 |
|
| 153 |
Only acquires reference if voltage offset is enabled. |
| 154 |
""" |
| 155 |
self.write(":SENS:VOLT:CHAN{ch}:REF:ACQ") |
| 156 |
|
| 157 |
|
| 158 |
class Keithley2182(SCPIMixin, KeithleyBuffer, Instrument): |
| 159 |
"""Represents the Keithley 2182 Nanovoltmeter and provides a |
| 160 |
high-level interface for interacting with the instrument. |
| 161 |
|
| 162 |
.. code-block:: python |
| 163 |
|
| 164 |
keithley = Keithley2182("GPIB::1") |
| 165 |
|
| 166 |
keithley.reset() # Return instrument settings to default |
| 167 |
values |
| 168 |
keithley.thermocouple = 'S' # Sets thermocouple type to S |
| 169 |
keithley.active_channel = 1 # Sets channel 1 for active measurement |
| 170 |
keithley.channel_function = 'voltage' # Configures active channel for voltage |
| 171 |
measurement |
| 172 |
print(keithley.voltage) # Prints the voltage in volts |
| 173 |
|
| 174 |
keithley.ch_1.setup_voltage() # Set channel 1 active and prepare |
| 175 |
voltage measurement |
| 176 |
keithley.ch_2.setup_temperature() # Set channel 2 active and prepare |
| 177 |
temperature measurement |
| 178 |
|
| 179 |
""" |
| 180 |
|
| 181 |
def __init__(self, adapter, name="Keithley 2182 Nanovoltmeter", |
| 182 |
read_termination='\r', **kwargs): |
| 183 |
super().__init__(adapter, name, read_termination=read_termination, **kwargs) |
| 184 |
|
| 185 |
ch_1 = Instrument.ChannelCreator(Keithley2182Channel, 1) |
| 186 |
ch_2 = Instrument.ChannelCreator(Keithley2182Channel, 2) |
| 187 |
|
| 188 |
################# |
| 189 |
# Configuration # |
| 190 |
################# |
| 191 |
|
| 192 |
auto_zero_enabled = Instrument.control( |
| 193 |
":SYST:AZER:STAT?", ":SYST:AZER:STAT %d", |
| 194 |
"""Control the auto zero option (bool).""", |
| 195 |
validator=strict_discrete_set, |
| 196 |
values={True: 1, False: 0}, |
| 197 |
map_values=True, |
| 198 |
) |
| 199 |
|
| 200 |
line_frequency = Instrument.measurement( |
| 201 |
":SYST:LFR?", |
| 202 |
"""Get the line frequency in Hertz. Values are 50 or 60. |
| 203 |
Cannot be set on 2182.""", |
| 204 |
) |
| 205 |
|
| 206 |
display_enabled = Instrument.control( |
| 207 |
":DISP:ENAB?", ":DISP:ENAB %d", |
| 208 |
"""Control whether the front display of the voltmeter is enabled. |
| 209 |
Valid values are True and False.""", |
| 210 |
validator=strict_discrete_set, |
| 211 |
values={True: 1, False: 0}, |
| 212 |
map_values=True, |
| 213 |
) |
| 214 |
|
| 215 |
active_channel = Instrument.control( |
| 216 |
":SENS:CHAN?", ":SENS:CHAN %d", |
| 217 |
"""Control which channel is active for measurement. |
| 218 |
Valid values are 0 (internal temperature sensor), 1, and 2.""", |
| 219 |
validator=strict_discrete_set, |
| 220 |
values=(0, 1, 2), |
| 221 |
cast=int |
| 222 |
) |
| 223 |
|
| 224 |
channel_function = Instrument.control( |
| 225 |
":SENS:FUNC?", "SENS:FUNC %s", |
| 226 |
"""Control the measurement mode of the active channel. |
| 227 |
Valid options are `voltage` and `temperature`.""", |
| 228 |
validator=strict_discrete_set, |
| 229 |
values={'voltage': '"VOLT:DC"', 'temperature': '"TEMP"'}, |
| 230 |
map_values=True |
| 231 |
) |
| 232 |
|
| 233 |
############### |
| 234 |
# Voltage (V) # |
| 235 |
############### |
| 236 |
|
| 237 |
voltage = Instrument.measurement( |
| 238 |
":READ?", |
| 239 |
"""Measure the voltage in Volts, if active channel is configured for this |
| 240 |
reading.""" |
| 241 |
) |
| 242 |
|
| 243 |
voltage_nplc = Instrument.control( |
| 244 |
":SENS:VOLT:NPLC?", ":SENS:VOLT:NPLC %g", |
| 245 |
"""Control the number of power line cycles (NPLC) for voltage measurements, |
| 246 |
which sets the integration period and measurement speed. |
| 247 |
Valid values are from 0.01 to 50 or 60, depending on the line frequency. |
| 248 |
Default is 5.""", |
| 249 |
validator=strict_range, |
| 250 |
values=(0.01, 60), |
| 251 |
dynamic=True, |
| 252 |
) |
| 253 |
|
| 254 |
################### |
| 255 |
# Temperature (C) # |
| 256 |
################### |
| 257 |
|
| 258 |
temperature = Instrument.measurement( |
| 259 |
":READ?", |
| 260 |
"""Measure the temperature in Celsius, if active channel is configured for this |
| 261 |
reading.""" |
| 262 |
) |
| 263 |
|
| 264 |
thermocouple = Instrument.control( |
| 265 |
":SENS:TEMP:TC?", ":SENS:TEMP:TC %s", |
| 266 |
"""Control the thermocouple type for temperature measurements. |
| 267 |
Valid options are B, E, J, K, N, R, S, and T.""", |
| 268 |
validator=strict_discrete_set, |
| 269 |
values=('B', 'E', 'J', 'K', 'N', 'R', 'S', 'T') |
| 270 |
) |
| 271 |
|
| 272 |
temperature_nplc = Instrument.control( |
| 273 |
":SENS:TEMP:NPLC?", ":SENS:TEMP:NPLC %g", |
| 274 |
"""Control the number of power line cycles (NPLC) for temperature measurements, |
| 275 |
which sets the integration period and measurement speed. |
| 276 |
Valid values are from 0.01 to 50 or 60, depending on the line frequency. |
| 277 |
Default is 5.""", |
| 278 |
validator=strict_range, |
| 279 |
values=(0.01, 60), |
| 280 |
dynamic=True, |
| 281 |
) |
| 282 |
|
| 283 |
temperature_reference_junction = Instrument.control( |
| 284 |
":SENS:TEMP:RJUN:RSEL?", ":SENS:TEMP:RJUN:RSEL %s", |
| 285 |
"""Control whether the thermocouple reference junction is internal (INT) or |
| 286 |
simulated (SIM). Default is INT.""", |
| 287 |
validator=strict_discrete_set, |
| 288 |
values=('SIM', 'INT'), |
| 289 |
) |
| 290 |
|
| 291 |
temperature_simulated_reference = Instrument.control( |
| 292 |
":SENS:TEMP:RJUN:SIM?", ":SENS:TEMP:RJUN:SIM %g", |
| 293 |
"""Control the value of the simulated thermocouple reference junction in |
| 294 |
Celsius. Default is 23 C.""", |
| 295 |
validator=strict_range, |
| 296 |
values=(0, 60), |
| 297 |
) |
| 298 |
|
| 299 |
internal_temperature = Instrument.measurement( |
| 300 |
":SENS:TEMP:RTEM?", |
| 301 |
"""Measure the internal temperature in Celsius.""" |
| 302 |
) |
| 303 |
|
| 304 |
############## |
| 305 |
# Statistics # |
| 306 |
############## |
| 307 |
|
| 308 |
mean = Instrument.measurement( |
| 309 |
":CALC2:FORM MEAN;:CALC2:STAT ON;:CALC2:IMM?;", |
| 310 |
"""Get the calculated mean (average) from the buffer data.""" |
| 311 |
) |
| 312 |
|
| 313 |
maximum = Instrument.measurement( |
| 314 |
":CALC2:FORM MAX;:CALC2:STAT ON;:CALC2:IMM?;", |
| 315 |
"""Get the calculated maximum from the buffer data.""" |
| 316 |
) |
| 317 |
|
| 318 |
minimum = Instrument.measurement( |
| 319 |
":CALC2:FORM MIN;:CALC2:STAT ON;:CALC2:IMM?;", |
| 320 |
"""Get the calculated minimum from the buffer data.""" |
| 321 |
) |
| 322 |
|
| 323 |
standard_dev = Instrument.measurement( |
| 324 |
":CALC2:FORM SDEV;:CALC2:STAT ON;:CALC2:IMM?;", |
| 325 |
"""Get the calculated standard deviation from the buffer data.""" |
| 326 |
) |
| 327 |
|
| 328 |
########### |
| 329 |
# Trigger # |
| 330 |
########### |
| 331 |
|
| 332 |
trigger_count = Instrument.control( |
| 333 |
":TRIG:COUN?", ":TRIG:COUN %d", |
| 334 |
"""Control the trigger count which can take values from 1 to 9,999. |
| 335 |
Default is 1.""", |
| 336 |
validator=strict_range, |
| 337 |
values=(1, 9999), |
| 338 |
cast=int |
| 339 |
) |
| 340 |
|
| 341 |
trigger_delay = Instrument.control( |
| 342 |
":TRIG:DEL?", ":TRIG:DEL %g", |
| 343 |
"""Control the trigger delay in seconds, which can take values from 0 to |
| 344 |
999999.999 s. Default is 0.""", |
| 345 |
validator=strict_range, |
| 346 |
values=(0, 999999.999) |
| 347 |
) |
| 348 |
|
| 349 |
########### |
| 350 |
# Methods # |
| 351 |
########### |
| 352 |
|
| 353 |
def auto_line_frequency(self): |
| 354 |
"""Set appropriate limits for NPLC voltage and temperature readings.""" |
| 355 |
if self.line_frequency == 50: |
| 356 |
self.temperature_nplc_values = (0.01, 50) |
| 357 |
self.voltage_nplc_values = (0.01, 50) |
| 358 |
else: |
| 359 |
self.temperature_nplc_values = (0.01, 60) |
| 360 |
self.voltage_nplc_values = (0.01, 60) |
| 361 |
|
| 362 |
def reset(self): |
| 363 |
"""Reset the instrument and clear the queue.""" |
| 364 |
self.write("status:queue:clear;*RST;:stat:pres;:*CLS;") |
| 365 |
|
| 366 |
def trigger(self): |
| 367 |
"""Execute a bus trigger, which can be used when :meth:`~.trigger_on_bus` |
| 368 |
is configured. |
| 369 |
""" |
| 370 |
return self.write("*TRG") |
| 371 |
|
| 372 |
def trigger_immediately(self): |
| 373 |
"""Configure measurements to be taken with the internal trigger at the maximum |
| 374 |
sampling rate. |
| 375 |
""" |
| 376 |
self.write(":TRIG:SOUR IMM;") |
| 377 |
|
| 378 |
def trigger_on_bus(self): |
| 379 |
"""Configure the trigger to detect events based on the bus trigger, which can be |
| 380 |
activated by :meth:`~.trigger`. |
| 381 |
""" |
| 382 |
self.write(":TRIG:SOUR BUS") |
| 383 |
|
| 384 |
def sample_continuously(self): |
| 385 |
"""Configure the instrument to continuously read samples |
| 386 |
and turn off any buffer or output triggering. |
| 387 |
""" |
| 388 |
self.disable_buffer() |
| 389 |
self.trigger_immediately() |