| 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 |
|
| 27 |
from pymeasure.test import expected_protocol |
| 28 |
from pymeasure.instruments.anritsu import AnritsuMS464xB, AnritsuMS4642B, AnritsuMS4644B,\ |
| 29 |
AnritsuMS4645B, AnritsuMS4647B |
| 30 |
|
| 31 |
|
| 32 |
def test_init(): |
| 33 |
with expected_protocol( |
| 34 |
AnritsuMS464xB, |
| 35 |
[], |
| 36 |
) as instr: |
| 37 |
assert len(instr.channels) == 16 |
| 38 |
assert len(instr.ch_1.ports) == 4 |
| 39 |
assert len(instr.ch_1.traces) == 16 |
| 40 |
|
| 41 |
|
| 42 |
def test_init_with_different_channel_numbers(): |
| 43 |
# Test init with different number of active channels and installed ports |
| 44 |
with expected_protocol( |
| 45 |
AnritsuMS464xB, |
| 46 |
[], |
| 47 |
active_channels=12, |
| 48 |
installed_ports=2, |
| 49 |
traces_per_channel=10 |
| 50 |
) as instr: |
| 51 |
assert len(instr.channels) == 12 |
| 52 |
assert len(instr.ch_1.ports) == 2 |
| 53 |
assert len(instr.ch_1.traces) == 10 |
| 54 |
|
| 55 |
|
| 56 |
def test_init_unknown_active_channels(): |
| 57 |
# Test init with unknown active channels and traces |
| 58 |
with expected_protocol( |
| 59 |
AnritsuMS464xB, |
| 60 |
[(":SYST:PORT:COUN?", "3"), |
| 61 |
(":DISP:COUN?", "2"), |
| 62 |
(":CALC1:PAR:COUN?", "8"), |
| 63 |
(":CALC2:PAR:COUN?", "12")], |
| 64 |
active_channels="auto", |
| 65 |
installed_ports="auto", |
| 66 |
traces_per_channel="auto", |
| 67 |
) as instr: |
| 68 |
assert len(instr.channels) == 2 |
| 69 |
assert len(instr.ch_1.ports) == 3 |
| 70 |
assert len(instr.ch_1.traces) == 8 |
| 71 |
assert len(instr.ch_2.traces) == 12 |
| 72 |
|
| 73 |
|
| 74 |
def test_update_channels(): |
| 75 |
with expected_protocol( |
| 76 |
AnritsuMS464xB, |
| 77 |
[(":DISP:COUN?", "8"), |
| 78 |
(":DISP:COUN?", "12")], |
| 79 |
) as instr: |
| 80 |
assert len(instr.channels) == 16 |
| 81 |
instr.update_channels() |
| 82 |
assert len(instr.channels) == 8 |
| 83 |
instr.update_channels() |
| 84 |
assert len(instr.channels) == 12 |
| 85 |
|
| 86 |
|
| 87 |
def test_channel_number_of_traces(): |
| 88 |
# Test first level channel |
| 89 |
with expected_protocol( |
| 90 |
AnritsuMS464xB, |
| 91 |
[(":CALC6:PAR:COUN 16", None), |
| 92 |
(":CALC2:PAR:COUN?", "4")], |
| 93 |
) as instr: |
| 94 |
instr.ch_6.number_of_traces = 16 |
| 95 |
assert instr.ch_2.number_of_traces == 4 |
| 96 |
|
| 97 |
|
| 98 |
def test_channel_update_traces(): |
| 99 |
# Test first level channel |
| 100 |
with expected_protocol( |
| 101 |
AnritsuMS464xB, |
| 102 |
[(":CALC1:PAR:COUN?", "4"), |
| 103 |
(":CALC1:PAR:COUN?", "12")], |
| 104 |
) as instr: |
| 105 |
assert len(instr.ch_1.traces) == 16 |
| 106 |
instr.ch_1.update_traces() |
| 107 |
assert len(instr.ch_1.traces) == 4 |
| 108 |
instr.ch_1.update_traces() |
| 109 |
assert len(instr.ch_1.traces) == 12 |
| 110 |
|
| 111 |
|
| 112 |
def test_channel_port_power_level(): |
| 113 |
# Test second level channel (port in channel) |
| 114 |
with expected_protocol( |
| 115 |
AnritsuMS464xB, |
| 116 |
[(":SOUR6:POW:PORT1 12", None), |
| 117 |
(":SOUR2:POW:PORT4?", "-1.5E1")], |
| 118 |
) as instr: |
| 119 |
instr.ch_6.pt_1.power_level = 12. |
| 120 |
assert instr.ch_2.pt_4.power_level == -15. |
| 121 |
|
| 122 |
|
| 123 |
def test_channel_trace_measurement_parameter(): |
| 124 |
# Test second level channel (trace in channel) |
| 125 |
with expected_protocol( |
| 126 |
AnritsuMS464xB, |
| 127 |
[(":CALC6:PAR1:DEF S11", None), |
| 128 |
(":CALC2:PAR6:DEF?", "S21")], |
| 129 |
) as instr: |
| 130 |
instr.ch_6.tr_1.measurement_parameter = "S11" |
| 131 |
assert instr.ch_2.tr_6.measurement_parameter == "S21" |
| 132 |
|
| 133 |
|
| 134 |
def test_subclass_MS4642B_frequency_range(): |
| 135 |
with expected_protocol( |
| 136 |
AnritsuMS4642B, |
| 137 |
[(":SENS1:FREQ:STOP 2e+10", None)], |
| 138 |
) as instr: |
| 139 |
instr.ch_1.frequency_stop = 2e10 |
| 140 |
with pytest.raises(ValueError): |
| 141 |
instr.ch_1.frequency_stop = 3e10 |
| 142 |
|
| 143 |
|
| 144 |
def test_subclass_MS4644B_frequency_range(): |
| 145 |
with expected_protocol( |
| 146 |
AnritsuMS4644B, |
| 147 |
[(":SENS1:FREQ:STOP 4e+10", None)], |
| 148 |
) as instr: |
| 149 |
instr.ch_1.frequency_stop = 4e10 |
| 150 |
with pytest.raises(ValueError): |
| 151 |
instr.ch_1.frequency_stop = 5e10 |
| 152 |
|
| 153 |
|
| 154 |
def test_subclass_MS4645B_frequency_range(): |
| 155 |
with expected_protocol( |
| 156 |
AnritsuMS4645B, |
| 157 |
[(":SENS1:FREQ:STOP 5e+10", None)], |
| 158 |
) as instr: |
| 159 |
instr.ch_1.frequency_stop = 5e10 |
| 160 |
with pytest.raises(ValueError): |
| 161 |
instr.ch_1.frequency_stop = 6e10 |
| 162 |
|
| 163 |
|
| 164 |
def test_subclass_MS4647B_frequency_range(): |
| 165 |
with expected_protocol( |
| 166 |
AnritsuMS4647B, |
| 167 |
[(":SENS1:FREQ:STOP 7e+10", None)], |
| 168 |
) as instr: |
| 169 |
instr.ch_1.frequency_stop = 7e10 |
| 170 |
with pytest.raises(ValueError): |
| 171 |
instr.ch_1.frequency_stop = 8e10 |