| 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 |
import pytest |
| 25 |
|
| 26 |
from pymeasure.test import expected_protocol |
| 27 |
from pymeasure.instruments.keithley.keithley2182 import Keithley2182 |
| 28 |
|
| 29 |
|
| 30 |
def test_voltage_read(): |
| 31 |
with expected_protocol( |
| 32 |
Keithley2182, |
| 33 |
[(":READ?", "3.1415")], |
| 34 |
) as inst: |
| 35 |
assert inst.voltage == pytest.approx(3.1415) |
| 36 |
|
| 37 |
|
| 38 |
def test_voltage_range(): |
| 39 |
with expected_protocol( |
| 40 |
Keithley2182, |
| 41 |
[(":SENS:VOLT:CHAN1:RANG?", "92"), |
| 42 |
(":SENS:VOLT:CHAN1:RANG 2", None) |
| 43 |
], |
| 44 |
) as inst: |
| 45 |
assert inst.ch_1.voltage_range == 92 |
| 46 |
inst.ch_1.voltage_range = 2 |
| 47 |
|
| 48 |
|
| 49 |
def test_voltage_range_trunc(): |
| 50 |
with expected_protocol( |
| 51 |
Keithley2182, |
| 52 |
[(":SENS:VOLT:CHAN2:RANG 15", None), |
| 53 |
(":SENS:VOLT:CHAN2:RANG?", "12"), |
| 54 |
], |
| 55 |
) as inst: |
| 56 |
inst.ch_2.voltage_range = 15 # too large, gets truncated |
| 57 |
assert inst.ch_2.voltage_range == 12 |
| 58 |
|
| 59 |
|
| 60 |
def test_active_channel(): |
| 61 |
with expected_protocol( |
| 62 |
Keithley2182, |
| 63 |
[(":SENS:CHAN?", "1"), |
| 64 |
(":SENS:CHAN 2", None), |
| 65 |
], |
| 66 |
) as inst: |
| 67 |
assert inst.active_channel == 1 |
| 68 |
inst.active_channel = 2 |
| 69 |
|
| 70 |
|
| 71 |
def test_thermocouple(): |
| 72 |
with expected_protocol( |
| 73 |
Keithley2182, |
| 74 |
[(":SENS:TEMP:TC?", "S"), |
| 75 |
(":SENS:TEMP:TC K", None), |
| 76 |
], |
| 77 |
) as inst: |
| 78 |
assert inst.thermocouple == 'S' |
| 79 |
inst.thermocouple = 'K' |
| 80 |
|
| 81 |
|
| 82 |
def test_setup_voltage(): |
| 83 |
with expected_protocol( |
| 84 |
Keithley2182, |
| 85 |
[(":SENS:CHAN 1;" |
| 86 |
":SENS:FUNC 'VOLT';" |
| 87 |
":SENS:VOLT:NPLC 5;", None), |
| 88 |
(":SENS:VOLT:RANG:AUTO 1", None), |
| 89 |
("SYST:ERR?", '0,"No error"'), |
| 90 |
], |
| 91 |
) as inst: |
| 92 |
inst.ch_1.setup_voltage() |
| 93 |
|
| 94 |
|
| 95 |
def test_setup_temperature(): |
| 96 |
with expected_protocol( |
| 97 |
Keithley2182, |
| 98 |
[(":SENS:CHAN 2;" |
| 99 |
":SENS:FUNC 'TEMP';" |
| 100 |
":SENS:TEMP:NPLC 5", None), |
| 101 |
("SYST:ERR?", '0,"No error"'), |
| 102 |
], |
| 103 |
) as inst: |
| 104 |
inst.ch_2.setup_temperature() |