| 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.srs.sr830 import SR830 |
| 28 |
|
| 29 |
|
| 30 |
def test_id(): |
| 31 |
"""Verify the communication of the device type.""" |
| 32 |
with expected_protocol( |
| 33 |
SR830, |
| 34 |
[("*IDN?", "Stanford_Research_Systems,SR830,s/n12345,ver1.07"),], |
| 35 |
) as inst: |
| 36 |
assert inst.id == "Stanford_Research_Systems,SR830,s/n12345,ver1.07" |
| 37 |
|
| 38 |
|
| 39 |
@pytest.mark.parametrize("number, value", ( |
| 40 |
("0", 2e-9), |
| 41 |
("14", 100e-6), |
| 42 |
("25", 0.5), |
| 43 |
)) |
| 44 |
def test_sensitivity(number, value): |
| 45 |
"""Verify the communication of the sensitivity getter.""" |
| 46 |
with expected_protocol( |
| 47 |
SR830, |
| 48 |
[("SENS?", number),], |
| 49 |
) as inst: |
| 50 |
assert inst.sensitivity == pytest.approx(value) |
| 51 |
|
| 52 |
|
| 53 |
def test_frequency(): |
| 54 |
"""Verify the communication of the frequency getter.""" |
| 55 |
with expected_protocol( |
| 56 |
SR830, |
| 57 |
[("FREQ?", "121.98"),], |
| 58 |
) as inst: |
| 59 |
assert inst.frequency == pytest.approx(121.98) |
| 60 |
|
| 61 |
|
| 62 |
def test_snap(): |
| 63 |
"""Verify the communication of the measurement values.""" |
| 64 |
with expected_protocol( |
| 65 |
SR830, |
| 66 |
[("SNAP? 1,2", "-4.17234e-007,-5.9605e-007"),], |
| 67 |
) as inst: |
| 68 |
xy = inst.xy |
| 69 |
assert len(xy) == 2 |
| 70 |
assert xy[0] == pytest.approx(-4.17234e-007) |
| 71 |
assert xy[1] == pytest.approx(-5.9605e-007) |
| 72 |
|
| 73 |
|
| 74 |
def test_get_scaling(): |
| 75 |
"""Verify the communication of the X channel scaling settings.""" |
| 76 |
with expected_protocol( |
| 77 |
SR830, |
| 78 |
[("OEXP? 1", "9.7,1"),], |
| 79 |
) as inst: |
| 80 |
offset, expand = inst.get_scaling("X") |
| 81 |
assert offset == pytest.approx(9.7) |
| 82 |
assert expand == pytest.approx(10) |
| 83 |
|
| 84 |
|
| 85 |
def test_output_conversion(): |
| 86 |
"""Verify the communication of the X channel value with conversion.""" |
| 87 |
with expected_protocol( |
| 88 |
SR830, |
| 89 |
[("OEXP? 1", "10,1"), |
| 90 |
("SENS?", "19"), |
| 91 |
("OUTP?1", "-0.000500266"), |
| 92 |
], |
| 93 |
) as inst: |
| 94 |
conv = inst.output_conversion("X") |
| 95 |
assert conv(inst.x) == pytest.approx(-2.66e-7) |