| 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.test import expected_protocol |
| 26 |
|
| 27 |
from pymeasure.instruments.lakeshore.lakeshore211 import LakeShore211 |
| 28 |
|
| 29 |
|
| 30 |
def test_init(): |
| 31 |
with expected_protocol( |
| 32 |
LakeShore211, |
| 33 |
[], |
| 34 |
): |
| 35 |
pass # Verify the expected communication. |
| 36 |
|
| 37 |
|
| 38 |
def test_temp_kelvin(): |
| 39 |
with expected_protocol( |
| 40 |
LakeShore211, |
| 41 |
[(b"KRDG?", b"27.1")], |
| 42 |
) as instr: |
| 43 |
assert instr.temperature_kelvin == 27.1 |
| 44 |
|
| 45 |
|
| 46 |
def test_temp_celsius(): |
| 47 |
with expected_protocol( |
| 48 |
LakeShore211, |
| 49 |
[(b"CRDG?", b"27.1")], |
| 50 |
) as instr: |
| 51 |
assert instr.temperature_celsius == 27.1 |
| 52 |
|
| 53 |
|
| 54 |
def test_set_analog(): |
| 55 |
with expected_protocol( |
| 56 |
LakeShore211, |
| 57 |
[(b"ANALOG 0,1", None), |
| 58 |
(b"ANALOG?", b"0,1")], |
| 59 |
) as instr: |
| 60 |
instr.analog_configuration = (0, 1) |
| 61 |
assert instr.analog_configuration == (0, 1) |
| 62 |
|
| 63 |
|
| 64 |
def test_set_display(): |
| 65 |
with expected_protocol( |
| 66 |
LakeShore211, |
| 67 |
[(b"DISPFLD 1", None), |
| 68 |
(b"DISPFLD?", b"1")], |
| 69 |
) as instr: |
| 70 |
instr.display_units = 'celsius' |
| 71 |
assert instr.display_units == 'celsius' |
| 72 |
|
| 73 |
|
| 74 |
def test_alarms(): |
| 75 |
with expected_protocol( |
| 76 |
LakeShore211, |
| 77 |
[(b"ALARM?", b"0,+000.0,+000.0,+00.0,0\r\n"), |
| 78 |
(b"ALARM 1,300,10,5,0", None), |
| 79 |
(b"ALARM?", b"1,+300.0,+010.0,+05.0,0\r\n") |
| 80 |
], |
| 81 |
) as instr: |
| 82 |
assert instr.get_alarm_status() == {'on': 0, 'high_value': 0.0, 'low_value': 0.0, |
| 83 |
'deadband': 0.0, 'latch': 0} |
| 84 |
instr.configure_alarm(on=True, high_value=300, low_value=10, deadband=5, latch=False) |
| 85 |
assert instr.get_alarm_status() == {'on': 1, 'high_value': 300.0, 'low_value': 10.0, |
| 86 |
'deadband': 5.0, 'latch': 0} |
| 87 |
|
| 88 |
|
| 89 |
def test_relays(): |
| 90 |
with expected_protocol( |
| 91 |
LakeShore211, |
| 92 |
[(b"RELAY? 1", b"0\r\n"), |
| 93 |
(b"RELAY 1 2", None), |
| 94 |
(b"RELAY? 1", b"2\r\n") |
| 95 |
], |
| 96 |
) as instr: |
| 97 |
assert instr.get_relay_mode(1) == 0 |
| 98 |
instr.configure_relay(1, 2) |
| 99 |
assert instr.get_relay_mode(1) == 2 |