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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
#
# 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, Channel, SCPIMixin
from pymeasure.instruments.validators import strict_discrete_set, strict_range
from .buffer import KeithleyBuffer
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
class Keithley2182Channel(Channel):
"""Implementation of a Keithley 2182 channel.
Channel 1 is the fundamental measurement channel, while channel 2 provides
sense measurements. Channel 2 inputs are referenced to Channel 1 LO.
Possible configurations are
Voltage (Channel 1)
Temperature (Channel 1)
Voltage (Channel 1) and Voltage (Channel 2)
Voltage (Channel 1) and Temperature (Channel 2)
"""
def __init__(self, parent, id):
"""Set max voltage depending on channel."""
if id == 1:
self.voltage_range_values = (0, 120)
self.voltage_offset_values = (-120, 120)
else:
self.voltage_range_values = (0, 12)
self.voltage_offset_values = (-12, 12)
super().__init__(parent, id)
voltage_range = Channel.control(
":SENS:VOLT:CHAN{ch}:RANG?", ":SENS:VOLT:CHAN{ch}:RANG %g",
"""Control the positive full-scale measurement voltage range in Volts.
The Keithley 2182 selects a measurement range based on the expected voltage.
DCV1 has five ranges: 10 mV, 100 mV, 1 V, 10 V, and 100 V.
DCV2 has three ranges: 100 mV, 1 V, and 10 V.
Valid limits are from 0 to 120 V for Ch. 1, and 0 to 12 V for Ch. 2.
Auto-range is automatically disabled when this property is set.""",
validator=strict_range,
values=(0, 120),
dynamic=True,
)
voltage_range_auto_enabled = Channel.control(
":SENS:VOLT:CHAN{ch}:RANG:AUTO?", ":SENS:VOLT:CHAN{ch}:RANG:AUTO %d",
"""Control the auto voltage ranging option (bool).""",
validator=strict_discrete_set,
values={True: 1, False: 0},
map_values=True,
)
voltage_offset = Channel.control(
":SENS:VOLT:CHAN{ch}:REF?", ":SENS:VOLT:CHAN{ch}:REF %g",
"""Control the relative offset for measuring voltage.
Displayed value = actual value - offset value.
Valid ranges are -120 V to +120 V for Ch. 1, and -12 V to +12 V for Ch. 2.""",
validator=strict_range,
values=(-120, 120),
dynamic=True,
)
temperature_offset = Channel.control(
":SENS:TEMP:CHAN{ch}:REF?", ":SENS:TEMP:CHAN{ch}:REF %g",
"""Control the relative offset for measuring temperature.
Displayed value = actual value - offset value.
Valid values are -273 C to 1800 C.""",
validator=strict_range,
values=(-273, 1800),
)
voltage_offset_enabled = Channel.control(
":SENS:VOLT:CHAN{ch}:REF:STAT?", ":SENS:VOLT:CHAN{ch}:REF:STAT %s",
"""Control whether voltage is measured as a relative or absolute value (bool).
Enabled by default for Ch. 2 voltage, which is measured relative to Ch. 1
voltage.""",
validator=strict_discrete_set,
values={False: 0, True: 1},
map_values=True
)
temperature_offset_enabled = Channel.control(
":SENS:TEMP:CHAN{ch}:REF:STAT?", ":SENS:TEMP:CHAN{ch}:REF:STAT %s",
"""Control whether temperature is measured as a relative or absolute value (bool).
Disabled by default.""",
validator=strict_discrete_set,
values={False: 0, True: 1},
map_values=True
)
def setup_voltage(self, auto_range=True, nplc=5):
"""Set active channel and configure channel for voltage measurement.
:param auto_range: Enables auto_range if True, else uses set voltage
range
:param nplc: Number of power line cycles (NPLC) from 0.01 to 50/60
"""
self.write(":SENS:CHAN {ch};"
":SENS:FUNC 'VOLT';"
f":SENS:VOLT:NPLC {nplc};")
if auto_range:
self.write(":SENS:VOLT:RANG:AUTO 1")
self.check_errors()
def setup_temperature(self, nplc=5):
"""Change active channel and configure channel for temperature measurement.
:param nplc: Number of power line cycles (NPLC) from 0.01 to 50/60
"""
self.write(":SENS:CHAN {ch};"
":SENS:FUNC 'TEMP';"
f":SENS:TEMP:NPLC {nplc}")
self.check_errors()
def acquire_temperature_reference(self):
"""Acquire a temperature measurement and store it as the relative offset value.
Only acquires reference if temperature offset is enabled.
"""
self.write(":SENS:TEMP:CHAN{ch}:REF:ACQ")
def acquire_voltage_reference(self):
"""Acquire a voltage measurement and store it as the relative offset value.
Only acquires reference if voltage offset is enabled.
"""
self.write(":SENS:VOLT:CHAN{ch}:REF:ACQ")
class Keithley2182(SCPIMixin, KeithleyBuffer, Instrument):
"""Represents the Keithley 2182 Nanovoltmeter and provides a
high-level interface for interacting with the instrument.
.. code-block:: python
keithley = Keithley2182("GPIB::1")
keithley.reset() # Return instrument settings to default
values
keithley.thermocouple = 'S' # Sets thermocouple type to S
keithley.active_channel = 1 # Sets channel 1 for active measurement
keithley.channel_function = 'voltage' # Configures active channel for voltage
measurement
print(keithley.voltage) # Prints the voltage in volts
keithley.ch_1.setup_voltage() # Set channel 1 active and prepare
voltage measurement
keithley.ch_2.setup_temperature() # Set channel 2 active and prepare
temperature measurement
"""
def __init__(self, adapter, name="Keithley 2182 Nanovoltmeter",
read_termination='\r', **kwargs):
super().__init__(adapter, name, read_termination=read_termination, **kwargs)
ch_1 = Instrument.ChannelCreator(Keithley2182Channel, 1)
ch_2 = Instrument.ChannelCreator(Keithley2182Channel, 2)
#################
# Configuration #
#################
auto_zero_enabled = Instrument.control(
":SYST:AZER:STAT?", ":SYST:AZER:STAT %d",
"""Control the auto zero option (bool).""",
validator=strict_discrete_set,
values={True: 1, False: 0},
map_values=True,
)
line_frequency = Instrument.measurement(
":SYST:LFR?",
"""Get the line frequency in Hertz. Values are 50 or 60.
Cannot be set on 2182.""",
)
display_enabled = Instrument.control(
":DISP:ENAB?", ":DISP:ENAB %d",
"""Control whether the front display of the voltmeter is enabled.
Valid values are True and False.""",
validator=strict_discrete_set,
values={True: 1, False: 0},
map_values=True,
)
active_channel = Instrument.control(
":SENS:CHAN?", ":SENS:CHAN %d",
"""Control which channel is active for measurement.
Valid values are 0 (internal temperature sensor), 1, and 2.""",
validator=strict_discrete_set,
values=(0, 1, 2),
cast=int
)
channel_function = Instrument.control(
":SENS:FUNC?", "SENS:FUNC %s",
"""Control the measurement mode of the active channel.
Valid options are `voltage` and `temperature`.""",
validator=strict_discrete_set,
values={'voltage': '"VOLT:DC"', 'temperature': '"TEMP"'},
map_values=True
)
###############
# Voltage (V) #
###############
voltage = Instrument.measurement(
":READ?",
"""Measure the voltage in Volts, if active channel is configured for this
reading."""
)
voltage_nplc = Instrument.control(
":SENS:VOLT:NPLC?", ":SENS:VOLT:NPLC %g",
"""Control the number of power line cycles (NPLC) for voltage measurements,
which sets the integration period and measurement speed.
Valid values are from 0.01 to 50 or 60, depending on the line frequency.
Default is 5.""",
validator=strict_range,
values=(0.01, 60),
dynamic=True,
)
###################
# Temperature (C) #
###################
temperature = Instrument.measurement(
":READ?",
"""Measure the temperature in Celsius, if active channel is configured for this
reading."""
)
thermocouple = Instrument.control(
":SENS:TEMP:TC?", ":SENS:TEMP:TC %s",
"""Control the thermocouple type for temperature measurements.
Valid options are B, E, J, K, N, R, S, and T.""",
validator=strict_discrete_set,
values=('B', 'E', 'J', 'K', 'N', 'R', 'S', 'T')
)
temperature_nplc = Instrument.control(
":SENS:TEMP:NPLC?", ":SENS:TEMP:NPLC %g",
"""Control the number of power line cycles (NPLC) for temperature measurements,
which sets the integration period and measurement speed.
Valid values are from 0.01 to 50 or 60, depending on the line frequency.
Default is 5.""",
validator=strict_range,
values=(0.01, 60),
dynamic=True,
)
temperature_reference_junction = Instrument.control(
":SENS:TEMP:RJUN:RSEL?", ":SENS:TEMP:RJUN:RSEL %s",
"""Control whether the thermocouple reference junction is internal (INT) or
simulated (SIM). Default is INT.""",
validator=strict_discrete_set,
values=('SIM', 'INT'),
)
temperature_simulated_reference = Instrument.control(
":SENS:TEMP:RJUN:SIM?", ":SENS:TEMP:RJUN:SIM %g",
"""Control the value of the simulated thermocouple reference junction in
Celsius. Default is 23 C.""",
validator=strict_range,
values=(0, 60),
)
internal_temperature = Instrument.measurement(
":SENS:TEMP:RTEM?",
"""Measure the internal temperature in Celsius."""
)
##############
# Statistics #
##############
mean = Instrument.measurement(
":CALC2:FORM MEAN;:CALC2:STAT ON;:CALC2:IMM?;",
"""Get the calculated mean (average) from the buffer data."""
)
maximum = Instrument.measurement(
":CALC2:FORM MAX;:CALC2:STAT ON;:CALC2:IMM?;",
"""Get the calculated maximum from the buffer data."""
)
minimum = Instrument.measurement(
":CALC2:FORM MIN;:CALC2:STAT ON;:CALC2:IMM?;",
"""Get the calculated minimum from the buffer data."""
)
standard_dev = Instrument.measurement(
":CALC2:FORM SDEV;:CALC2:STAT ON;:CALC2:IMM?;",
"""Get the calculated standard deviation from the buffer data."""
)
###########
# Trigger #
###########
trigger_count = Instrument.control(
":TRIG:COUN?", ":TRIG:COUN %d",
"""Control the trigger count which can take values from 1 to 9,999.
Default is 1.""",
validator=strict_range,
values=(1, 9999),
cast=int
)
trigger_delay = Instrument.control(
":TRIG:DEL?", ":TRIG:DEL %g",
"""Control the trigger delay in seconds, which can take values from 0 to
999999.999 s. Default is 0.""",
validator=strict_range,
values=(0, 999999.999)
)
###########
# Methods #
###########
def auto_line_frequency(self):
"""Set appropriate limits for NPLC voltage and temperature readings."""
if self.line_frequency == 50:
self.temperature_nplc_values = (0.01, 50)
self.voltage_nplc_values = (0.01, 50)
else:
self.temperature_nplc_values = (0.01, 60)
self.voltage_nplc_values = (0.01, 60)
def reset(self):
"""Reset the instrument and clear the queue."""
self.write("status:queue:clear;*RST;:stat:pres;:*CLS;")
def trigger(self):
"""Execute a bus trigger, which can be used when :meth:`~.trigger_on_bus`
is configured.
"""
return self.write("*TRG")
def trigger_immediately(self):
"""Configure measurements to be taken with the internal trigger at the maximum
sampling rate.
"""
self.write(":TRIG:SOUR IMM;")
def trigger_on_bus(self):
"""Configure the trigger to detect events based on the bus trigger, which can be
activated by :meth:`~.trigger`.
"""
self.write(":TRIG:SOUR BUS")
def sample_continuously(self):
"""Configure the instrument to continuously read samples
and turn off any buffer or output triggering.
"""
self.disable_buffer()
self.trigger_immediately()
|