| 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 |
from datetime import datetime |
| 25 |
|
| 26 |
import pytest |
| 27 |
|
| 28 |
from pymeasure.test import expected_protocol |
| 29 |
|
| 30 |
from pymeasure.instruments.hp import HP8560A, HP8561B |
| 31 |
from pymeasure.instruments.hp.hp856Xx import Trace, MixerMode, CouplingMode, DemodulationMode, \ |
| 32 |
DetectionModes, AmplitudeUnits, HP856Xx, ErrorCode, FrequencyReference, PeakSearchMode, \ |
| 33 |
StatusRegister, SourceLevelingControlMode, SweepCoupleMode, SweepOut, TraceDataFormat, \ |
| 34 |
TriggerMode, WindowType |
| 35 |
|
| 36 |
|
| 37 |
class TestHP856Xx: |
| 38 |
def test_id(self): |
| 39 |
with expected_protocol( |
| 40 |
HP856Xx, |
| 41 |
[("ID?", "HP8560A,002,H03")], |
| 42 |
) as instr: |
| 43 |
assert instr.id == "HP8560A,002,H03" |
| 44 |
|
| 45 |
def test_attenuation(self): |
| 46 |
with expected_protocol( |
| 47 |
HP856Xx, |
| 48 |
[("AT 70", None), |
| 49 |
("AT?", "70")], |
| 50 |
) as instr: |
| 51 |
# test set and get of attenuation as integer |
| 52 |
instr.attenuation = 70 |
| 53 |
assert instr.attenuation == 70 |
| 54 |
|
| 55 |
def test_attenuation_string_parameters(self): |
| 56 |
with expected_protocol( |
| 57 |
HP856Xx, |
| 58 |
[("AT AUTO", None), |
| 59 |
("AT?", "20"), ], |
| 60 |
) as instr: |
| 61 |
# test string parameters |
| 62 |
instr.attenuation = "AUTO" |
| 63 |
assert instr.attenuation == 20 |
| 64 |
|
| 65 |
def test_attenuation_truncation(self): |
| 66 |
with expected_protocol( |
| 67 |
HP856Xx, |
| 68 |
[("AT 20", None), |
| 69 |
("AT?", "20")], |
| 70 |
) as instr: |
| 71 |
instr.attenuation = 16 |
| 72 |
assert instr.attenuation == 20 |
| 73 |
|
| 74 |
@pytest.mark.parametrize("amplitude_unit", [e for e in AmplitudeUnits]) |
| 75 |
def test_amplitude_units(self, amplitude_unit): |
| 76 |
with expected_protocol( |
| 77 |
HP856Xx, |
| 78 |
[("AUNITS " + amplitude_unit, None), |
| 79 |
("AUNITS?", amplitude_unit)], |
| 80 |
) as instr: |
| 81 |
instr.amplitude_unit = amplitude_unit |
| 82 |
assert instr.amplitude_unit == amplitude_unit |
| 83 |
|
| 84 |
@pytest.mark.parametrize( |
| 85 |
"function, command", |
| 86 |
[ |
| 87 |
("set_auto_couple", "AUTOCPL"), |
| 88 |
("exchange_traces", "AXB"), |
| 89 |
("subtract_display_line_from_trace_b", "BML"), |
| 90 |
("set_continuous_sweep", "CONTS"), |
| 91 |
("set_full_span", "FS"), |
| 92 |
("set_linear_scale", "LN"), |
| 93 |
("set_marker_to_center_frequency", "MKCF"), |
| 94 |
("set_marker_minimum", "MKMIN"), |
| 95 |
("set_marker_to_reference_level", "MKRL"), |
| 96 |
("set_marker_delta_to_span", "MKSP"), |
| 97 |
("set_marker_to_center_frequency_step_size", "MKSS"), |
| 98 |
("preset", "IP"), |
| 99 |
("recall_open_short_average", "RCLOSCAL"), |
| 100 |
("recall_thru", "RCLTHRU"), |
| 101 |
("sweep_single", "SNGLS"), |
| 102 |
("store_open", "STOREOPEN"), |
| 103 |
("store_short", "STORESHORT"), |
| 104 |
("store_thru", "STORETHRU"), |
| 105 |
("adjust_all", "ADJALL"), |
| 106 |
("set_crt_adjustment_pattern", "ADJCRT"), |
| 107 |
("trigger_sweep", "TS"), |
| 108 |
] |
| 109 |
) |
| 110 |
def test_primitive_commands(self, command, function): |
| 111 |
""" |
| 112 |
Tests primitive commands which have no parameter or query derivat |
| 113 |
""" |
| 114 |
with expected_protocol( |
| 115 |
HP856Xx, |
| 116 |
[(command, None)] |
| 117 |
) as instr: |
| 118 |
getattr(instr, function)() |
| 119 |
|
| 120 |
@pytest.mark.parametrize("trace", [e for e in Trace]) |
| 121 |
def test_blank_trace(self, trace): |
| 122 |
with expected_protocol( |
| 123 |
HP856Xx, |
| 124 |
[("BLANK " + trace, None)] |
| 125 |
) as instr: |
| 126 |
instr.blank_trace(trace) |
| 127 |
|
| 128 |
def test_blank_trace_exceptions(self): |
| 129 |
with expected_protocol( |
| 130 |
HP856Xx, |
| 131 |
[] |
| 132 |
) as instr: |
| 133 |
with pytest.raises(ValueError): |
| 134 |
instr.blank_trace("TEST") |
| 135 |
|
| 136 |
with pytest.raises(TypeError): |
| 137 |
instr.blank_trace(0) |
| 138 |
|
| 139 |
@pytest.mark.parametrize("function, command", [ |
| 140 |
("start_frequency", "FA"), |
| 141 |
("center_frequency", "CF"), |
| 142 |
("stop_frequency", "FB"), |
| 143 |
("frequency_offset", "FOFFSET"), |
| 144 |
("span", "SP") |
| 145 |
]) |
| 146 |
@pytest.mark.parametrize("hp_derivat, max_freq", [(HP8560A, 2.9e9), (HP8561B, 6.5e9)]) |
| 147 |
def test_frequencies(self, function, command, hp_derivat, max_freq): |
| 148 |
with expected_protocol( |
| 149 |
hp_derivat, |
| 150 |
[("%s %.11E Hz" % (command, max_freq), None), |
| 151 |
("%s?" % command, '%.11E' % max_freq)] |
| 152 |
) as instr: |
| 153 |
setattr(instr, function, max_freq) |
| 154 |
assert getattr(instr, function) == max_freq |
| 155 |
|
| 156 |
@pytest.mark.parametrize("trace", [e for e in Trace]) |
| 157 |
def test_clear_write_trace(self, trace): |
| 158 |
with expected_protocol( |
| 159 |
HP856Xx, |
| 160 |
[("CLRW " + trace, None)] |
| 161 |
) as instr: |
| 162 |
instr.clear_write_trace(trace) |
| 163 |
|
| 164 |
def test_clear_write_trace_exceptions(self): |
| 165 |
with expected_protocol( |
| 166 |
HP856Xx, |
| 167 |
[] |
| 168 |
) as instr: |
| 169 |
with pytest.raises(ValueError): |
| 170 |
instr.clear_write_trace("TEST") |
| 171 |
|
| 172 |
with pytest.raises(TypeError): |
| 173 |
instr.clear_write_trace(0) |
| 174 |
|
| 175 |
@pytest.mark.parametrize("coupling", [e for e in CouplingMode]) |
| 176 |
def test_coupling(self, coupling): |
| 177 |
with expected_protocol( |
| 178 |
HP856Xx, |
| 179 |
[("COUPLE " + coupling, None), |
| 180 |
("COUPLE?", coupling)] |
| 181 |
) as instr: |
| 182 |
instr.coupling = coupling |
| 183 |
assert instr.coupling == coupling |
| 184 |
|
| 185 |
@pytest.mark.parametrize("demod_mode", [e for e in DemodulationMode]) |
| 186 |
def test_demodulation_mode(self, demod_mode): |
| 187 |
with expected_protocol( |
| 188 |
HP856Xx, |
| 189 |
[("DEMOD " + demod_mode, None), |
| 190 |
("DEMOD?", demod_mode)] |
| 191 |
) as instr: |
| 192 |
instr.demodulation_mode = demod_mode |
| 193 |
assert instr.demodulation_mode == demod_mode |
| 194 |
|
| 195 |
@pytest.mark.parametrize("on_off, boole", [("1", True), ("0", False)]) |
| 196 |
def test_demodulation_agc_enabled(self, on_off, boole): |
| 197 |
with expected_protocol( |
| 198 |
HP856Xx, |
| 199 |
[("DEMODAGC " + on_off, None), |
| 200 |
("DEMODAGC?", on_off)] |
| 201 |
) as instr: |
| 202 |
instr.demodulation_agc_enabled = boole |
| 203 |
assert instr.demodulation_agc_enabled == boole |
| 204 |
|
| 205 |
def test_demodulation_time(self): |
| 206 |
with expected_protocol( |
| 207 |
HP856Xx, |
| 208 |
[("DEMODT 1.02000000000E+01", None), |
| 209 |
("DEMODT?", "1.03000000000E+01")] |
| 210 |
) as instr: |
| 211 |
instr.demodulation_time = 10.2 |
| 212 |
assert instr.demodulation_time == 10.3 |
| 213 |
|
| 214 |
@pytest.mark.parametrize("detector_mode", [e for e in DetectionModes]) |
| 215 |
def test_detector_mode(self, detector_mode): |
| 216 |
with expected_protocol( |
| 217 |
HP856Xx, |
| 218 |
[("DET " + detector_mode, None), |
| 219 |
("DET?", detector_mode)] |
| 220 |
) as instr: |
| 221 |
instr.detector_mode = detector_mode |
| 222 |
assert instr.detector_mode == detector_mode |
| 223 |
|
| 224 |
@pytest.mark.parametrize("string_params", ["ON", "OFF"]) |
| 225 |
def test_display_line_enabled(self, string_params): |
| 226 |
with expected_protocol( |
| 227 |
HP856Xx, |
| 228 |
[ |
| 229 |
("DL " + string_params, None) |
| 230 |
] |
| 231 |
) as instr: |
| 232 |
instr.display_line_enabled = True if string_params == "ON" else False |
| 233 |
|
| 234 |
def test_check_done(self): |
| 235 |
with expected_protocol( |
| 236 |
HP856Xx, |
| 237 |
[("DONE?", "1")], |
| 238 |
) as instr: |
| 239 |
instr.check_done() |
| 240 |
|
| 241 |
def test_errors(self): |
| 242 |
with expected_protocol( |
| 243 |
HP856Xx, |
| 244 |
[("ERR?", "112,101,111")], |
| 245 |
) as instr: |
| 246 |
assert instr.errors == [ErrorCode(112), ErrorCode(101), ErrorCode(111)] |
| 247 |
|
| 248 |
def test_elapsed_time(self): |
| 249 |
with expected_protocol( |
| 250 |
HP856Xx, |
| 251 |
[("EL?", "1800")], |
| 252 |
) as instr: |
| 253 |
assert instr.elapsed_time == 1800 |
| 254 |
|
| 255 |
@pytest.mark.parametrize( |
| 256 |
"function, command", |
| 257 |
[ |
| 258 |
("sampling_frequency", "SMP"), |
| 259 |
("lo_frequency", "LO"), |
| 260 |
("mroll_frequency", "MROLL"), |
| 261 |
("oroll_frequency", "OROLL"), |
| 262 |
("xroll_frequency", "XROLL") |
| 263 |
] |
| 264 |
) |
| 265 |
def test_fdiag_frequencies(self, function, command): |
| 266 |
with expected_protocol( |
| 267 |
HP856Xx, |
| 268 |
[("FDIAG %s,?" % command, '%.11E' % 2.8E8)] |
| 269 |
) as instr: |
| 270 |
assert getattr(instr, function) == 2.8E8 |
| 271 |
|
| 272 |
def test_sampler_harmonic_number(self): |
| 273 |
with expected_protocol( |
| 274 |
HP856Xx, |
| 275 |
[("FDIAG HARM,?", '%.11E' % 1.40000000000E1)] |
| 276 |
) as instr: |
| 277 |
assert instr.sampler_harmonic_number == 14 |
| 278 |
|
| 279 |
def test_frequency_display_enabled(self): |
| 280 |
with expected_protocol( |
| 281 |
HP856Xx, |
| 282 |
[("FDSP?", "0")] |
| 283 |
) as instr: |
| 284 |
assert instr.frequency_display_enabled is False |
| 285 |
|
| 286 |
def test_fft(self): |
| 287 |
with expected_protocol( |
| 288 |
HP856Xx, |
| 289 |
[("FFT TRA,TRB,TRA", None)] |
| 290 |
) as instr: |
| 291 |
instr.do_fft(Trace.A, Trace.B, Trace.A) |
| 292 |
|
| 293 |
def test_fft_exceptions(self): |
| 294 |
with expected_protocol( |
| 295 |
HP856Xx, |
| 296 |
[] |
| 297 |
) as instr: |
| 298 |
with pytest.raises(TypeError): |
| 299 |
instr.do_fft(0, 4, 5) |
| 300 |
|
| 301 |
with pytest.raises(ValueError): |
| 302 |
instr.do_fft("TRAZ", "zuo", "TEWST") |
| 303 |
|
| 304 |
@pytest.mark.parametrize("frequency_reference", [e for e in FrequencyReference]) |
| 305 |
def test_frequency_reference_source(self, frequency_reference): |
| 306 |
with expected_protocol( |
| 307 |
HP856Xx, |
| 308 |
[("FREF " + frequency_reference, None), |
| 309 |
("FREF?", frequency_reference)] |
| 310 |
) as instr: |
| 311 |
instr.frequency_reference_source = frequency_reference |
| 312 |
assert instr.frequency_reference_source == frequency_reference |
| 313 |
|
| 314 |
@pytest.mark.parametrize( |
| 315 |
"function, command", |
| 316 |
[ |
| 317 |
("graticule_enabled", "GRAT"), |
| 318 |
("marker_signal_tracking_enabled", "MKTRACK"), |
| 319 |
("marker_noise_mode_enabled", "MKNOISE"), |
| 320 |
("normalize_trace_data_enabled", "NORMLIZE"), |
| 321 |
("protect_state_enabled", "PSTATE"), |
| 322 |
("trace_a_minus_b_enabled", "AMB"), |
| 323 |
("trace_a_minus_b_plus_dl_enabled", "AMBPL"), |
| 324 |
("annotation_enabled", "ANNOT") |
| 325 |
] |
| 326 |
) |
| 327 |
def test_on_off_commands(self, function, command): |
| 328 |
with expected_protocol( |
| 329 |
HP856Xx, |
| 330 |
[(command + " 0", None), |
| 331 |
(command + "?", "1")] |
| 332 |
) as instr: |
| 333 |
setattr(instr, function, False) |
| 334 |
assert getattr(instr, function) is True |
| 335 |
|
| 336 |
@pytest.mark.parametrize("cmd", ["CURR", "FULL"]) |
| 337 |
def test_adjust_if(self, cmd): |
| 338 |
with expected_protocol( |
| 339 |
HP856Xx, |
| 340 |
[("ADJIF 1", None), |
| 341 |
("ADJIF %s" % cmd, None), |
| 342 |
("ADJIF?", "1")] |
| 343 |
) as instr: |
| 344 |
instr.adjust_if = True |
| 345 |
instr.adjust_if = cmd |
| 346 |
assert instr.adjust_if is True |
| 347 |
|
| 348 |
def test_logarithmic_scale(self): |
| 349 |
with expected_protocol( |
| 350 |
HP856Xx, |
| 351 |
[("LG 1 DB", None), |
| 352 |
("LG?", "10")] |
| 353 |
) as instr: |
| 354 |
instr.logarithmic_scale = 1 |
| 355 |
assert instr.logarithmic_scale == 10 |
| 356 |
|
| 357 |
@pytest.mark.parametrize( |
| 358 |
"function, cmdstr", |
| 359 |
[ |
| 360 |
("set_minimum_hold", "MINH"), |
| 361 |
("set_maximum_hold", "MXMH") |
| 362 |
] |
| 363 |
) |
| 364 |
@pytest.mark.parametrize("trace", [e for e in Trace]) |
| 365 |
def test_hold(self, trace, function, cmdstr): |
| 366 |
with expected_protocol( |
| 367 |
HP856Xx, |
| 368 |
[(cmdstr + " " + trace, None)] |
| 369 |
) as instr: |
| 370 |
getattr(instr, function)(trace) |
| 371 |
|
| 372 |
@pytest.mark.parametrize("function", ["set_minimum_hold", "set_maximum_hold"]) |
| 373 |
def test_hold_exceptions(self, function): |
| 374 |
with expected_protocol( |
| 375 |
HP856Xx, |
| 376 |
[] |
| 377 |
) as instr: |
| 378 |
with pytest.raises(ValueError): |
| 379 |
getattr(instr, function)("TEST") |
| 380 |
|
| 381 |
with pytest.raises(TypeError): |
| 382 |
getattr(instr, function)(0) |
| 383 |
|
| 384 |
def test_marker_amplitude(self): |
| 385 |
with expected_protocol( |
| 386 |
HP856Xx, |
| 387 |
[("MKA?", 2.8e7)] |
| 388 |
) as instr: |
| 389 |
assert instr.marker_amplitude == 2.8e7 |
| 390 |
|
| 391 |
def test_marker_delta(self): |
| 392 |
with expected_protocol( |
| 393 |
HP856Xx, |
| 394 |
[ |
| 395 |
("MKD %.11E Hz" % 28, None), |
| 396 |
("MKD?", 2.8e7) |
| 397 |
] |
| 398 |
) as instr: |
| 399 |
instr.marker_delta = 2.8e1 |
| 400 |
assert instr.marker_delta == 2.8e7 |
| 401 |
|
| 402 |
def test_marker_frequency(self): |
| 403 |
with expected_protocol( |
| 404 |
HP856Xx, |
| 405 |
[ |
| 406 |
("MKF %.11E Hz" % 1, None), |
| 407 |
("MKF?", 0.5) |
| 408 |
] |
| 409 |
) as instr: |
| 410 |
instr.marker_frequency = 1 |
| 411 |
assert instr.marker_frequency == 0.5 |
| 412 |
|
| 413 |
def test_frequency_counter_mode_enabled(self): |
| 414 |
with expected_protocol( |
| 415 |
HP856Xx, |
| 416 |
[ |
| 417 |
("MKFC OFF", None), |
| 418 |
("MKFC ON", None) |
| 419 |
] |
| 420 |
) as instr: |
| 421 |
instr.frequency_counter_mode_enabled = False |
| 422 |
instr.frequency_counter_mode_enabled = True |
| 423 |
|
| 424 |
def test_frequency_counter_resolution(self): |
| 425 |
with expected_protocol( |
| 426 |
HP856Xx, |
| 427 |
[ |
| 428 |
("MKFCR %d Hz" % 1e3, None), |
| 429 |
("MKFCR?", 1e4) |
| 430 |
] |
| 431 |
) as instr: |
| 432 |
instr.frequency_counter_resolution = 1e3 |
| 433 |
assert instr.frequency_counter_resolution == 1e4 |
| 434 |
|
| 435 |
@pytest.mark.parametrize("all_markers, cmdstring", [(True, " ALL"), (False, "")]) |
| 436 |
def test_deactivate_marker(self, all_markers, cmdstring): |
| 437 |
with expected_protocol( |
| 438 |
HP856Xx, |
| 439 |
[ |
| 440 |
("MKOFF%s" % cmdstring, None), |
| 441 |
] |
| 442 |
) as instr: |
| 443 |
instr.deactivate_marker(all_markers) |
| 444 |
|
| 445 |
@pytest.mark.parametrize("mode", [e for e in PeakSearchMode]) |
| 446 |
def test_minimum_hold(self, mode): |
| 447 |
with expected_protocol( |
| 448 |
HP856Xx, |
| 449 |
[("MKPK " + mode, None)] |
| 450 |
) as instr: |
| 451 |
instr.search_peak(mode) |
| 452 |
|
| 453 |
def test_marker_threshold(self): |
| 454 |
with expected_protocol( |
| 455 |
HP856Xx, |
| 456 |
[ |
| 457 |
("AUNITS?", "DBM"), |
| 458 |
("MKPT %d DBM" % -30, None), |
| 459 |
("MKPT?", -70) |
| 460 |
] |
| 461 |
) as instr: |
| 462 |
instr.marker_threshold = -30 |
| 463 |
assert instr.marker_threshold == -70 |
| 464 |
|
| 465 |
def test_peak_excursion(self): |
| 466 |
with expected_protocol( |
| 467 |
HP856Xx, |
| 468 |
[ |
| 469 |
("MKPX %g DB" % 10.3, None), |
| 470 |
("MKPX?", 10.3) |
| 471 |
] |
| 472 |
) as instr: |
| 473 |
instr.peak_excursion = 10.3 |
| 474 |
assert instr.peak_excursion == 10.3 |
| 475 |
|
| 476 |
def test_marker_time(self): |
| 477 |
with expected_protocol( |
| 478 |
HP856Xx, |
| 479 |
[ |
| 480 |
("MKT %gS" % 10.3, None), |
| 481 |
("MKT?", 10.3) |
| 482 |
] |
| 483 |
) as instr: |
| 484 |
instr.marker_time = 10.3 |
| 485 |
assert instr.marker_time == 10.3 |
| 486 |
|
| 487 |
def test_mixer_level(self): |
| 488 |
with expected_protocol( |
| 489 |
HP856Xx, |
| 490 |
[ |
| 491 |
("ML -30 DB", None), |
| 492 |
("ML?", "-30") |
| 493 |
] |
| 494 |
) as instr: |
| 495 |
instr.mixer_level = -30 |
| 496 |
assert instr.mixer_level == -30 |
| 497 |
|
| 498 |
def test_normalized_reference_level(self): |
| 499 |
with expected_protocol( |
| 500 |
HP856Xx, |
| 501 |
[ |
| 502 |
("AUNITS?", "DBM"), |
| 503 |
("NRL -30 DBM", None), |
| 504 |
("NRL?", "-30") |
| 505 |
] |
| 506 |
) as instr: |
| 507 |
instr.normalized_reference_level = -30 |
| 508 |
assert instr.normalized_reference_level == -30 |
| 509 |
|
| 510 |
def test_normalized_reference_position(self): |
| 511 |
with expected_protocol( |
| 512 |
HP856Xx, |
| 513 |
[ |
| 514 |
("NRPOS 8.000000 DB", None), |
| 515 |
("NRPOS?", "8") |
| 516 |
] |
| 517 |
) as instr: |
| 518 |
instr.normalized_reference_position = 8 |
| 519 |
assert instr.normalized_reference_position == 8 |
| 520 |
|
| 521 |
def test_display_parameters(self): |
| 522 |
with expected_protocol( |
| 523 |
HP856Xx, |
| 524 |
[ |
| 525 |
("OP?", "72,16,712,766") |
| 526 |
] |
| 527 |
) as instr: |
| 528 |
assert instr.display_parameters == (72, 16, 712, 766) |
| 529 |
|
| 530 |
def test_plot(self): |
| 531 |
with expected_protocol( |
| 532 |
HP856Xx, |
| 533 |
[ |
| 534 |
("PLOT 72,16,712,766", None) |
| 535 |
] |
| 536 |
) as instr: |
| 537 |
instr.plot(72, 16, 712, 766) |
| 538 |
|
| 539 |
def test_power_bandwidth(self): |
| 540 |
with expected_protocol( |
| 541 |
HP856Xx, |
| 542 |
[ |
| 543 |
("PWRBW TRA,99.2?", "1.0e3") |
| 544 |
] |
| 545 |
) as instr: |
| 546 |
assert instr.get_power_bandwidth(Trace.A, 99.2) == 1e3 |
| 547 |
|
| 548 |
def test_resolution_bandwidth(self): |
| 549 |
with expected_protocol( |
| 550 |
HP856Xx, |
| 551 |
[ |
| 552 |
("RB 30 Hz", None), |
| 553 |
("RB AUTO", None), |
| 554 |
("RB?", "30") |
| 555 |
] |
| 556 |
) as instr: |
| 557 |
instr.resolution_bandwidth = 30 |
| 558 |
instr.resolution_bandwidth = "AUTO" |
| 559 |
assert instr.resolution_bandwidth == 30 |
| 560 |
|
| 561 |
def test_resolution_bandwidth_to_span_ratio(self): |
| 562 |
with expected_protocol( |
| 563 |
HP856Xx, |
| 564 |
[ |
| 565 |
("RBR 0.014", None), |
| 566 |
("RBR?", "0.014") |
| 567 |
] |
| 568 |
) as instr: |
| 569 |
instr.resolution_bandwidth_to_span_ratio = 0.0140 |
| 570 |
assert instr.resolution_bandwidth_to_span_ratio == 0.0140 |
| 571 |
|
| 572 |
def test_recall_state(self): |
| 573 |
with expected_protocol( |
| 574 |
HP856Xx, |
| 575 |
[ |
| 576 |
("RCLS LAST", None), |
| 577 |
("RCLS 8", None) |
| 578 |
] |
| 579 |
) as instr: |
| 580 |
instr.recall_state("LAST") |
| 581 |
instr.recall_state(8) |
| 582 |
|
| 583 |
def test_recall_trace(self): |
| 584 |
with expected_protocol( |
| 585 |
HP856Xx, |
| 586 |
[ |
| 587 |
("RCLT TRA,6", None) |
| 588 |
] |
| 589 |
) as instr: |
| 590 |
instr.recall_trace(Trace.A, 6) |
| 591 |
|
| 592 |
def test_firmware_revision(self): |
| 593 |
with expected_protocol( |
| 594 |
HP856Xx, |
| 595 |
[ |
| 596 |
("REV?", "901101") |
| 597 |
] |
| 598 |
) as instr: |
| 599 |
assert instr.firmware_revision == datetime.strptime("11-01-1990", '%m-%d-%Y').date() |
| 600 |
|
| 601 |
def test_reference_level(self): |
| 602 |
with expected_protocol( |
| 603 |
HP856Xx, |
| 604 |
[ |
| 605 |
("AUNITS?", "DBM"), |
| 606 |
("RL 10 DBM", None), |
| 607 |
("RL?", "10") |
| 608 |
] |
| 609 |
) as instr: |
| 610 |
instr.reference_level = 10 |
| 611 |
assert instr.reference_level == 10 |
| 612 |
|
| 613 |
def test_reference_level_calibration(self): |
| 614 |
with expected_protocol( |
| 615 |
HP856Xx, |
| 616 |
[ |
| 617 |
("RLCAL 33", None), |
| 618 |
("RLCAL?", "33") |
| 619 |
] |
| 620 |
) as instr: |
| 621 |
instr.reference_level_calibration = 33 |
| 622 |
assert instr.reference_level_calibration == 33 |
| 623 |
|
| 624 |
def test_request_service_conditions(self): |
| 625 |
with expected_protocol( |
| 626 |
HP856Xx, |
| 627 |
[ |
| 628 |
("RQS 48", None), |
| 629 |
("RQS?", "48") |
| 630 |
] |
| 631 |
) as instr: |
| 632 |
instr.request_service_conditions = \ |
| 633 |
StatusRegister.COMMAND_COMPLETE | StatusRegister.ERROR_PRESENT |
| 634 |
assert instr.request_service_conditions == \ |
| 635 |
StatusRegister.COMMAND_COMPLETE | StatusRegister.ERROR_PRESENT |
| 636 |
|
| 637 |
def test_save_state(self): |
| 638 |
with expected_protocol( |
| 639 |
HP856Xx, |
| 640 |
[ |
| 641 |
("SAVES 6", None) |
| 642 |
] |
| 643 |
) as instr: |
| 644 |
instr.save_state(6) |
| 645 |
|
| 646 |
def test_save_trace(self): |
| 647 |
with expected_protocol( |
| 648 |
HP856Xx, |
| 649 |
[ |
| 650 |
("SAVET TRA,6", None) |
| 651 |
] |
| 652 |
) as instr: |
| 653 |
instr.save_trace(Trace.A, 6) |
| 654 |
|
| 655 |
@pytest.mark.parametrize("param", ["FULL", "ZERO"]) |
| 656 |
def test_span_string_params(self, param): |
| 657 |
with expected_protocol( |
| 658 |
HP856Xx, |
| 659 |
[ |
| 660 |
("SP %s" % param, None) |
| 661 |
] |
| 662 |
) as instr: |
| 663 |
instr.span = param |
| 664 |
|
| 665 |
@pytest.mark.parametrize("string_params", ["ON", "OFF"]) |
| 666 |
def test_squelch(self, string_params): |
| 667 |
with expected_protocol( |
| 668 |
HP856Xx, |
| 669 |
[("AUNITS?", "DBM"), |
| 670 |
("SQUELCH 10 DBM", None), |
| 671 |
("SQUELCH %s" % string_params, None), |
| 672 |
("SQUELCH?", "10")] |
| 673 |
) as instr: |
| 674 |
instr.squelch = 10 |
| 675 |
instr.squelch = string_params |
| 676 |
assert instr.squelch == 10 |
| 677 |
|
| 678 |
def test_service_request(self): |
| 679 |
with expected_protocol( |
| 680 |
HP856Xx, |
| 681 |
[ |
| 682 |
("SRQ 48", None) |
| 683 |
] |
| 684 |
) as instr: |
| 685 |
instr.request_service(StatusRegister.COMMAND_COMPLETE | StatusRegister.ERROR_PRESENT) |
| 686 |
|
| 687 |
def test_sweep_time(self): |
| 688 |
with expected_protocol( |
| 689 |
HP856Xx, |
| 690 |
[("ST 10.000 S", None), |
| 691 |
("ST AUTO", None), |
| 692 |
("ST?", "10.00")] |
| 693 |
) as instr: |
| 694 |
instr.sweep_time = 10 |
| 695 |
instr.sweep_time = "AUTO" |
| 696 |
assert instr.sweep_time == 10 |
| 697 |
|
| 698 |
@pytest.mark.parametrize("mode", [e for e in SweepCoupleMode]) |
| 699 |
def test_sweep_couple(self, mode): |
| 700 |
with expected_protocol( |
| 701 |
HP856Xx, |
| 702 |
[("SWPCPL " + mode, None), |
| 703 |
("SWPCPL?", mode)] |
| 704 |
) as instr: |
| 705 |
instr.sweep_couple = mode |
| 706 |
assert instr.sweep_couple == mode |
| 707 |
|
| 708 |
@pytest.mark.parametrize("mode", [e for e in SweepOut]) |
| 709 |
def test_sweep_output(self, mode): |
| 710 |
with expected_protocol( |
| 711 |
HP856Xx, |
| 712 |
[("SWPOUT " + mode, None), |
| 713 |
("SWPOUT?", mode)] |
| 714 |
) as instr: |
| 715 |
instr.sweep_output = mode |
| 716 |
assert instr.sweep_output == mode |
| 717 |
|
| 718 |
@pytest.mark.parametrize("mode", [e for e in TraceDataFormat]) |
| 719 |
def test_trace_data_format(self, mode): |
| 720 |
with expected_protocol( |
| 721 |
HP856Xx, |
| 722 |
[("TDF " + mode, None), |
| 723 |
("TDF?", mode)] |
| 724 |
) as instr: |
| 725 |
instr.trace_data_format = mode |
| 726 |
assert instr.trace_data_format == mode |
| 727 |
|
| 728 |
def test_threshold(self): |
| 729 |
with expected_protocol( |
| 730 |
HP856Xx, |
| 731 |
[("AUNITS?", "DBM"), |
| 732 |
("TH 1.00E+01 DBM", None), |
| 733 |
("TH?", "10.00")] |
| 734 |
) as instr: |
| 735 |
instr.threshold = 10 |
| 736 |
assert instr.threshold == 10 |
| 737 |
|
| 738 |
def test_threshold_enabled(self): |
| 739 |
with expected_protocol( |
| 740 |
HP856Xx, |
| 741 |
[("TH ON", None)] |
| 742 |
) as instr: |
| 743 |
instr.threshold_enabled = True |
| 744 |
|
| 745 |
def test_title(self): |
| 746 |
with expected_protocol( |
| 747 |
HP856Xx, |
| 748 |
[("TITLE@%s@" % "TestString", None)] |
| 749 |
) as instr: |
| 750 |
instr.set_title("TestString") |
| 751 |
|
| 752 |
@pytest.mark.parametrize("mode", [e for e in TriggerMode]) |
| 753 |
def test_trigger_mode(self, mode): |
| 754 |
with expected_protocol( |
| 755 |
HP856Xx, |
| 756 |
[("TM " + mode, None), |
| 757 |
("TM?", mode)] |
| 758 |
) as instr: |
| 759 |
instr.trigger_mode = mode |
| 760 |
assert instr.trigger_mode == mode |
| 761 |
|
| 762 |
@pytest.mark.parametrize("function, cmd", [ |
| 763 |
("get_trace_data_a", "TRA"), |
| 764 |
("get_trace_data_b", "TRB") |
| 765 |
]) |
| 766 |
def test_trace_data(self, function, cmd): |
| 767 |
data = [48, 61, 31, 73, 90, 82, 56, 48, 87, 78, 59, 103, 78, 76, 92, 52, 57, 72, 48, 82, |
| 768 |
108, 63, 52, 79, 44, 88, 95, 99, 74, 79, 63, 100, 51, 85, 96, 69, 97, 50, 105, 94, |
| 769 |
58, 98, 92, 92, 96, 59, 63, 34, 81, 56, 50, 94, 74, 61, 40, 48, 72, 69, 86, 114, 59, |
| 770 |
70, 83, 53, 67, 111, 110, 99, 112, 72, 100, 44, 80, 81, 65, 34, 56, 62, 55, 78, 86, |
| 771 |
68, 59, 66, 91, 91, 91, 63, 83, 90, 71, 94, 91, 46, 69, 70, 99, 52, 86, 63, 88, 75, |
| 772 |
55, 80, 97, 31, 40, 81, 92, 75, 30, 113, 83, 64, 98, 49, 51, 99, 102, 54, 57, 38, |
| 773 |
67, 84, 75, 59, 75, 78, 93, 47, 89, 107, 77, 42, 63, 98, 45, 81, 81, 98, 39, 39, 44, |
| 774 |
89, 72, 77, 99, 104, 84, 61, 105, 76, 80, 29, 66, 45, 88, 98, 54, 108, 89, 88, 54, |
| 775 |
79, 91, 38, 85, 98, 42, 66, 41, 94, 55, 49, 94, 57, 67, 69, 75, 96, 87, 75, 97, 101, |
| 776 |
52, 85, 76, 47, 53, 108, 61, 82, 61, 61, 64, 56, 88, 62, 54, 91, 54, 38, 37, 91, 65, |
| 777 |
60, 60, 70, 102, 97, 71, 93, 85, 92, 52, 85, 61, 77, 63, 96, 71, 40, 51, 65, 69, 78, |
| 778 |
65, 81, 56, 63, 68, 59, 43, 120, 77, 58, 57, 79, 90, 62, 47, 50, 76, 77, 87, 38, |
| 779 |
102, 72, 66, 74, 84, 73, 70, 64, 88, 86, 73, 83, 82, 98, 98, 93, 100, 114, 111, 116, |
| 780 |
121, 127, 132, 139, 148, 153, 160, 167, 174, 182, 190, 197, 205, 215, 224, 233, 244, |
| 781 |
255, 265, 275, 287, 300, 313, 325, 339, 354, 368, 383, 397, 414, 429, 443, 455, 466, |
| 782 |
472, 475, 474, 468, 458, 447, 434, 417, 402, 388, 373, 357, 343, 329, 316, 303, 291, |
| 783 |
279, 269, 259, 248, 239, 230, 220, 212, 204, 196, 189, 181, 175, 168, 162, 154, 147, |
| 784 |
143, 136, 128, 124, 120, 113, 104, 104, 98, 92, 86, 115, 96, 86, 112, 77, 92, 88, |
| 785 |
82, 79, 104, 49, 97, 73, 58, 68, 80, 84, 68, 78, 46, 74, 88, 81, 110, 80, 82, 89, |
| 786 |
83, 50, 62, 64, 97, 58, 48, 66, 47, 53, 38, 108, 94, 88, 116, 66, 103, 85, 41, 63, |
| 787 |
81, 58, 118, 50, 110, 93, 52, 43, 74, 42, 89, 71, 66, 50, 73, 89, 119, 86, 57, 100, |
| 788 |
55, 79, 71, 75, 90, 47, 86, 79, 110, 99, 87, 79, 87, 63, 76, 73, 62, 98, 107, 89, |
| 789 |
80, 90, 71, 44, 46, 50, 41, 66, 109, 47, 97, 70, 77, 75, 103, 120, 69, 67, 92, 90, |
| 790 |
81, 54, 95, 97, 86, 83, 71, 48, 53, 95, 62, 51, 85, 59, 71, 90, 63, 69, 108, 72, 75, |
| 791 |
25, 116, 60, 51, 90, 84, 74, 43, 88, 83, 60, 99, 86, 61, 72, 82, 77, 80, 64, 84, |
| 792 |
101, 108, 57, 107, 92, 77, 62, 81, 74, 69, 50, 46, 56, 51, 79, 49, 34, 101, 76, 55, |
| 793 |
111, 103, 92, 109, 123, 74, 50, 68, 56, 79, 43, 55, 43, 111, 46, 76, 103, 85, 70, |
| 794 |
53, 70, 88, 54, 117, 78, 85, 57, 72, 88, 89, 58, 98, 55, 68, 77, 71, 56, 75, 44, 53, |
| 795 |
76, 95, 81, 48, 40, 84, 38, 84, 110, 82, 67, 114, 79, 40, 52, 102, 103, 85, 80, 108, |
| 796 |
86, 40, 123, 66, 86, 93, 83, 78, 42, 74, 33, 79, 55, 67, 111, 77, 61, 89, 58, 89, |
| 797 |
103, 77, 77, 62, 57, 61, 54, 30] |
| 798 |
|
| 799 |
expected_data = [-82.0, -79.83, -84.83, -77.83, -75.0, -76.33, -80.67, -82.0, -75.5, -77.0, |
| 800 |
-80.17, -72.83, -77.0, -77.33, -74.67, -81.33, -80.5, -78.0, -82.0, -76.33, |
| 801 |
-72.0, -79.5, -81.33, -76.83, -82.67, -75.33, -74.17, -73.5, -77.67, |
| 802 |
-76.83, -79.5, -73.33, -81.5, -75.83, -74.0, -78.5, -73.83, -81.67, -72.5, |
| 803 |
-74.33, -80.33, -73.67, -74.67, -74.67, -74.0, -80.17, -79.5, -84.33, |
| 804 |
-76.5, -80.67, -81.67, -74.33, -77.67, -79.83, -83.33, -82.0, -78.0, -78.5, |
| 805 |
-75.67, -71.0, -80.17, -78.33, -76.17, -81.17, -78.83, -71.5, -71.67, |
| 806 |
-73.5, -71.33, -78.0, -73.33, -82.67, -76.67, -76.5, -79.17, -84.33, |
| 807 |
-80.67, -79.67, -80.83, -77.0, -75.67, -78.67, -80.17, -79.0, -74.83, |
| 808 |
-74.83, -74.83, -79.5, -76.17, -75.0, -78.17, -74.33, -74.83, -82.33, |
| 809 |
-78.5, -78.33, -73.5, -81.33, -75.67, -79.5, -75.33, -77.5, -80.83, -76.67, |
| 810 |
-73.83, -84.83, -83.33, -76.5, -74.67, -77.5, -85.0, -71.17, -76.17, |
| 811 |
-79.33, -73.67, -81.83, -81.5, -73.5, -73.0, -81.0, -80.5, -83.67, -78.83, |
| 812 |
-76.0, -77.5, -80.17, -77.5, -77.0, -74.5, -82.17, -75.17, -72.17, -77.17, |
| 813 |
-83.0, -79.5, -73.67, -82.5, -76.5, -76.5, -73.67, -83.5, -83.5, -82.67, |
| 814 |
-75.17, -78.0, -77.17, -73.5, -72.67, -76.0, -79.83, -72.5, -77.33, -76.67, |
| 815 |
-85.17, -79.0, -82.5, -75.33, -73.67, -81.0, -72.0, -75.17, -75.33, -81.0, |
| 816 |
-76.83, -74.83, -83.67, -75.83, -73.67, -83.0, -79.0, -83.17, -74.33, |
| 817 |
-80.83, -81.83, -74.33, -80.5, -78.83, -78.5, -77.5, -74.0, -75.5, -77.5, |
| 818 |
-73.83, -73.17, -81.33, -75.83, -77.33, -82.17, -81.17, -72.0, -79.83, |
| 819 |
-76.33, -79.83, -79.83, -79.33, -80.67, -75.33, -79.67, -81.0, -74.83, |
| 820 |
-81.0, -83.67, -83.83, -74.83, -79.17, -80.0, -80.0, -78.33, -73.0, -73.83, |
| 821 |
-78.17, -74.5, -75.83, -74.67, -81.33, -75.83, -79.83, -77.17, -79.5, |
| 822 |
-74.0, -78.17, -83.33, -81.5, -79.17, -78.5, -77.0, -79.17, -76.5, -80.67, |
| 823 |
-79.5, -78.67, -80.17, -82.83, -70.0, -77.17, -80.33, -80.5, -76.83, -75.0, |
| 824 |
-79.67, -82.17, -81.67, -77.33, -77.17, -75.5, -83.67, -73.0, -78.0, -79.0, |
| 825 |
-77.67, -76.0, -77.83, -78.33, -79.33, -75.33, -75.67, -77.83, -76.17, |
| 826 |
-76.33, -73.67, -73.67, -74.5, -73.33, -71.0, -71.5, -70.67, -69.83, |
| 827 |
-68.83, -68.0, -66.83, -65.33, -64.5, -63.33, -62.17, -61.0, -59.67, |
| 828 |
-58.33, -57.17, -55.83, -54.17, -52.67, -51.17, -49.33, -47.5, -45.83, |
| 829 |
-44.17, -42.17, -40.0, -37.83, -35.83, -33.5, -31.0, -28.67, -26.17, |
| 830 |
-23.83, -21.0, -18.5, -16.17, -14.17, -12.33, -11.33, -10.83, -11.0, -12.0, |
| 831 |
-13.67, -15.5, -17.67, -20.5, -23.0, -25.33, -27.83, -30.5, -32.83, -35.17, |
| 832 |
-37.33, -39.5, -41.5, -43.5, -45.17, -46.83, -48.67, -50.17, -51.67, |
| 833 |
-53.33, -54.67, -56.0, -57.33, -58.5, -59.83, -60.83, -62.0, -63.0, -64.33, |
| 834 |
-65.5, -66.17, -67.33, -68.67, -69.33, -70.0, -71.17, -72.67, -72.67, |
| 835 |
-73.67, -74.67, -75.67, -70.83, -74.0, -75.67, -71.33, -77.17, -74.67, |
| 836 |
-75.33, -76.33, -76.83, -72.67, -81.83, -73.83, -77.83, -80.33, -78.67, |
| 837 |
-76.67, -76.0, -78.67, -77.0, -82.33, -77.67, -75.33, -76.5, -71.67, |
| 838 |
-76.67, -76.33, -75.17, -76.17, -81.67, -79.67, -79.33, -73.83, -80.33, |
| 839 |
-82.0, -79.0, -82.17, -81.17, -83.67, -72.0, -74.33, -75.33, -70.67, -79.0, |
| 840 |
-72.83, -75.83, -83.17, -79.5, -76.5, -80.33, -70.33, -81.67, -71.67, |
| 841 |
-74.5, -81.33, -82.83, -77.67, -83.0, -75.17, -78.17, -79.0, -81.67, |
| 842 |
-77.83, -75.17, -70.17, -75.67, -80.5, -73.33, -80.83, -76.83, -78.17, |
| 843 |
-77.5, -75.0, -82.17, -75.67, -76.83, -71.67, -73.5, -75.5, -76.83, -75.5, |
| 844 |
-79.5, -77.33, -77.83, -79.67, -73.67, -72.17, -75.17, -76.67, -75.0, |
| 845 |
-78.17, -82.67, -82.33, -81.67, -83.17, -79.0, -71.83, -82.17, -73.83, |
| 846 |
-78.33, -77.17, -77.5, -72.83, -70.0, -78.5, -78.83, -74.67, -75.0, -76.5, |
| 847 |
-81.0, -74.17, -73.83, -75.67, -76.17, -78.17, -82.0, -81.17, -74.17, |
| 848 |
-79.67, -81.5, -75.83, -80.17, -78.17, -75.0, -79.5, -78.5, -72.0, -78.0, |
| 849 |
-77.5, -85.83, -70.67, -80.0, -81.5, -75.0, -76.0, -77.67, -82.83, -75.33, |
| 850 |
-76.17, -80.0, -73.5, -75.67, -79.83, -78.0, -76.33, -77.17, -76.67, |
| 851 |
-79.33, -76.0, -73.17, -72.0, -80.5, -72.17, -74.67, -77.17, -79.67, -76.5, |
| 852 |
-77.67, -78.5, -81.67, -82.33, -80.67, -81.5, -76.83, -81.83, -84.33, |
| 853 |
-73.17, -77.33, -80.83, -71.5, -72.83, -74.67, -71.83, -69.5, -77.67, |
| 854 |
-81.67, -78.67, -80.67, -76.83, -82.83, -80.83, -82.83, -71.5, -82.33, |
| 855 |
-77.33, -72.83, -75.83, -78.33, -81.17, -78.33, -75.33, -81.0, -70.5, |
| 856 |
-77.0, -75.83, -80.5, -78.0, -75.33, -75.17, -80.33, -73.67, -80.83, |
| 857 |
-78.67, -77.17, -78.17, -80.67, -77.5, -82.67, -81.17, -77.33, -74.17, |
| 858 |
-76.5, -82.0, -83.33, -76.0, -83.67, -76.0, -71.67, -76.33, -78.83, -71.0, |
| 859 |
-76.83, -83.33, -81.33, -73.0, -72.83, -75.83, -76.67, -72.0, -75.67, |
| 860 |
-83.33, -69.5, -79.0, -75.67, -74.5, -76.17, -77.0, -83.0, -77.67, -84.5, |
| 861 |
-76.83, -80.83, -78.83, -71.5, -77.17, -79.83, -75.17, -80.33, -75.17, |
| 862 |
-72.83, -77.17, -77.17, -79.67, -80.5, -79.83, -81.0, -85.0] |
| 863 |
with expected_protocol( |
| 864 |
HP856Xx, |
| 865 |
[ |
| 866 |
("TDF M", None), |
| 867 |
("AUNITS?", "DBM"), |
| 868 |
("RL?", "10.0"), |
| 869 |
("LG?", "10.0"), |
| 870 |
(cmd + "?", ','.join([str(i) for i in data])) |
| 871 |
] |
| 872 |
) as instr: |
| 873 |
assert getattr(instr, function)() == expected_data |
| 874 |
|
| 875 |
def test_fft_trace_window(self): |
| 876 |
with expected_protocol( |
| 877 |
HP856Xx, |
| 878 |
[("TWNDOW TRA,FLATTOP", None)] |
| 879 |
) as instr: |
| 880 |
instr.create_fft_trace_window(Trace.A, WindowType.Flattop) |
| 881 |
|
| 882 |
@pytest.mark.parametrize("param", [("ON", True), ("OFF", False)]) |
| 883 |
def test_video_average_enabled(self, param): |
| 884 |
str_param, boolean = param |
| 885 |
with expected_protocol( |
| 886 |
HP856Xx, |
| 887 |
[("VAVG " + str_param, None)] |
| 888 |
) as instr: |
| 889 |
instr.video_average_enabled = boolean |
| 890 |
|
| 891 |
def test_video_bandwidth(self): |
| 892 |
with expected_protocol( |
| 893 |
HP856Xx, |
| 894 |
[("VB 70 Hz", None), |
| 895 |
("VB?", "70")], |
| 896 |
) as instr: |
| 897 |
instr.video_bandwidth = 70 |
| 898 |
assert instr.video_bandwidth == 70 |
| 899 |
|
| 900 |
def test_video_bandwidth_string_parameters(self): |
| 901 |
with expected_protocol( |
| 902 |
HP856Xx, |
| 903 |
[("VB AUTO", None), |
| 904 |
("VB?", "20"), ], |
| 905 |
) as instr: |
| 906 |
instr.video_bandwidth = "AUTO" |
| 907 |
assert instr.video_bandwidth == 20 |
| 908 |
|
| 909 |
def test_video_bandwidth_to_resolution_bandwidth(self): |
| 910 |
with expected_protocol( |
| 911 |
HP856Xx, |
| 912 |
[("VBR 0.005", None), |
| 913 |
("VBR?", "0.005")], |
| 914 |
) as instr: |
| 915 |
instr.video_bandwidth_to_resolution_bandwidth = 0.005 |
| 916 |
assert instr.video_bandwidth_to_resolution_bandwidth == 0.005 |
| 917 |
|
| 918 |
@pytest.mark.parametrize("trace", [e for e in Trace]) |
| 919 |
def test_view_trace(self, trace): |
| 920 |
with expected_protocol( |
| 921 |
HP856Xx, |
| 922 |
[("VIEW " + trace, None)] |
| 923 |
) as instr: |
| 924 |
instr.view_trace(trace) |
| 925 |
|
| 926 |
def test_video_trigger_level(self): |
| 927 |
with expected_protocol( |
| 928 |
HP856Xx, |
| 929 |
[("AUNITS?", "DBM"), |
| 930 |
("VTL -200.780 DBM", None), |
| 931 |
("VTL?", "0.005")], |
| 932 |
) as instr: |
| 933 |
instr.video_trigger_level = -200.78 |
| 934 |
assert instr.video_trigger_level == 0.005 |
| 935 |
|
| 936 |
|
| 937 |
class TestHP8560A: |
| 938 |
|
| 939 |
@pytest.mark.parametrize("mode", [e for e in SourceLevelingControlMode]) |
| 940 |
def test_source_leveling_control(self, mode): |
| 941 |
with expected_protocol( |
| 942 |
HP8560A, |
| 943 |
[("SRCALC " + mode, None), |
| 944 |
("SRCALC?", mode)] |
| 945 |
) as instr: |
| 946 |
instr.source_leveling_control = mode |
| 947 |
assert instr.source_leveling_control == mode |
| 948 |
|
| 949 |
def test_tracking_adjust_coarse(self): |
| 950 |
with expected_protocol( |
| 951 |
HP8560A, |
| 952 |
[("SRCCRSTK 10", None), |
| 953 |
("SRCCRSTK?", "10")] |
| 954 |
) as instr: |
| 955 |
instr.tracking_adjust_coarse = 10 |
| 956 |
assert instr.tracking_adjust_coarse == 10 |
| 957 |
|
| 958 |
def test_tracking_adjust_fine(self): |
| 959 |
with expected_protocol( |
| 960 |
HP8560A, |
| 961 |
[("SRCFINTK 10", None), |
| 962 |
("SRCFINTK?", "10")] |
| 963 |
) as instr: |
| 964 |
instr.tracking_adjust_fine = 10 |
| 965 |
assert instr.tracking_adjust_fine == 10 |
| 966 |
|
| 967 |
def test_source_power_offset(self): |
| 968 |
with expected_protocol( |
| 969 |
HP8560A, |
| 970 |
[("AUNITS?", "DBM"), |
| 971 |
("SRCPOFS 10 DBM", None), |
| 972 |
("SRCPOFS?", "10")] |
| 973 |
) as instr: |
| 974 |
instr.source_power_offset = 10 |
| 975 |
assert instr.source_power_offset == 10 |
| 976 |
|
| 977 |
def test_source_power_step(self): |
| 978 |
with expected_protocol( |
| 979 |
HP8560A, |
| 980 |
[("SRCPSTP 10.10 DB", None), |
| 981 |
("SRCPSTP?", "10.10")] |
| 982 |
) as instr: |
| 983 |
instr.source_power_step = 10.1 |
| 984 |
assert instr.source_power_step == 10.1 |
| 985 |
|
| 986 |
def test_source_power_sweep(self): |
| 987 |
with expected_protocol( |
| 988 |
HP8560A, |
| 989 |
[("SRCPSWP 10.00 DB", None), |
| 990 |
("SRCPSWP?", "10.00")] |
| 991 |
) as instr: |
| 992 |
instr.source_power_sweep = 10 |
| 993 |
assert instr.source_power_sweep == 10 |
| 994 |
|
| 995 |
def test_source_power_sweep_enabled(self): |
| 996 |
with expected_protocol( |
| 997 |
HP8560A, |
| 998 |
[("SRCPSWP OFF", None)] |
| 999 |
) as instr: |
| 1000 |
instr.source_power_sweep_enabled = False |
| 1001 |
|
| 1002 |
def test_source_power(self): |
| 1003 |
with expected_protocol( |
| 1004 |
HP8560A, |
| 1005 |
[("AUNITS?", "DBM"), |
| 1006 |
("SRCPWR 2.00 DBM", None), |
| 1007 |
("SRCPWR ON", None), |
| 1008 |
("SRCPWR?", "2.00")] |
| 1009 |
) as instr: |
| 1010 |
instr.source_power = 2.0 |
| 1011 |
instr.source_power = "ON" |
| 1012 |
assert instr.source_power == 2.0 |
| 1013 |
|
| 1014 |
def test_source_peak_tracking(self): |
| 1015 |
with expected_protocol( |
| 1016 |
HP8560A, |
| 1017 |
[("SRCTKPK", None)] |
| 1018 |
) as instr: |
| 1019 |
instr.activate_source_peak_tracking() |
| 1020 |
|
| 1021 |
|
| 1022 |
class TestHP8561B: |
| 1023 |
|
| 1024 |
@pytest.mark.parametrize("mixer_mode", [e for e in MixerMode]) |
| 1025 |
def test_external_mixer(self, mixer_mode): |
| 1026 |
with expected_protocol( |
| 1027 |
HP8561B, |
| 1028 |
[("MXRMODE " + mixer_mode, None), |
| 1029 |
("MXRMODE?", mixer_mode)] |
| 1030 |
) as instr: |
| 1031 |
instr.mixer_mode = mixer_mode |
| 1032 |
assert instr.mixer_mode == mixer_mode |
| 1033 |
|
| 1034 |
def test_conversion_loss(self): |
| 1035 |
with expected_protocol( |
| 1036 |
HP8561B, |
| 1037 |
[("CNVLOSS 10.2 DB", None), |
| 1038 |
("CNVLOSS?", "10.3")] |
| 1039 |
) as instr: |
| 1040 |
instr.conversion_loss = 10.2 |
| 1041 |
assert instr.conversion_loss == 10.3 |
| 1042 |
|
| 1043 |
def test_fullband(self): |
| 1044 |
with expected_protocol( |
| 1045 |
HP8561B, |
| 1046 |
[("FULLBAND K", None)] |
| 1047 |
) as instr: |
| 1048 |
instr.set_fullband("K") |
| 1049 |
|
| 1050 |
def test_fullband_exceptions(self): |
| 1051 |
with expected_protocol( |
| 1052 |
HP8561B, |
| 1053 |
[] |
| 1054 |
) as instr: |
| 1055 |
with pytest.raises(TypeError): |
| 1056 |
instr.set_fullband(1) |
| 1057 |
|
| 1058 |
with pytest.raises(ValueError): |
| 1059 |
instr.set_fullband("Z") |
| 1060 |
|
| 1061 |
def test_harmonic_number_lock(self): |
| 1062 |
with expected_protocol( |
| 1063 |
HP8561B, |
| 1064 |
[("HNLOCK 10", None), |
| 1065 |
("HNLOCK?", "10")] |
| 1066 |
) as instr: |
| 1067 |
instr.harmonic_number_lock = 10 |
| 1068 |
assert instr.harmonic_number_lock == 10 |
| 1069 |
|
| 1070 |
@pytest.mark.parametrize("params", [("ON", True), ("OFF", False)]) |
| 1071 |
def test_harmonic_number_lock_enabled(self, params): |
| 1072 |
str_param, boolean = params |
| 1073 |
with expected_protocol( |
| 1074 |
HP8561B, |
| 1075 |
[("HNLOCK %s" % str_param, None)] |
| 1076 |
) as instr: |
| 1077 |
instr.harmonic_number_lock_enabled = boolean |
| 1078 |
|
| 1079 |
@pytest.mark.parametrize( |
| 1080 |
"function, command", |
| 1081 |
[ |
| 1082 |
("unlock_harmonic_number", "HUNLK"), |
| 1083 |
("set_signal_identification_to_center_frequency", "IDCF"), |
| 1084 |
("peak_preselector", "PP") |
| 1085 |
] |
| 1086 |
) |
| 1087 |
def test_primitive_commands(self, command, function): |
| 1088 |
""" |
| 1089 |
Tests primitive commands which have no parameter or query derivat |
| 1090 |
""" |
| 1091 |
with expected_protocol( |
| 1092 |
HP8561B, |
| 1093 |
[(command, None)] |
| 1094 |
) as instr: |
| 1095 |
getattr(instr, function)() |
| 1096 |
|
| 1097 |
def test_signal_identification_frequency(self): |
| 1098 |
with expected_protocol( |
| 1099 |
HP8561B, |
| 1100 |
[("IDFREQ?", 2.7897e9)] |
| 1101 |
) as instr: |
| 1102 |
assert instr.signal_identification_frequency == 2.7897e9 |
| 1103 |
|
| 1104 |
def test_mixer_bias(self): |
| 1105 |
with expected_protocol( |
| 1106 |
HP8561B, |
| 1107 |
[("MBIAS -9.900 MA", None), |
| 1108 |
("MBIAS?", "5.5")] |
| 1109 |
) as instr: |
| 1110 |
instr.mixer_bias = -9.9 |
| 1111 |
assert instr.mixer_bias == 5.5 |
| 1112 |
|
| 1113 |
@pytest.mark.parametrize("params", [("ON", True), ("OFF", False)]) |
| 1114 |
def test_mixer_bias_enabled(self, params): |
| 1115 |
str_param, boolean = params |
| 1116 |
with expected_protocol( |
| 1117 |
HP8561B, |
| 1118 |
[("MBIAS %s" % str_param, None)] |
| 1119 |
) as instr: |
| 1120 |
instr.mixer_bias_enabled = boolean |
| 1121 |
|
| 1122 |
def test_preselector_dac_number(self): |
| 1123 |
with expected_protocol( |
| 1124 |
HP8561B, |
| 1125 |
[("PSDAC 10", None), |
| 1126 |
("PSDAC?", "10")] |
| 1127 |
) as instr: |
| 1128 |
instr.preselector_dac_number = 10 |
| 1129 |
assert instr.preselector_dac_number == 10 |
| 1130 |
|
| 1131 |
def test_signal_identification(self): |
| 1132 |
with expected_protocol( |
| 1133 |
HP8561B, |
| 1134 |
[("SIGID AUTO", None), |
| 1135 |
("SIGID?", "1")] |
| 1136 |
) as instr: |
| 1137 |
instr.signal_identification = "AUTO" |
| 1138 |
assert instr.signal_identification is True |