1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import pytest
from pymeasure.test import expected_protocol
from pymeasure.instruments.kuhneelectronic import Kusg245_250A
from pymeasure.instruments.kuhneelectronic.kusg245_250a import termination_character, encoding
termination_character = termination_character.encode(encoding=encoding)[0]
def test_voltage_5v():
with expected_protocol(
Kusg245_250A,
[("5", bytes([0, 1, termination_character]))],
) as inst:
assert inst.voltage_5v == 103.0 / 4700.0
def test_voltage_32v():
with expected_protocol(
Kusg245_250A,
[("8", bytes([0, 1, termination_character]))],
) as inst:
assert inst.voltage_32v == 1282.0 / 8200.0
def test_power_forward():
with expected_protocol(
Kusg245_250A,
[("6", bytes([255, termination_character]))],
) as inst:
assert inst.power_forward == 255
def test_power_reverse():
with expected_protocol(
Kusg245_250A,
[("7", bytes([255, termination_character]))],
) as inst:
assert inst.power_reverse == 255
def test_external_enabled():
with expected_protocol(
Kusg245_250A,
[
("R", "A"),
("r?", bytes([1, termination_character])),
("r", "A"),
("r?", bytes([0, termination_character]))
],
) as inst:
inst.external_enabled = True
assert inst.external_enabled is True
inst.external_enabled = False
assert inst.external_enabled is False
def test_bias_enabled():
with expected_protocol(
Kusg245_250A,
[
("X", "A"),
("x?", bytes([1, termination_character])),
("x", "A"),
("x?", bytes([0, termination_character]))
],
) as inst:
inst.bias_enabled = True
assert inst.bias_enabled is True
inst.bias_enabled = False
assert inst.bias_enabled is False
def test_rf_enabled():
with expected_protocol(
Kusg245_250A,
[
("O", "A"),
("o?", bytes([1, termination_character])),
("o", "A"),
("o?", bytes([0, termination_character]))
],
) as inst:
inst.rf_enabled = True
assert inst.rf_enabled is True
inst.rf_enabled = False
assert inst.rf_enabled is False
def test_pulse_mode_enabled():
with expected_protocol(
Kusg245_250A,
[
("P", "A"),
("p?", bytes([1, termination_character])),
("p", "A"),
("p?", bytes([0, termination_character]))
],
) as inst:
inst.pulse_mode_enabled = True
assert inst.pulse_mode_enabled is True
inst.pulse_mode_enabled = False
assert inst.pulse_mode_enabled is False
def test_freq_steps_fine_enabled():
with expected_protocol(
Kusg245_250A,
[
("fm1", "A"),
("fm?", bytes([1, termination_character])),
("fm0", "A"),
("fm?", bytes([0, termination_character]))
],
) as inst:
inst.freq_steps_fine_enabled = True
assert inst.freq_steps_fine_enabled is True
inst.freq_steps_fine_enabled = False
assert inst.freq_steps_fine_enabled is False
def test_frequency_coarse():
with expected_protocol(
Kusg245_250A,
[
("f2456", "A"),
("f?", "2456MHz"),
("f2400", "A"),
("f?", "2400MHz"),
("f2500", "A"),
("f?", "2500MHz"),
],
) as inst:
inst.frequency_coarse = 2456
assert inst.frequency_coarse == 2456
inst.frequency_coarse = 2000 # must be truncated to 2400
assert inst.frequency_coarse == 2400
inst.frequency_coarse = 3000 # must be truncated to 2500
assert inst.frequency_coarse == 2500
def test_frequency_fine():
with expected_protocol(
Kusg245_250A,
[
("f2456780", "A"),
("f?", "2456780kHz"),
("f2400000", "A"),
("f?", "2400000kHz"),
("f2500000", "A"),
("f?", "2500000kHz"),
],
) as inst:
inst.frequency_fine = 2456778 # must be rounded to 2456780
assert inst.frequency_fine == 2456780
inst.frequency_fine = 2000000 # must be truncated to 2400000
assert inst.frequency_fine == 2400000
inst.frequency_fine = 3000000 # must be truncated to 2500000
assert inst.frequency_fine == 2500000
def test_power_setpoint():
with expected_protocol(
Kusg245_250A,
[
("A123", "A"),
("A?", "123"),
("A000", "A"),
("A?", "000"),
("A250", "A"),
("A?", "250"),
],
) as inst:
inst.power_setpoint = 123
assert inst.power_setpoint == 123
inst.power_setpoint = -1 # must be truncated to 0
assert inst.power_setpoint == 0
inst.power_setpoint = 300 # must be truncated to 250
assert inst.power_setpoint == 250
def test_power_setpoint_limited():
with expected_protocol(
Kusg245_250A, [("A000", "A"), ("A?", "000"), ("A020", "A"), ("A?", "020")], power_limit=20
) as inst:
inst.power_setpoint = -1 # must be truncated to 0
assert inst.power_setpoint == 0
inst.power_setpoint = 300 # must be truncated to power_limit
assert inst.power_setpoint == 20
def test_pulse_width():
with expected_protocol(
Kusg245_250A,
[
("C0125", "A"),
("C?", "0125"),
("C0010", "A"),
("C?", "0010"),
("C1000", "A"),
("C?", "1000"),
],
) as inst:
inst.pulse_width = 123 # must be rounded to 125
assert inst.pulse_width == 125
inst.pulse_width = 0 # must be truncated to 10
assert inst.pulse_width == 10
inst.pulse_width = 10000 # must be truncated to 250
assert inst.pulse_width == 1000
def test_off_time():
with expected_protocol(
Kusg245_250A,
[
("c0125", "A"),
("c?", "0125"),
("c0010", "A"),
("c?", "0010"),
("c1000", "A"),
("c?", "1000"),
],
) as inst:
inst.off_time = 123 # must be rounded to 125
assert inst.off_time == 125
inst.off_time = 0 # must be truncated to 10
assert inst.off_time == 10
inst.off_time = 10000 # must be truncated to 250
assert inst.off_time == 1000
def test_phase_shift():
with expected_protocol(
Kusg245_250A,
[
("H088", "A"),
("H?", bytes([88, termination_character])),
("H000", "A"),
("H?", bytes([0, termination_character])),
("H255", "A"),
("H?", bytes([255, termination_character])),
],
) as inst:
inst.phase_shift = 124
assert inst.phase_shift == pytest.approx(124, 0.01)
inst.phase_shift = -1 # must be truncated to 0
assert inst.phase_shift == 0
inst.phase_shift = 358.6
assert inst.phase_shift == pytest.approx(358.6, 0.01)
def test_reflection_limit():
with expected_protocol(
Kusg245_250A,
[
("B0", "A"),
("B?", bytes([0, termination_character])),
("B4", "A"),
("B?", bytes([4, termination_character])),
("B5", "A"),
("B?", bytes([5, termination_character]))
],
) as inst:
inst.reflection_limit = 0
assert inst.reflection_limit == 0
inst.reflection_limit = 182 # must be rounded to the next
# higher discrete value (200)
assert inst.reflection_limit == 200
inst.reflection_limit = 300 # must be truncated to 230
assert inst.reflection_limit == 230
def test_tune():
with expected_protocol(
Kusg245_250A,
[("b010", "A")],
) as inst:
inst.tune(10)
def test_tune_power_limited():
with expected_protocol(Kusg245_250A, [("b020", "A")], power_limit=20) as inst:
inst.tune(100)
def test_clear_VSWR_error():
with expected_protocol(
Kusg245_250A,
[("z", "A")],
) as inst:
inst.clear_VSWR_error()
def test_store_settings():
with expected_protocol(
Kusg245_250A,
[("SE", "A")],
) as inst:
inst.store_settings()
def test_turn_off():
with expected_protocol(
Kusg245_250A,
[("o", "A"),
("x", "A")],
) as inst:
inst.turn_off()
def test_turn_on():
with expected_protocol(
Kusg245_250A,
[("X", "A"),
("O", "A")],
) as inst:
inst.turn_on()
|