Debian Codegraph @

tests/instruments/agilent/test_agilent4284A.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 pytest
26 from pymeasure.test import expected_protocol
27 from pymeasure.instruments.agilent import Agilent4284A
28
29
30 @pytest.mark.parametrize("frequency", [20, 100, 1e4, 1e6])
31 def test_frequency(frequency):
32 with expected_protocol(
33 Agilent4284A,
34 [("FREQ?", frequency),
35 (f"FREQ {frequency:g}", None),],
36 ) as inst:
37 assert frequency == inst.frequency
38 inst.frequency = frequency
39
40
41 def test_frequency_limit():
42 with pytest.raises(ValueError):
43 with expected_protocol(
44 Agilent4284A,
45 [("FREQ 1", None)],
46 ) as inst:
47 inst.frequency = 1
48
49
50 @pytest.mark.parametrize("power_mode", ["0", "1"])
51 def test_high_power_mode(power_mode):
52 with expected_protocol(
53 Agilent4284A,
54 [("OUTP:HPOW?", power_mode),],
55 ) as inst:
56 assert bool(power_mode) == inst.high_power_enabled
57
58
59 @pytest.mark.parametrize("impedance_mode", [
60 "CPD", "CPQ", "CPG", "CPRP", "CSD", "CSQ", "CSRS", "LPQ", "LPD", "LPG", "LPRP",
61 "LSD", "LSQ", "LSRS", "RX", "ZTD", "ZTR", "GB", "YTD", "YTR"])
62 def test_impedance_mode(impedance_mode):
63 with expected_protocol(
64 Agilent4284A,
65 [("FUNC:IMP?", impedance_mode),
66 (f"FUNC:IMP {impedance_mode}", None),],
67 ) as inst:
68 assert impedance_mode == inst.impedance_mode
69 inst.impedance_mode = impedance_mode
70
71
72 def test_enable_high_power():
73 with expected_protocol(
74 Agilent4284A,
75 [("*OPT?", "1,0,0,0,0"),
76 ("OUTP:HPOW 1", None),
77 ("VOLT:LEV 5", None),],
78 ) as inst:
79 inst.high_power_enabled = True
80 inst.ac_voltage = 5
81
82
83 def test_disable_high_power():
84 with pytest.raises(ValueError):
85 with expected_protocol(
86 Agilent4284A,
87 [("OUTP:HPOW 0", None),
88 ("VOLT:LEV 5", None)],
89 ) as inst:
90 inst.high_power_enabled = False
91 inst.ac_voltage = 5
92
93
94 @pytest.fixture
95 def param_list():
96 freq_input = [1e7, 5e6, 1e6, 5e5, 1e5, 5e4, 1e4, 5e3, 1e3, 500, 100, 50, 20, 10]
97 freq_str = "1000000,500000,100000,50000,10000,5000,1000,500,100,50,20"
98 freq_output = [1e6, 5e5, 1e5, 5e4, 1e4, 5e3, 1e3, 500, 100, 50, 20]
99 measured_str = "0.5,-0.785,+0,+0,"
100 return freq_input, freq_str, freq_output, measured_str
101
102
103 def sweep_measurement(param_list):
104 with expected_protocol(
105 Agilent4284A,
106 [("*CLS", None),
107 ("TRIG:SOUR BUS;:DISP:PAGE LIST;:FORM ASC;:LIST:MODE SEQ;:INIT:CONT ON", None),
108 (f"LIST:FREQ {param_list[1][:-3]};:TRIG:IMM", None),
109 ("STAT:OPER?", "+8"),
110 ("FETCH?", f"{param_list[3]*10}"),
111 ("LIST:FREQ?", f"{param_list[1][:-3]}"),
112 ("LIST:FREQ 20;:TRIG:IMM", None),
113 ("STAT:OPER?", "+8"),
114 ("FETCH?", f"{param_list[3]}"),
115 ("LIST:FREQ?", "20"),
116 ("SYST:ERR?", '0,"No error"')],
117 ) as inst:
118 results = inst.sweep_measurement('frequency', param_list[0])
119 assert results[0] == [0.5,] * 11
120 assert results[1] == [-0.785,] * 11
121 assert results[2] == param_list[2]