Debian Codegraph @

pymeasure/instruments/keithley/keithleyDMM6500.py

raw
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 (
29 truncated_range,
30 truncated_discrete_set,
31 strict_discrete_set,
32 )
33
34 log = logging.getLogger(__name__)
35 log.addHandler(logging.NullHandler())
36
37 BOOL_MAPPINGS = {True: 1, False: 0}
38
39
40 class ScannerCard2000Channel(Channel):
41 MODES = {
42 "voltage": "VOLT:DC",
43 "voltage ac": "VOLT:AC",
44 "resistance": "RES",
45 "resistance 4W": "FRES",
46 "diode": "DIOD",
47 "capacitance": "CAP",
48 "temperature": "TEMP",
49 "continuity": "CONT",
50 "period": "PER:VOLT",
51 "frequency": "FREQ:VOLT",
52 "voltage ratio": "VOLT:DC:RAT",
53 "NONE": "NONE",
54 }
55
56 mode = Channel.control(
57 ":SENS:FUNC? (@{ch})",
58 ':SENS:FUNC "%s", (@{ch})',
59 """ Control the configuration mode for measurements, which can take the values:
60 ``current`` (DC), ``current ac``,
61 ``voltage`` (DC), ``voltage ac``,
62 ``resistance`` (2-wire), ``resistance 4W`` (4-wire),
63 ``diode``, ``capacitance``,
64 ``temperature``, ``continuity``,
65 ``period``, ``frequency``,
66 and ``voltage ratio``.
67 """,
68 validator=strict_discrete_set,
69 values=MODES,
70 map_values=True,
71 get_process=lambda v: v.replace('"', ""),
72 )
73
74 nplc = Channel.control(
75 "{function}:NPLC? (@{ch})",
76 "{function}:NPLC %s, (@{ch})",
77 """ Control the integration time in number of power line cycles (NPLC).
78 Valid values: 0.0005 to 15 (60Hz) or 12 (50Hz or 400Hz)
79 This command is valid only for ``voltage``, 2-wire ohms, and 4-wire ohms.
80
81 .. note::
82
83 Only ``voltage``, ``current``, ``resistance``, ``resistance 4W``, ``diode``,
84 ``temperature``, and ``voltage ratio`` mode support NPLC setting. If current
85 active mode doesn't support NPLC, this command will hang till adapter's
86 timeout and cause -113 "Undefined header" error.
87
88 """,
89 validator=truncated_range,
90 values=[0.0005, 15],
91 )
92
93 range = Instrument.control(
94 "{function}:RANG? (@{ch})",
95 "{function}:RANG %s, (@{ch})",
96 """ Control measuring range for currently active mode. For ``frequency`` and ``period``
97 measurements, :attr:`range` applies to the signal's input voltage, not its frequency""",
98 )
99
100 autorange_enabled = Instrument.control(
101 "{function}:RANG:AUTO? (@{ch})",
102 "{function}:RANG:AUTO %d, (@{ch})",
103 """ Control the autorange state for currently active mode.
104
105 .. note::
106
107 If current active mode doesn't support autorange, this command will hang
108 till adapter's timeout and cause -113 "Undefined header" error.
109
110 """,
111 validator=strict_discrete_set,
112 values=BOOL_MAPPINGS,
113 map_values=True,
114 )
115
116 def _mode_command(self, mode=None):
117 """Get SCPI's function name from mode."""
118 if mode is None:
119 mode = self.mode
120 return self.MODES[mode]
121
122 def enable_filter(self, mode=None, type="repeat", count=1):
123 """Enable the averaging filter for the active mode, or can set another mode by its name.
124
125 :param mode: A valid :attr:`mode` name, or `None` for the active mode
126 :param type: The type of averaging filter, could be ``REPeat``, ``MOVing``, or ``HYBRid``.
127 :param count: A number of averages, which can take take values from 1 to 100
128
129 :return: Filter status read from the instrument
130 """
131 mode_cmd = self._mode_command(mode)
132 self.write(f":SENS:{mode_cmd}:AVER:STAT 1, (@{self.id})")
133 self.write(f":SENS:{mode_cmd}:AVER:TCON {type}, (@{self.id})")
134 self.write(f":SENS:{mode_cmd}:AVER:COUN {count}, (@{self.id})")
135 return self.ask(f":SENS:{mode_cmd}:AVER:STAT? (@{self.id})")
136
137 def disable_filter(self, mode=None):
138 """Disable the averaging filter for the active mode, or can set another mode by its name.
139
140 :param mode: A valid :attr:`mode` name, or `None` for the active mode
141
142 :return: Filter status read from the instrument
143 """
144 mode_cmd = self._mode_command(mode)
145 self.write(f":SENS:{mode_cmd}:AVER:STAT 0, (@{self.id})")
146 return self.ask(f":SENS:{mode_cmd}:AVER:STAT? (@{self.id})")
147
148 def write(self, command):
149 """Write a command to the instrument."""
150 if "{function}" in command:
151 super().write(command.format(function=ScannerCard2000Channel.MODES[self.mode]))
152 else:
153 super().write(command)
154
155
156 class KeithleyDMM6500(SCPIMixin, Instrument):
157 """Represent the Keithely DMM6500 6½-Digit Multimeter and provide a
158 high-level interface for interacting with the instrument.
159 This class only uses "SCPI" command set (see also :attr:`command_set`) to
160 communicate with the instrument.
161
162 .. code-block:: python
163
164 # Access via LAN
165 ip_address = "xxx.xxx.xxx.xxx"
166 dmm = KeithleyDMM6500(f"TCPIP::{ip_address}::inst0::INSTR")
167
168
169 User can also use PyVISA to get DMM6500's USB port name and pass it to :class:`KeithleyDMM6500`
170
171 .. code-block:: python
172
173 import pyvisa
174 rm = pyvisa.ResourceManager()
175 resources = rm.list_resources()
176
177 # assume there is only one USB instruments
178 # Ex. ('USB0::1510::25856::01234567::0::INSTR')
179
180 dmm = KeithleyDMM6500( resources[0] )
181
182 # Measure voltage
183 dmm.measure_voltage()
184 print(dmm.voltage)
185
186 # Measure AC voltage
187 dmm.measure_voltage(ac=True)
188 print(dmm.voltage)
189 """
190
191 MODES = {
192 "voltage": "VOLT:DC",
193 "voltage ac": "VOLT:AC",
194 "current": "CURR:DC",
195 "current ac": "CURR:AC",
196 "resistance": "RES",
197 "resistance 4W": "FRES",
198 "diode": "DIOD",
199 "capacitance": "CAP",
200 "temperature": "TEMP",
201 "continuity": "CONT",
202 "period": "PER:VOLT",
203 "frequency": "FREQ:VOLT",
204 "voltage ratio": "VOLT:DC:RAT",
205 }
206
207 MODES_HAVE_AUTORANGE = (
208 "current",
209 "current ac",
210 "voltage",
211 "voltage ac",
212 "resistance",
213 "resistance 4W",
214 "capacitance",
215 "voltage ratio",
216 )
217
218 channels = Instrument.MultiChannelCreator(ScannerCard2000Channel, list(range(1, 11)))
219
220 def __init__(
221 self, adapter, name="Keithley DMM6500 6½-Digit Multimeter", read_termination="\n", **kwargs
222 ):
223 super().__init__(
224 adapter,
225 name,
226 read_termination=read_termination,
227 **kwargs)
228 self.command_set = "SCPI"
229
230 def __exit__(self, exc_type, exc_value, traceback):
231 """Fully close the connection when the `with` code block finishes."""
232 self.adapter.close()
233
234 def close(self):
235 """Close the connection"""
236 self.adapter.close()
237
238 ###########
239 # General #
240 ###########
241
242 command_set = Instrument.control(
243 "*LANG?",
244 "*LANG %s",
245 """ Control the command set that to use with DMM6500. Reboot the instrument is needed
246 after changing the command set. Available values are:
247 :code:`SCPI`, :code:`TSP`, :code:`SCPI2000`, and :code:`SCPI34401`.
248 The :attr:`KeithleyDMM6500` class was designed to use :code:`SCPI` command set only.
249
250 .. note::
251
252 If you want to use TSP command set, you can use :attr:`write()` and :attr:`ask()`
253 to send TSP command instead.
254
255 """,
256 validator=strict_discrete_set,
257 values=["TSP", "SCPI", "SCPI2000", "SCPI34401"],
258 )
259 mode = Instrument.control(
260 ":SENS:FUNC?",
261 ':SENS:FUNC "%s"',
262 """ Control the active measure function. Available values are:
263 ``current`` (DC), ``current ac``, ``voltage`` (DC), ``voltage ac``,
264 ``resistance`` (2-wire), ``resistance 4W`` (4-wire),
265 ``diode``, ``capacitance``, ``temperature``, ``continuity``,
266 ``period``, ``frequency``, and ``voltage ratio``.
267 """,
268 validator=strict_discrete_set,
269 values=MODES,
270 map_values=True,
271 get_process=lambda v: v.replace('"', ""),
272 )
273
274 line_frequency = Instrument.measurement(
275 ":SYST:LFR?",
276 """ Get the power line frequency which automatically detected while the instrument is
277 powered on.""",
278 )
279
280 aperture = Instrument.control(
281 "{function}:APER?",
282 "{function}:APER %s",
283 """ Control the aperture time of currently active :attr:`mode`.
284
285 Valid values: ``MIN``, ``DEF``, ``MAX``, or number between 8.333u and 0.25 s.
286
287 .. note::
288
289 Only ``voltage``, ``current``, ``resistance``, ``resistance 4W``, ``diode``,
290 ``temperature``, ``frequency``, ``period``, and ``voltage ratio`` mode support
291 aperture setting. If current active mode doesn't support aperture, this command
292 will hang till adapter's timeout and cause -113 "Undefined header" error.
293
294 """,
295 )
296
297 range = Instrument.control(
298 "{function}:RANG?",
299 "{function}:RANG:AUTO 0;UPP %s",
300 """ Control the positive full-scale measure range for currently active :attr:`mode`.
301 Auto-range is disabled when this property is set.
302
303 For frequency and period measurements, ranging applies to the signal's input voltage,
304 not its frequency""",
305 )
306
307 autorange_enabled = Instrument.control(
308 "{function}:RANG:AUTO?",
309 "{function}:RANG:AUTO %d",
310 """ Control the autorange state for currently active :attr:`mode`.
311
312 .. note::
313
314 If currently active mode doesn't support autorange, this command will hang
315 till adapter's timeout and cause -113 "Undefined header" error.
316
317 """,
318 validator=strict_discrete_set,
319 values=BOOL_MAPPINGS,
320 map_values=True,
321 )
322
323 relative = Instrument.control(
324 "{function}:REL?",
325 "{function}:REL %g",
326 """ Control the relative offset value of currently active :attr:`mode`.
327 When relative offset is enabled, all subsequent measured readings are offset by
328 the value that is set for this command.
329 If the instrument acquires the value, read this setting to return the value that
330 was measured internally. See also the :attr:`relative_enabled`.""",
331 )
332
333 relative_enabled = Instrument.control(
334 "{function}:REL:STAT?",
335 "{function}:REL:STAT %d",
336 """ Control the relative offset value applied to new measurements for currently
337 active :attr:`mode`.""",
338 validator=strict_discrete_set,
339 values=BOOL_MAPPINGS,
340 map_values=True,
341 )
342
343 nplc = Instrument.control(
344 "{function}:NPLC?",
345 "{function}:NPLC %s",
346 """ Control the integration time in number of power line cycles (NPLC) of currently
347 active :attr:`mode`. This value sets the amount of time that the input signal is measured.
348 Valid values are: 0.0005 to 15 (60Hz) or 12 (50Hz or 400Hz).
349
350 .. note::
351
352 Only ``voltage``, ``current``, ``resistance``, ``resistance 4W``, ``diode``,
353 ``temperature``, and ``voltage ratio`` mode support NPLC setting. If current
354 active mode doesn't support NPLC, this command will hang till adapter's timeout
355 and cause -113 "Undefined header" error.
356
357 """,
358 validator=truncated_range,
359 values=[0.0005, 15],
360 )
361
362 digits = Instrument.control(
363 ":DISP:{function}:DIG?",
364 ":DISP:{function}:DIG %d",
365 """ Control the displaying number of digits for currently active :attr:`mode`.
366 Available values are from 3 to 6 representing display digits from 3.5 to 6.5.""",
367 validator=truncated_discrete_set,
368 values=[3, 4, 5, 6],
369 cast=int,
370 )
371
372 detector_bandwidth = Instrument.control(
373 "{function}:DET:BAND?",
374 "{function}:DET:BAND %s",
375 """ Control the lowest frequency expected in the input signal in Hz
376 ONLY for AC voltage and AC current measurement,
377
378 Valid values: 3, 30, 300, ``MIN``, ``DEF``, ``MAX``.""",
379 validator=strict_discrete_set,
380 values=[3, 30, 300, "MIN", "DEF", "MAX"],
381 )
382
383 autozero_enabled = Instrument.control(
384 "{function}:AZER?",
385 "{function}:AZER %d",
386 """ Control automatic updates to the internal reference measurements (autozero)
387 of the instrument.
388 """,
389 validator=strict_discrete_set,
390 values=BOOL_MAPPINGS,
391 map_values=True,
392 )
393
394 system_time = Instrument.control(
395 ":SYST:TIME? 1",
396 ":SYST:TIME %s",
397 """ Control system time on the instrument.
398 Format of set is: ``year, month, day, hour, minute, second`` or ``hour, minute, second``.
399 Example: Using ``time`` package to set instrument's clock:
400 ``dmm.system_time = time.strftime("%Y, %m, %d, %H, %M, %S")``
401 """,
402 )
403
404 def trigger_single_autozero(self):
405 """Cause the instrument to refresh the reference and zero measurements once.
406
407 Consequent autozero measurements are disabled."""
408 self.write("AZER:ONCE")
409
410 terminals_used = Instrument.measurement(
411 "ROUT:TERM?",
412 """ Get which set of input and output terminals the instrument is using.
413 Return can be ``FRONT`` or ``REAR``.""",
414 values={"FRONT": "FRON", "REAR": "REAR"},
415 map_values=True,
416 )
417
418 ###########
419 # Display #
420 ###########
421
422 display_screen = Instrument.setting(
423 ":DISP:SCR %s",
424 """ Set displayed front-panel screen by the name. Available names are:
425 ``HOME`` (home), ``HOME_LARG`` (home screen with large readings), ``READ`` (reading table),
426 ``HIST`` (histogram), ``SWIPE_FUNC`` (FUNCTIONS swipe screen),
427 ``SWIPE_GRAP`` (GRAPH swipe screen), ``SWIPE_SEC`` (SECONDARY swipe screen),
428 ``SWIPE_SETT`` (SETTINGS swipe screen), ``SWIPE_STAT`` (STATISTICS swipe screen),
429 ``SWIPE_USER`` (USER swipe screen), ``SWIPE_CHAN`` (CHANNEL swipe screen),
430 ``SWIPE_NONS`` (NONSWITCH swipe screen),
431 ``SWIPE_SCAN`` (SCAN swipe screen), ``CHANNEL_CONT`` (Channel control screen),
432 ``CHANNEL_SETT`` (Channel settings screen), ``CHANNEL_SCAN`` (Channel scan screen),
433 or ``PROC`` (minimal CPU resources).
434 """,
435 validator=strict_discrete_set,
436 values=(
437 "HOME",
438 "HOME_LARG",
439 "READ",
440 "HIST",
441 "SWIPE_FUNC",
442 "SWIPE_GRAP",
443 "SWIPE_SEC",
444 "SWIPE_SETT",
445 "SWIPE_STAT",
446 "SWIPE_USER",
447 "SWIPE_CHAN",
448 "SWIPE_NONS",
449 "SWIPE_SCAN",
450 "CHANNEL_CONT",
451 "CHANNEL_SETT",
452 "CHANNEL_SCAN",
453 "PROC",
454 ),
455 )
456
457 def displayed_text(self, top_line=None, bot_line=None):
458 """Display text messages on the front-panel USER swipe screen.
459 If no messages were defined, screen will be cleared.
460
461 :param top_line: 1st line message
462 :param bot_line: 2nd line message
463
464 :return: None
465 """
466 self.write(":DISP:CLE")
467 self.display_screen = "SWIPE_USER"
468 if top_line:
469 self.write(f':DISP:USER1:TEXT "{top_line}"')
470 if bot_line:
471 self.write(f':DISP:USER2:TEXT "{bot_line}"')
472
473 ###############
474 # Current (A) #
475 ###############
476
477 current = Instrument.measurement(
478 ":READ?",
479 """ Measure a DC or AC current in Amps, based on the active :attr:`mode`.""",
480 )
481 current_range = Instrument.control(
482 ":SENS:CURR:RANG?",
483 ":SENS:CURR:RANG:AUTO 0;:SENS:CURR:RANG %g",
484 """ Control the DC current full-scale measure range in Amps.
485 Available ranges are 10e-6, 100e-6, 1e-3, 10e-3, 100e-3, 1, 3 Amps (for front terminals),
486 and 10 Amps (for rear terminals). Auto-range is disabled when this property is set.
487 See also the :attr:`range`.""",
488 validator=truncated_discrete_set,
489 values=[10e-6, 100e-6, 1e-3, 10e-3, 100e-3, 1, 3, 10],
490 )
491 current_relative = Instrument.control(
492 ":SENS:CURR:REL?",
493 ":SENS:CURR:REL %g",
494 """ Control the DC current relative value in Amps (float strictly from -3 to 3).
495 See also the :attr:`relative`.""",
496 validator=truncated_range,
497 values=[-3.0, 3.0],
498 )
499 current_relative_enabled = Instrument.control(
500 ":SENS:CURR:REL:STAT?",
501 ":SENS:CURR:REL:STAT %d",
502 """ Control a relative offset value applied to DC current measurement.
503 See also the :attr:`relative_enabled`.""",
504 validator=strict_discrete_set,
505 values=BOOL_MAPPINGS,
506 map_values=True,
507 )
508 current_nplc = Instrument.control(
509 ":SENS:CURR:NPLC?",
510 ":SENS:CURR:NPLC %g",
511 """ Control the number of power line cycles (NPLC) for the DC current measurement
512 (float strictly from 0.0005 to 15). See also the :attr:`nplc`.""",
513 validator=truncated_range,
514 values=[0.0005, 15],
515 )
516 current_digits = Instrument.control(
517 ":DISP:CURR:DIG?",
518 ":DISP:CURR:DIG %d",
519 """ Control the number of digits in the DC current readings (integer strictly from 3 to 6).
520 See also the :attr:`digits`.
521 """,
522 validator=truncated_discrete_set,
523 values=[3, 4, 5, 6],
524 cast=int,
525 )
526
527 # Current (AC)
528 current_ac_range = Instrument.control(
529 ":SENS:CURR:AC:RANG?",
530 ":SENS:CURR:AC:RANG:AUTO 0;:SENS:CURR:AC:RANG %g",
531 """ Control the AC current positive full-scale measure range in Amps.
532 Available ranges are 1e-3, 10e-3, 100e-3, 1, 3 Amps (for front terminals),
533 and 10 Amps (for rear terminals). See also the :attr:`range`.""",
534 validator=truncated_discrete_set,
535 values=[1e-3, 10e-3, 100e-3, 1, 3, 10],
536 )
537 current_ac_relative = Instrument.control(
538 ":SENS:CURR:AC:REL?",
539 ":SENS:CURR:AC:REL %g",
540 """ Control the AC current relative value in Amps (float strictly from -3 to 3).
541 See also the :attr:`relative`.""",
542 validator=truncated_range,
543 values=[-3.0, 3.0],
544 )
545 current_ac_relative_enabled = Instrument.control(
546 ":SENS:CURR:AC:REL:STAT?",
547 ":SENS:CURR:AC:REL:STAT %d",
548 """ Control a relative offset value applied to AC current measurement.
549 See also the :attr:`relative_enabled`.""",
550 validator=strict_discrete_set,
551 values=BOOL_MAPPINGS,
552 map_values=True,
553 )
554 current_ac_digits = Instrument.control(
555 ":DISP:CURR:AC:DIG?",
556 ":DISP:CURR:AC:DIG %d",
557 """ Control the number of digits in the AC current readings (integer strictly from 3 to 6).
558 See also the :attr:`digits`.
559 """,
560 validator=truncated_discrete_set,
561 values=[3, 4, 5, 6],
562 cast=int,
563 )
564 current_ac_bandwidth = Instrument.control(
565 ":SENS:CURR:AC:DET:BAND?",
566 ":SENS:CURR:AC:DET:BAND %g",
567 """ Control the detector bandwidth in Hz for AC current measurement
568 (integer strictly among 3, 30, and 300).
569 """,
570 validator=truncated_discrete_set,
571 values=[3, 30, 300],
572 )
573
574 def measure_current(self, max_current=10e-3, ac=False):
575 """Configure the instrument to measure current,
576 based on a maximum current to set the range, and
577 a boolean flag to determine if DC or AC is required.
578
579 :param max_current: A current in Volts to set the current range
580 :param ac: False for DC current, and True for AC current
581 """
582 if ac:
583 self.mode = "current ac"
584 self.current_ac_range = max_current
585 else:
586 self.mode = "current"
587 self.current_range = max_current
588
589 ###############
590 # Voltage (V) #
591 ###############
592
593 # DC
594 voltage = Instrument.measurement(
595 ":READ?",
596 """ Measure a DC or AC voltage in Volts, based on the active :attr:`mode`.""",
597 )
598 voltage_range = Instrument.control(
599 ":SENS:VOLT:RANG?",
600 ":SENS:VOLT:RANG:AUTO 0;:SENS:VOLT:RANG %g",
601 """ Control the DC voltage full-scale measure range in Volts.
602 Available ranges are 0.1, 1, 10, 100, 1000.
603 Auto-range is disabled when this property is set. See also the :attr:`range`.""",
604 validator=truncated_discrete_set,
605 values=[0.1, 1, 10, 100, 1000],
606 )
607 voltage_relative = Instrument.control(
608 ":SENS:VOLT:REL?",
609 ":SENS:VOLT:REL %g",
610 """ Control the DC voltage relative value in Volts (float strictly from -1000 to 1000).
611 See also the :attr:`relative`.""",
612 validator=truncated_range,
613 values=[-1000, 1000],
614 )
615 voltage_relative_enabled = Instrument.control(
616 ":SENS:VOLT:REL:STAT?",
617 ":SENS:VOLT:REL:STAT %d",
618 """ Control a relative offset value applied to DC voltage measurement.
619 See also the :attr:`relative_enabled`.""",
620 validator=strict_discrete_set,
621 values=BOOL_MAPPINGS,
622 map_values=True,
623 )
624 voltage_nplc = Instrument.control(
625 ":SENS:VOLT:NPLC?",
626 ":SENS:VOLT:NPLC %g",
627 """ Control the number of power line cycles (NPLC) for the DC voltage measurement
628 (float strictly from 0.0005 to 15). See also the :attr:`nplc`.""",
629 validator=truncated_range,
630 values=[0.0005, 15],
631 )
632 voltage_digits = Instrument.control(
633 ":DISP:VOLT:DIG?",
634 ":DISP:VOLT:DIG %d",
635 """ Control the number of digits in the DC voltage readings (integer strictly from 3 to 6).
636 See also the :attr:`digits`.""",
637 validator=truncated_discrete_set,
638 values=[3, 4, 5, 6],
639 cast=int,
640 )
641 # AC
642 voltage_ac_range = Instrument.control(
643 ":SENS:VOLT:AC:RANG?",
644 ":SENS:VOLT:RANG:AUTO 0;:SENS:VOLT:AC:RANG %g",
645 """ Control the AC voltage positive full-scale measure range in Volts.
646 Available ranges are 0.1, 1, 10, 100, 750.
647 Auto-range is disabled when this property is set. See also the :attr:`range`.
648 """,
649 validator=truncated_discrete_set,
650 values=[0.1, 1, 10, 100, 750],
651 )
652 voltage_ac_relative = Instrument.control(
653 ":SENS:VOLT:AC:REL?",
654 ":SENS:VOLT:AC:REL %g",
655 """ Control the AC voltage relative value in Volts (float strictly from -750 to 750).
656 See also the :attr:`relative`.
657 """,
658 validator=truncated_range,
659 values=[-750, 750],
660 )
661 voltage_ac_relative_enabled = Instrument.control(
662 ":SENS:VOLT:AC:REL:STAT?",
663 ":SENS:VOLT:AC:REL:STAT %d",
664 """ Control a relative offset value applied to AC voltage measurement.
665 See also the :attr:`relative_enabled`.
666 """,
667 validator=strict_discrete_set,
668 values=BOOL_MAPPINGS,
669 map_values=True,
670 )
671 voltage_ac_digits = Instrument.control(
672 ":DISP:VOLT:AC:DIG?",
673 ":DISP:VOLT:AC:DIG %d",
674 """ Control the number of digits in the AC voltage readings (integer strictly from 3 to 6).
675 See also the :attr:`digits`.
676 """,
677 validator=truncated_discrete_set,
678 values=[3, 4, 5, 6],
679 cast=int,
680 )
681 voltage_ac_bandwidth = Instrument.control(
682 ":SENS:VOLT:AC:DET:BAND?",
683 ":SENS:VOLT:AC:DET:BAND %g",
684 """ Control the detector bandwidth in Hz for AC voltage measurement
685 (integer strictly among 3, 30, and 300).
686 """,
687 validator=truncated_discrete_set,
688 values=[3, 30, 300],
689 )
690
691 def measure_voltage(self, max_voltage=1, ac=False):
692 """Configure the instrument to measure voltage,
693 based on a maximum voltage to set the range, and
694 a boolean flag to determine if DC or AC is required.
695
696 :param max_voltage: A voltage in Volts to set the voltage range
697 :param ac: False for DC voltage, and True for AC voltage
698 """
699 if ac:
700 self.mode = "voltage ac"
701 self.voltage_ac_range = max_voltage
702 else:
703 self.mode = "voltage"
704 self.voltage_range = max_voltage
705
706 ####################
707 # Resistance (Ohm) #
708 ####################
709
710 resistance = Instrument.measurement(
711 ":READ?",
712 """ Measure a resistance in Ohms for both 2-wire and 4-wire
713 configurations, based on the active :attr:`mode`. """,
714 )
715 resistance_range = Instrument.control(
716 ":SENS:RES:RANG?",
717 ":SENS:RES:RANG:AUTO 0;:SENS:RES:RANG %g",
718 """ Control the 2-wire resistance full-scale measure range in Ohms.
719 Available ranges are: 10, 100, 1e3, 10e3, 100e3, 1e6, 10e6, and 100e6.
720 Auto-range is disabled when this property is set. See also the :attr:`range`.""",
721 validator=truncated_discrete_set,
722 values=[10, 100, 1e3, 10e3, 100e3, 1e6, 10e6, 100e6],
723 )
724 resistance_relative = Instrument.control(
725 ":SENS:RES:REL?",
726 ":SENS:RES:REL %g",
727 """ Control the 2-wire resistance relative value in Ohms (float strictly
728 from -100M to 100M). See also the :attr:`relative`.""",
729 validator=truncated_range,
730 values=[-1e8, 1e8],
731 )
732 resistance_relative_enabled = Instrument.control(
733 ":SENS:RES:REL:STAT?",
734 ":SENS:RES:REL:STAT %d",
735 """ Control a relative offset value applied to 2-wire resistance measurement.
736 See also the :attr:`relative_enabled`.""",
737 validator=strict_discrete_set,
738 values=BOOL_MAPPINGS,
739 map_values=True,
740 )
741 resistance_nplc = Instrument.control(
742 ":SENS:RES:NPLC?",
743 ":SENS:RES:NPLC %g",
744 """ Control the number of power line cycles (NPLC) for the 2-wire resistance measurement
745 (float strictly from 0.0005 to 15). See also the :attr:`nplc`.""",
746 validator=truncated_range,
747 values=[0.0005, 15],
748 )
749 resistance_digits = Instrument.control(
750 ":DISP:RES:DIG?",
751 ":DISP:RES:DIG %d",
752 """ Control the number of digits in the 2-wire resistance readings
753 (integer strictly from 3 to 6). See also the :attr:`digits`.""",
754 validator=truncated_discrete_set,
755 values=[3, 4, 5, 6],
756 cast=int,
757 )
758 resistance_4W_range = Instrument.control(
759 ":SENS:FRES:RANG?",
760 ":SENS:FRES:RANG:AUTO 0;:SENS:FRES:RANG %g",
761 """ Control the 4-wire resistance full-scale measure range in Ohms.
762 Available ranges are: 1, 10, 100, 1e3, 10e3, 100e3, 1e6, 10e6, and 100e6.
763 Auto-range is disabled when this property is set. See also the :attr:`range`.""",
764 validator=truncated_discrete_set,
765 values=[1, 10, 100, 1e3, 10e3, 100e3, 1e6, 10e6, 100e6],
766 )
767 resistance_4W_relative = Instrument.control(
768 ":SENS:FRES:REL?",
769 ":SENS:FRES:REL %g",
770 """ Control the 4-wire resistance relative value in Ohms (float strictly
771 from -100M to 100M). See also the :attr:`relative`.""",
772 validator=truncated_range,
773 values=[-1e8, 1e8],
774 )
775 resistance_4W_relative_enabled = Instrument.control(
776 ":SENS:FRES:REL:STAT?",
777 ":SENS:FRES:REL:STAT %d",
778 """ Control a relative offset value applied to 4-wire resistance measurement.
779 See also the :attr:`relative_enabled`.""",
780 validator=strict_discrete_set,
781 values=BOOL_MAPPINGS,
782 map_values=True,
783 )
784 resistance_4W_nplc = Instrument.control(
785 ":SENS:FRES:NPLC?",
786 ":SENS:FRES:NPLC %g",
787 """ Control the number of power line cycles (NPLC) for the 4-wire resistance measurement
788 (float strictly from 0.0005 to 15). See also the :attr:`nplc`.""",
789 validator=truncated_range,
790 values=[0.0005, 15],
791 )
792 resistance_4W_digits = Instrument.control(
793 ":DISP:FRES:DIG?",
794 ":DISP:FRES:DIG %d",
795 """ Control the number of digits in the 4-wire resistance readings
796 (integer strictly from 3 to 6). See also the :attr:`digits`.""",
797 validator=truncated_discrete_set,
798 values=[3, 4, 5, 6],
799 cast=int,
800 )
801
802 def measure_resistance(self, max_resistance=10e6, wires=2):
803 """Configure the instrument to measure resistance,
804 based on a maximum resistance to set the range.
805
806 :param max_resistance: A resistance in Ohms to set the resistance range
807 :type max_resistance: float
808 :param wires: ``2`` for normal resistance, and ``4`` for 4-wires resistance
809 :type wires: int
810
811 :return: None
812 """
813 if wires == 2:
814 self.mode = "resistance"
815 self.resistance_range = max_resistance
816 elif wires == 4:
817 self.mode = "resistance 4W"
818 self.resistance_4W_range = max_resistance
819 else:
820 raise ValueError("Keithley DMM6500 only supports 2 or 4 wire resistance measurements.")
821
822 ##################
823 # Frequency (Hz) #
824 ##################
825
826 frequency = Instrument.measurement(
827 ":READ?",
828 """ Measure a frequency in Hz, based on the active :attr:`mode`. """,
829 )
830 frequency_relative = Instrument.control(
831 ":SENS:FREQ:REL?",
832 ":SENS:FREQ:REL %g",
833 """ Control the frequency relative value in Hz (float strictly from -1 MHz to 1 MHz).
834 See also the :attr:`relative`.""",
835 validator=truncated_range,
836 values=[-1e6, 1e6],
837 )
838 frequency_relative_enabled = Instrument.control(
839 ":SENS:FREQ:REL:STAT?",
840 ":SENS:FREQ:REL:STAT %d",
841 """ Control a relative offset value applied to frequency measurement.
842 See also the :attr:`relative_enabled`.""",
843 validator=strict_discrete_set,
844 values=BOOL_MAPPINGS,
845 map_values=True,
846 )
847 frequency_digits = Instrument.control(
848 ":DISP:FREQ:DIG?",
849 ":DISP:FREQ:DIG %d",
850 """ Control the number of digits in the frequency readings (integer strictly from 3 to 6).
851 See also the :attr:`digits`.""",
852 validator=truncated_discrete_set,
853 values=[3, 4, 5, 6],
854 cast=int,
855 )
856 frequency_threshold = Instrument.control(
857 ":SENS:FREQ:THR:RANG?",
858 ":SENS:FREQ:THR:RANG %g",
859 """ Control the expected input level in Volts for the frequency measurement
860 (float strictly from 0.1 to 750V).""",
861 validator=truncated_range,
862 values=[0.1, 750],
863 )
864 frequency_threshold_auto_enabled = Instrument.control(
865 ":SENS:FREQ:THR:RANG:AUTO?",
866 ":SENS:FREQ:THR:RANG:AUTO %d",
867 """ Control the auto threshold range for frequency measurement enabled or not.""",
868 validator=strict_discrete_set,
869 values=BOOL_MAPPINGS,
870 map_values=True,
871 )
872 frequency_aperature = Instrument.control(
873 ":SENS:FREQ:APER?",
874 ":SENS:FREQ:APER %g",
875 """ Control the aperture time in seconds for frequency measurement
876 (float strictly from 2 ms to 273 ms). See also :attr:`aperture`.""",
877 validator=truncated_range,
878 values=[0.002, 0.273],
879 )
880
881 def measure_frequency(self):
882 """Configure the instrument to measure frequency."""
883 self.mode = "frequency"
884
885 ##############
886 # Period (s) #
887 ##############
888
889 period = Instrument.measurement(
890 ":READ?",
891 """ Measure a period in seconds, based on the active :attr:`mode`. """,
892 )
893 period_relative = Instrument.control(
894 ":SENS:PER:REL?",
895 ":SENS:PER:REL %g",
896 """ Control the period relative value in seconds (float strictly from -1 s to 1 s).
897 See also the :attr:`relative`.""",
898 validator=truncated_range,
899 values=[-1, 1],
900 )
901 period_relative_enabled = Instrument.control(
902 ":SENS:PER:REL:STAT?",
903 ":SENS:PER:REL:STAT %d",
904 """ Control a relative offset value applied to period measurement.
905 See also the :attr:`relative_enabled`.""",
906 validator=strict_discrete_set,
907 values=BOOL_MAPPINGS,
908 map_values=True,
909 )
910 period_digits = Instrument.control(
911 ":DISP:PER:DIG?",
912 ":DISP:PER:DIG %d",
913 """ Control the number of digits in the period readings (integer strictly from 3 to 6).
914 See also the :attr:`digits`.""",
915 validator=truncated_discrete_set,
916 values=[3, 4, 5, 6],
917 cast=int,
918 )
919 period_threshold = Instrument.control(
920 ":SENS:PER:THR:RANG?",
921 ":SENS:PRE:THR:RANG %g",
922 """ Control the expected input level in Volts for the period measurement
923 (float strictly from 0.1 to 750V).""",
924 validator=truncated_range,
925 values=[0.1, 750],
926 )
927 period_threshold_auto_enabled = Instrument.control(
928 ":SENS:PER:THR:RANG:AUTO?",
929 ":SENS:PER:THR:RANG:AUTO %d",
930 """ Control the auto threshold range for period measurement enabled or not.""",
931 validator=strict_discrete_set,
932 values=BOOL_MAPPINGS,
933 map_values=True,
934 )
935 period_aperature = Instrument.control(
936 ":SENS:PER:APER?",
937 ":SENS:PER:APER %g",
938 """ Control the aperture time in seconds for period measurement
939 (float strictly from 2 ms to 273 ms). See also :attr:`aperture`""",
940 validator=truncated_range,
941 values=[0.002, 0.273],
942 )
943
944 def measure_period(self):
945 """Configure the instrument to measure period."""
946 self.mode = "period"
947
948 ###################
949 # Temperature (C) #
950 ###################
951
952 temperature = Instrument.measurement(
953 ":READ?",
954 """ Measure a temperature in Celsius, based on the active :attr:`mode`. """,
955 )
956 temperature_relative = Instrument.control(
957 ":SENS:TEMP:REL?",
958 ":SENS:TEMP:REL %g",
959 """ Control the temperature relative value in Celsius (float strictly from -3310 C to
960 3310 C). See also the :attr:`relative`.""",
961 validator=truncated_range,
962 values=[-3310, 3310],
963 )
964 temperature_relative_enabled = Instrument.control(
965 ":SENS:TEMP:REL:STAT?",
966 ":SENS:TEMP:REL:STAT %d",
967 """ Control a relative offset value applied to temperature measurement.
968 See also the :attr:`relative_enabled`.""",
969 validator=strict_discrete_set,
970 values=BOOL_MAPPINGS,
971 map_values=True,
972 )
973 temperature_nplc = Instrument.control(
974 ":SENS:TEMP:NPLC?",
975 ":SENS:TEMP:NPLC %g",
976 """ Control the number of power line cycles (NPLC) for the temperature measurement
977 (float strictly from 0.0005 to 15). See also the :attr:`nplc`.""",
978 validator=truncated_range,
979 values=[0.0005, 15],
980 )
981 temperature_digits = Instrument.control(
982 ":DISP:TEMP:DIG?",
983 ":DISP:TEMP:DIG %d",
984 """ Control the number of digits in the temperature readings (integer strictly from 3 to 6).
985 See also the :attr:`digits`.""",
986 validator=truncated_discrete_set,
987 values=[3, 4, 5, 6],
988 cast=int,
989 )
990
991 def measure_temperature(self):
992 """Configure the instrument to measure temperature."""
993 self.mode = "temperature"
994
995 ###############
996 # Capacitance #
997 ###############
998
999 capacitance = Instrument.measurement(
1000 ":READ?",
1001 """ Measure a capacitance in Farad, based on the active :attr:`mode`.""",
1002 )
1003 capacitance_relative = Instrument.control(
1004 ":SENS:CAP:REL?",
1005 ":SENS:CAP:REL %g",
1006 """ Control the capacitance relative value in Farad (float strictly
1007 from -0.001 to 0.001 F). See also the :attr:`relative`.""",
1008 validator=truncated_range,
1009 values=[-0.001, 0.001],
1010 )
1011 capacitance_relative_status = Instrument.control(
1012 ":SENS:CAP:REL:STAT?",
1013 ":SENS:CAP:REL:STAT %d",
1014 """ Control a relative offset value applied to capacitance measurement.
1015 See also the :attr:`relative_enabled`.""",
1016 validator=strict_discrete_set,
1017 values=BOOL_MAPPINGS,
1018 map_values=True,
1019 )
1020 capacitance_range = Instrument.control(
1021 ":SENS:CAP:RANG?",
1022 ":SENS:CAP:RANG:AUTO 0;:SENS:CURR:RANG %g",
1023 """ Control the capacitance full-scale measure range in Farad.
1024 Available ranges are 1e-9, 10e-9, 100e-9, 1e-6, 10e-6, 100e-6, 1e-3.
1025 Auto-range is disabled when this property is set. See also the :attr:`range`.""",
1026 validator=truncated_discrete_set,
1027 values=[1e-9, 10e-9, 100e-9, 1e-6, 10e-6, 100e-6, 1e-3],
1028 )
1029 capacitance_digits = Instrument.control(
1030 ":DISP:CAP:DIG?",
1031 ":DISP:CAP:DIG %d",
1032 """ Control the number of digits in the capacitance readings (integer strictly from 3 to 6).
1033 See also the :attr:`digits`.""",
1034 validator=truncated_discrete_set,
1035 values=[3, 4, 5, 6],
1036 cast=int,
1037 )
1038
1039 def measure_capacitance(self, max_capacitance=1e-3):
1040 """Configure the instrument to measure capacitance.
1041
1042 :param max_capacitance: Set :attr:`capacitance_range` after changing :attr:`mode`
1043
1044 :return: None
1045 """
1046 self.mode = "capacitance"
1047 self.capacitance_range = max_capacitance
1048
1049 #########
1050 # Diode #
1051 #########
1052
1053 diode = Instrument.measurement(
1054 ":READ?",
1055 """ Measure a diode's forward voltage drop of general-purpose diodes and the
1056 Zener voltage of Zener diodes on the 10V range with a constant test current (bias level),
1057 based on the active :attr:`mode`. """,
1058 )
1059 diode_bias = Instrument.control(
1060 ":SENS:DIOD:BIAS:LEV?",
1061 ":SENS:DIOD:BIAS:LEV %g",
1062 """ Control the amount of current in Amps the instrument sources while making
1063 measurement. Available bias levels are 1e-5, 0.0001, 0.001, 0.01.""",
1064 validator=truncated_discrete_set,
1065 values=[1e-5, 0.0001, 0.001, 0.01],
1066 )
1067 diode_nplc = Instrument.control(
1068 ":SENS:DIOD:NPLC?",
1069 ":SENS:DIOD:NPLC %g",
1070 """ Control the number of power line cycles (NPLC) for the diode measurement
1071 (float strictly from 0.0005 to 15). See also the :attr:`nplc`.""",
1072 validator=truncated_range,
1073 values=[0.0005, 15],
1074 )
1075
1076 def measure_diode(self):
1077 """Configure the instrument to perform diode testing.
1078
1079 :return: None
1080 """
1081 self.mode = "diode"
1082
1083 ##############
1084 # Continuity #
1085 ##############
1086
1087 def measure_continuity(self):
1088 """Configure the instrument to perform continuity testing.
1089
1090 :return: None
1091 """
1092 self.mode = "continuity"
1093
1094 ##########
1095 # Buffer #
1096 ##########
1097 # Main buffer functions are inherited from `KeithleyBuffer` class
1098
1099 buffer_points = buffer_size = Instrument.control(
1100 ":TRAC:POIN?",
1101 ":TRAC:POIN %d",
1102 """ Control the number of buffer points.
1103 This does not represent actual points in the buffer, but the configuration
1104 value instead. `0` means the largest buffer possible based on the available
1105 memory when the bufer is created.""",
1106 validator=truncated_range,
1107 values=[0, 6_000_000],
1108 cast=int,
1109 )
1110
1111 points_in_buffer = Instrument.measurement(
1112 "TRAC:ACT?",
1113 """ Get the number of readings stored in the buffer.""",
1114 cast=int,
1115 )
1116
1117 ###########
1118 # Formats #
1119 ###########
1120
1121 data_format = Instrument.control(
1122 "FORMAT:DATA?",
1123 "FORMAT:DATA %s",
1124 """ Control data format that is used when transferring readings over the remote
1125 interface. Available values are ``ASC`` (ASCII), ``REAL`` (double-precision),
1126 or ``SRE`` (single-precision).""",
1127 validator=strict_discrete_set,
1128 values=("ASC", "REAL", "SRE"),
1129 )
1130
1131 ################
1132 # Scanner Card #
1133 ################
1134
1135 scan_id = Instrument.measurement(
1136 ":SYST:CARD1:IDN?",
1137 """ Get scanner card's ID.""",
1138 separator="|",
1139 )
1140
1141 scan_vch_start = Instrument.measurement(
1142 "SYST:CARD1:VCH:STAR?",
1143 """ Get the first channel in the slot that supports voltage or 2-wire measurements.""",
1144 cast=int,
1145 )
1146
1147 scan_vch_end = Instrument.measurement(
1148 "SYST:CARD1:VCH:END?",
1149 """ Get the last channel in the slot that supports voltage or 2-wire measurements.""",
1150 cast=int,
1151 )
1152
1153 scan_card_vmax = Instrument.measurement(
1154 "SYST:CARD1:VMAX?", """ Get the maximum voltage of all channels.""", cast=int
1155 )
1156
1157 pseudo_scanner_enabled = Instrument.setting(
1158 ":SYST:PCAR1 %d",
1159 """ Set pseudo scanner card if there's no scanner card in the instrument.
1160 After setting, user can check current scanner card by :attr:`scan_id`.
1161 If a scanner card is installed, this setting won't have any effect.""",
1162 validator=strict_discrete_set,
1163 values={True: 2000, False: 0},
1164 map_values=True,
1165 )
1166
1167 scan_channels = Instrument.control(
1168 ":ROUT:SCAN:CRE?",
1169 ":ROUT:SCAN:CRE (@%s)",
1170 """ Control the channel list of scanning. An empty string will clear the list.
1171 Use comma to separate single channel and use a colon to separate the first
1172 and last channel in the list.
1173 Examples: ``1``, ``1,3,5``, ``1:2, 7:8``, or ``1:10``.
1174 """,
1175 get_process=lambda x: x[-1].replace(")", ""),
1176 separator="@",
1177 )
1178
1179 @property
1180 def scan_channels_list(self):
1181 """Get :attr:`scan_channels` string to a list of integers.
1182
1183 For example, when :attr:`scan_channels` is ``1,3:5,7:8,10``,
1184 this attribute will return ``[1,3,4,5,7,8,10]``. If ``scan_channels_list=[1,2,3,4,6]``,
1185 the :attr:`scan_channels` will be ``1:4,6``.
1186 """
1187 chan_str = self.scan_channels
1188 # Trans string to list of int, ex. "1,3:5,7:8,10" -> [1,3,4,5,7,8,10]
1189 chn_list = chan_str.split(",")
1190 for idx, ch in enumerate(chn_list):
1191 try:
1192 chn_list[idx] = int(ch)
1193 except ValueError:
1194 # process string "a:b" -> a, a+1, ..., b
1195 ch = list(map(int, ch.split(":")))
1196 ch[-1] += 1
1197 chn_list[idx: idx + 1] = list(range(*ch))
1198 return chn_list
1199
1200 @scan_channels_list.setter
1201 def scan_channels_list(self, new_channels):
1202 """Set scan channels by a list or tuple."""
1203 if isinstance(new_channels, (list, tuple)):
1204 self.scan_channels = ",".join(map(str, new_channels))
1205 else:
1206 log.error("Not an acceptable list")
1207
1208 scan_count = Instrument.control(
1209 ":ROUT:SCAN:COUN:SCAN?",
1210 ":ROUT:SCAN:COUN:SCAN %d",
1211 """ Control the number of times the scan is repeated. Set to ``0`` set the scan
1212 to repeat until aborted.""",
1213 cast=int,
1214 )
1215
1216 scan_interval = Instrument.control(
1217 ":ROUT:SCAN:INT?",
1218 ":ROUT:SCAN:INT %d",
1219 """ Control the interval time (0s to 100ks) between scan starts when the
1220 :attr:`scan_count` is more than one.""",
1221 validator=truncated_range,
1222 values=[0, 100e3],
1223 cast=int,
1224 )
1225
1226 def scanned_data(self, start_idx=None, end_idx=None, raw=False):
1227 """Return a list of scanning values from the buffer.
1228
1229 :param start_idx: A bool value which controls communication state while scanning.
1230 Default is ``True`` and the communication waits until the commands are complete
1231 to accept new commands
1232 :param end_idx: An alternative way to set :attr:`scan_count`
1233 :param raw: An alternative way to set :attr:`scan_interval` in second
1234 :return: A list of scan channels' measured
1235 :rtype: A list of channels' list
1236 """
1237 self.write(":FORM:DATA ASCII")
1238 if start_idx is None:
1239 start_idx = self.ask(":TRAC:ACT:STAR?")
1240 if end_idx is None:
1241 end_idx = self.ask(":TRAC:ACT:END?")
1242 data = self.values(f":TRAC:DATA? {start_idx}, {end_idx}")
1243 if raw:
1244 return data
1245 else:
1246 nums = len(self.scan_channels_list)
1247 # re-organize data to 2D list
1248 return [data[i::nums] for i in range(nums)]
1249
1250 @property
1251 def scan_modes(self):
1252 """Get a dictionary of every channel's mode."""
1253 res = dict()
1254 for i in range(self.scan_vch_start, self.scan_vch_end + 1):
1255 res[i] = self.channels[i].mode
1256 return res
1257
1258 @scan_modes.setter
1259 def scan_modes(self, new_mode):
1260 """Set all channels to the new mode. Ex: ``scan_modes = "voltage"``"""
1261 self.write(f':SENS:FUNC "{self._mode_command(new_mode)}", (@1:10)')
1262
1263 @property
1264 def scan_iscomplete(self):
1265 """Get Event Status Register (ESR) bit 0 to determine if previous works were
1266 completed.
1267 This property is used while running time-consuming scanning operation."""
1268 res = int(self.ask("*ESR?")) & 1
1269 if res == 1:
1270 return True
1271 else:
1272 return False
1273
1274 def scan_start(self, block_communication=True, count=None, interval=None):
1275 """Start the scanner card to close each channel of :attr:`scan_channels` sequentially
1276 and to do measurements.
1277
1278 If :attr:`scan_count` is larger than 1, the next scanning will start again
1279 after :attr:`scan_interval` second. Running large counts or long interval scanning
1280 is a time-consuming operation. It's better to set ``block_communication=False`` and
1281 use :attr:`scan_iscomplete` to check if the measurement is completed.
1282
1283 :param block_communication: A bool value which controls communication state while
1284 scanning. Default is ``True`` and the communication waits until the commands
1285 are complete to accept new commands
1286 :param count: An alternative way to set :attr:`scan_count` before scanning.
1287 :param interval: An alternative way to set :attr:`scan_interval` in second before
1288 scanning.
1289 :return: None
1290 """
1291 if count:
1292 self.scan_count = count
1293 if interval:
1294 self.scan_interval = interval
1295 self.clear()
1296 if block_communication:
1297 self.write(":INIT;*WAI")
1298 log.info("Enable blocking communication.")
1299 else:
1300 self.write(":INIT")
1301 self.write("*OPC")
1302 log.info("Enable non-blocking communication.")
1303 log.info("Use `scan_iscomplete` to know the status.")
1304
1305 def scan_stop(self):
1306 """Abort the scanning measurement by stopping the measurement arming and
1307 triggering sequence.
1308
1309 :return: None
1310 """
1311 self.write(":ABOR")
1312
1313 ##########
1314 # Common #
1315 ##########
1316
1317 def _mode_command(self, mode=None):
1318 """Get SCPI's function name from mode."""
1319 if mode is None:
1320 mode = self.mode
1321 return self.MODES[mode]
1322
1323 def auto_range_status(self, mode=None):
1324 """Get the status of auto-range of active mode or another mode by its name.
1325 Only ``current`` (DC), ``current ac``, ``voltage`` (DC), ``voltage ac``,
1326 ``resistance`` (2-wire), ``resistance 4W`` (4-wire), ``capacitance``,
1327 and ``voltage ratio`` support autorange. If chosen mode is not in these
1328 modes, this command will also return ``False``.
1329
1330 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1331 :return: a bool value for auto-range enabled or disabled
1332 :rtype: bool
1333
1334 """
1335 if mode is None:
1336 mode = self.mode
1337 if mode in self.MODES_HAVE_AUTORANGE:
1338 value = self.ask(f":SENS:{self._mode_command(mode)}:RANG:AUTO?")
1339 if value == "1":
1340 return True
1341 else:
1342 return False
1343 else:
1344 return False
1345
1346 def auto_range(self, mode=None):
1347 """Set the active mode to use auto-range, or can set another mode by its name.
1348
1349 Only ``current`` (DC), ``current ac``, ``voltage`` (DC), ``voltage ac``,
1350 ``resistance`` (2-wire), ``resistance 4W`` (4-wire), ``capacitance``,
1351 and ``voltage ratio`` support autorange. If chosen mode is not in these
1352 modes, this command will do nothing.
1353
1354 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1355
1356 """
1357 if mode is None:
1358 mode = self.mode
1359 if mode in self.MODES_HAVE_AUTORANGE:
1360 self.write(f":SENS:{self._mode_command(mode)}:RANG:AUTO 1")
1361
1362 def enable_relative(self, mode=None):
1363 """Enable the application of a relative offset value to the measurement
1364 for the active mode, or can set another mode by its name.
1365
1366 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1367 """
1368 self.write(f":SENS:{self._mode_command(mode)}:REL:STAT 1")
1369
1370 def disable_relative(self, mode=None):
1371 """Disable the application of a relative offset value to the measurement
1372 for the active mode, or can set another mode by its name.
1373
1374 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1375 """
1376 self.write(f":SENS:{self._mode_command(mode)}:REL:STAT 0")
1377
1378 def acquire_relative(self, mode=None):
1379 """Set the active value as the relative for the active mode,
1380 or can set another mode by its name.
1381
1382 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1383
1384 :return: The relative value that was acquired
1385
1386 """
1387 mode_cmd = self._mode_command(mode)
1388 self.write(f":SENS:{mode_cmd}:REL:ACQ")
1389 rel = float(self.ask(f":SENS:{mode_cmd}:REL?"))
1390 return rel
1391
1392 def enable_filter(self, mode=None, type="repeat", count=1):
1393 """Enable the averaging filter for the active mode,
1394 or can set another mode by its name.
1395
1396 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1397 :param type: The type of averaging filter, could be ``REPeat``, ``MOVing``, or ``HYBRid``.
1398 :param count: A number of averages, which can take take values from 1 to 100
1399
1400 :return: Filter status read from the instrument
1401 """
1402 mode_cmd = self._mode_command(mode)
1403 self.write(f":SENS:{mode_cmd}:AVER:STAT 1")
1404 self.write(f":SENS:{mode_cmd}:AVER:TCON {type}")
1405 self.write(f":SENS:{mode_cmd}:AVER:COUN {count}")
1406 return self.ask(f":SENS:{mode_cmd}:AVER:STAT?")
1407
1408 def disable_filter(self, mode=None):
1409 """Disable the averaging filter for the active mode,
1410 or can set another mode by its name.
1411
1412 :param mode: A valid :attr:`mode` name, or `None` for the active mode
1413
1414 :return: Filter status read from the instrument
1415 """
1416 mode_cmd = self._mode_command(mode)
1417 self.write(f":SENS:{mode_cmd}:AVER:STAT 0")
1418 return self.ask(f":SENS:{mode_cmd}:AVER:STAT?")
1419
1420 def beep(self, frequency, duration):
1421 """Sound a system beep.
1422
1423 :param frequency: A frequency in Hz between 20 Hz and 8000 Hz
1424 :param duration: The amount of time to play the tone between 0.001 s to 100 s
1425 :return: None
1426 """
1427 self.write(f":SYST:BEEP {frequency:g}, {duration:g}")
1428
1429 def write(self, command):
1430 """Write a command to the instrument.
1431
1432 :param command: A command
1433 :param type: str
1434 :return: None
1435 """
1436 # Using if statement can prevent RecursionError because `self.mode`
1437 # will query instrument and call `write()` function again.
1438 if "{function}" in command:
1439 super().write(command.format(function=KeithleyDMM6500.MODES[self.mode]))
1440 else:
1441 super().write(command)