| 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 logging |
| 26 |
from math import log10 |
| 27 |
from enum import Enum, IntFlag |
| 28 |
from datetime import datetime |
| 29 |
|
| 30 |
import numpy as np |
| 31 |
|
| 32 |
from pymeasure.instruments import Instrument |
| 33 |
from pymeasure.instruments.validators import strict_discrete_set, truncated_discrete_set, \ |
| 34 |
joined_validators, strict_range |
| 35 |
|
| 36 |
log = logging.getLogger(__name__) |
| 37 |
log.addHandler(logging.NullHandler()) |
| 38 |
|
| 39 |
|
| 40 |
try: |
| 41 |
from enum import StrEnum |
| 42 |
except ImportError: |
| 43 |
class StrEnum(str, Enum): |
| 44 |
"""Until StrEnum is broadly available / pymeasure relies on python <= |
| 45 |
3.10.x.""" |
| 46 |
|
| 47 |
def __str__(self): |
| 48 |
return self.value |
| 49 |
|
| 50 |
|
| 51 |
class WindowType(StrEnum): |
| 52 |
"""Enumeration to represent the different window mode for FFT functions""" |
| 53 |
|
| 54 |
#: Flattop provides optimum amplitude accuracy |
| 55 |
Flattop = "FLATTOP" |
| 56 |
|
| 57 |
#: Hanning provides an amplitude accuracy/frequency resolution compromise |
| 58 |
Hanning = "HANNING" |
| 59 |
|
| 60 |
#: Uniform provides equal weighting of the time record for measuring transients. |
| 61 |
Uniform = "UNIFORM" |
| 62 |
|
| 63 |
|
| 64 |
class StatusRegister(IntFlag): |
| 65 |
"""Enumeration to represent the Status Register.""" |
| 66 |
|
| 67 |
#: Request Service |
| 68 |
RQS = 64 |
| 69 |
|
| 70 |
#: Set when error present |
| 71 |
ERROR_PRESENT = 32 |
| 72 |
|
| 73 |
#: Any command is completed |
| 74 |
COMMAND_COMPLETE = 16 |
| 75 |
|
| 76 |
#: Unused but sometimes set |
| 77 |
NA = 8 |
| 78 |
|
| 79 |
#: Set when any sweep is completed |
| 80 |
END_OF_SWEEP = 4 |
| 81 |
|
| 82 |
#: Set when display message appears |
| 83 |
MESSAGE = 2 |
| 84 |
|
| 85 |
#: Trigger is activated |
| 86 |
TRIGGER = 1 |
| 87 |
|
| 88 |
#: No Interrupts can interrupt the program sequence |
| 89 |
NONE = 0 |
| 90 |
|
| 91 |
|
| 92 |
class Trace(StrEnum): |
| 93 |
"""Enumeration to represent either Trace A or Trace B.""" |
| 94 |
|
| 95 |
#: Trace A |
| 96 |
A = "TRA" |
| 97 |
|
| 98 |
#: Trace B |
| 99 |
B = "TRB" |
| 100 |
|
| 101 |
|
| 102 |
class SweepCoupleMode(StrEnum): |
| 103 |
"""Enumeration.""" |
| 104 |
|
| 105 |
#: Stimulus Response |
| 106 |
SpectrumAnalyzer = "SA" |
| 107 |
|
| 108 |
#: Spectrum Analyeze |
| 109 |
StimulusResponse = "SR" |
| 110 |
|
| 111 |
|
| 112 |
class SweepOut(StrEnum): |
| 113 |
"""Enumeration.""" |
| 114 |
|
| 115 |
#: 0 - 10V Ramp |
| 116 |
Ramp = "RAMP" |
| 117 |
|
| 118 |
#: DC Ramp 0.5V / GHz |
| 119 |
Fav = "FAV" |
| 120 |
|
| 121 |
|
| 122 |
class MixerMode(StrEnum): |
| 123 |
"""Enumeration to represent the Mixer Mode of the HP8561B.""" |
| 124 |
|
| 125 |
#: Mixer Mode Internal |
| 126 |
Internal = "INT" |
| 127 |
|
| 128 |
#: Mixer Mode External |
| 129 |
External = "EXT" |
| 130 |
|
| 131 |
|
| 132 |
class SourceLevelingControlMode(StrEnum): |
| 133 |
"""Enumeration to represent the Source Leveling Control Mode of the |
| 134 |
HP8560A.""" |
| 135 |
|
| 136 |
#: Source Leveling Control Mode Internal |
| 137 |
Internal = "INT" |
| 138 |
|
| 139 |
#: Source Leveling Control Mode External |
| 140 |
External = "EXT" |
| 141 |
|
| 142 |
|
| 143 |
class PeakSearchMode(StrEnum): |
| 144 |
"""Enumeration to represent the Marker Peak Search Mode.""" |
| 145 |
|
| 146 |
#: Place marker to the highest value on the trace |
| 147 |
High = "HI" |
| 148 |
|
| 149 |
#: Place marker to the next highest value on the trace |
| 150 |
NextHigh = "NH" |
| 151 |
|
| 152 |
#: Place marker to the next peak to the right |
| 153 |
NextRight = "NR" |
| 154 |
|
| 155 |
#: Place marker to the next peak to the left |
| 156 |
NextLeft = "NL" |
| 157 |
|
| 158 |
|
| 159 |
class CouplingMode(StrEnum): |
| 160 |
"""Enumeration to represent the Coupling Mode.""" |
| 161 |
|
| 162 |
#: AC |
| 163 |
AC = "AC" |
| 164 |
|
| 165 |
#: DC |
| 166 |
DC = "DC" |
| 167 |
|
| 168 |
|
| 169 |
class DemodulationMode(StrEnum): |
| 170 |
"""Enumeration to represent the Demodulation Mode.""" |
| 171 |
|
| 172 |
#: Amplitude Modulation |
| 173 |
Amplitude = "AM" |
| 174 |
|
| 175 |
#: Frequency Modulation |
| 176 |
Frequency = "FM" |
| 177 |
|
| 178 |
#: Demodulation Off |
| 179 |
Off = "OFF" |
| 180 |
|
| 181 |
|
| 182 |
class TriggerMode(StrEnum): |
| 183 |
"""Enumeration to represent the different trigger modes""" |
| 184 |
|
| 185 |
#: External Mode |
| 186 |
External = "EXT" |
| 187 |
|
| 188 |
#: Free Running |
| 189 |
Free = "FREE" |
| 190 |
|
| 191 |
#: Line Mode |
| 192 |
Line = "LINE" |
| 193 |
|
| 194 |
#: Video Mode |
| 195 |
Video = "VID" |
| 196 |
|
| 197 |
|
| 198 |
class TraceDataFormat(StrEnum): |
| 199 |
"""Enumeration to represent the different trace data formats.""" |
| 200 |
|
| 201 |
#: A-Block format |
| 202 |
A_BLOCK = "A" |
| 203 |
|
| 204 |
#: Binary format |
| 205 |
BINARY = "B" |
| 206 |
|
| 207 |
#: I-Block format |
| 208 |
I_BLOCK = "I" |
| 209 |
|
| 210 |
#: ASCII format |
| 211 |
ASCII = "M" |
| 212 |
|
| 213 |
#: Real numbers format like are in Hz, volts, watts, dBm, dBmV, dBuV, dBV, or seconds. |
| 214 |
REAL = "P" |
| 215 |
|
| 216 |
|
| 217 |
class FrequencyReference(StrEnum): |
| 218 |
"""Enumeration to represent the frequency reference source.""" |
| 219 |
|
| 220 |
#: Internal Frequency Reference |
| 221 |
Internal = "INT" |
| 222 |
|
| 223 |
#: External Frequency Standard |
| 224 |
External = "EXT" |
| 225 |
|
| 226 |
|
| 227 |
class DetectionModes(StrEnum): |
| 228 |
"""Enumeration to represent the Detection Modes.""" |
| 229 |
|
| 230 |
#: Negative Peak Detection |
| 231 |
NegativePeak = "NEG" |
| 232 |
|
| 233 |
#: Normal Peak Detection |
| 234 |
Normal = "NRM" |
| 235 |
|
| 236 |
#: Positive Peak Detection |
| 237 |
PositivePeak = "POS" |
| 238 |
|
| 239 |
#: Sampl Mode Detection |
| 240 |
Sample = "SMP" |
| 241 |
|
| 242 |
|
| 243 |
class AmplitudeUnits(StrEnum): |
| 244 |
"""Enumeration to represent the amplitude units.""" |
| 245 |
|
| 246 |
#: DB over millit Watt |
| 247 |
DBM = "DBM" |
| 248 |
|
| 249 |
#: DB over milli Volt |
| 250 |
DBMV = "DBMV" |
| 251 |
|
| 252 |
#: DB over micro Volt |
| 253 |
DBUV = "DBUV" |
| 254 |
|
| 255 |
#: Volts |
| 256 |
V = "V" |
| 257 |
|
| 258 |
#: Watt |
| 259 |
W = "W" |
| 260 |
|
| 261 |
#: Automatic Unit (Usually derives to 'DBM') |
| 262 |
AUTO = "AUTO" |
| 263 |
|
| 264 |
#: Manual Mode |
| 265 |
MANUAL = "MAN" |
| 266 |
|
| 267 |
|
| 268 |
class ErrorCode: |
| 269 |
""" |
| 270 |
Class to decode error codes from the spectrum analyzer. |
| 271 |
""" |
| 272 |
__error_code_list = { |
| 273 |
0: ("NO ERR", "No Error at all"), |
| 274 |
100: ("PWRON", "Power-on state is invalid; default state is loaded"), |
| 275 |
101: ("NO STATE", "State to be RECALLed not valid or not SAVEd"), |
| 276 |
106: ("ABORTED!", "Current operation is aborted; HP-IB parser reset"), |
| 277 |
107: ("HELLO ??", "No HP-IB listener is present"), |
| 278 |
108: ("TIME OUT", "Analyzer timed out when acting as controller"), |
| 279 |
109: ("CtrlFail", "Analyzer unable to take control of the bus"), |
| 280 |
110: ("NOT CTRL", "Analyzer is not system controller"), |
| 281 |
111: ("# ARGMTS", "Command does not have enough arguments"), |
| 282 |
112: ("??CMD??", "Unrecognized command"), |
| 283 |
113: ("FREQ NQ!", "Command cannot have frequency units"), |
| 284 |
114: ("TIME NOG!", "Command cannot have time units"), |
| 285 |
115: ("AMPL NO!", "Command cannot have amplitude units"), |
| 286 |
116: ("PUNITS??", "Unrecognizable units"), |
| 287 |
117: ("NOP NUM", "Command cannot have numeric units"), |
| 288 |
118: ("NOP EP", "Enable parameter cannot be used"), |
| 289 |
119: ("NOP UPDN", "UP/DN are not valid arguments for command"), |
| 290 |
120: ("NOP ONOF", "ON/OFF are not valid arguments for command"), |
| 291 |
121: ("NOP ARG", "AUTO/MAN are not valid arguments for command"), |
| 292 |
122: ("NOP TRC", "Trace registers are not valid for command"), |
| 293 |
123: ("NOP ABLK", "A-block format not valid here"), |
| 294 |
124: ("NOP IBLK", "I-block format not valid here"), |
| 295 |
125: ("NOP STRNG", "Strings are not valid for this command"), |
| 296 |
126: ("NO ?", "This command cannot be queried"), |
| 297 |
127: ("BAD DTMD", "Not a valid peak detector mode"), |
| 298 |
128: ("PK WHAT?", "Not a valid peak search parameter"), |
| 299 |
129: ("PRE TERM", "Premature A-block termination"), |
| 300 |
130: ("BAD TDF", "Arguments are only for TDF command"), |
| 301 |
131: ("?? AM/FM", "AM/FM are not valid arguments for this command"), |
| 302 |
132: ("!FAV/RMP", "FAV/RAMP are not valid arguments for this command"), |
| 303 |
133: ("!INT/EXT", "INT/EXT are not valid arguments for this command"), |
| 304 |
134: ("??? ZERO", "ZERO is not a valid argument for this command"), |
| 305 |
135: ("??? CURR", "CURR is not a valid argument for this command"), |
| 306 |
136: ("??? FULL", "FULL is not a valid argument for this command"), |
| 307 |
137: ("??? LAST", "LAST is not a valid argument for this command"), |
| 308 |
138: ("!GRT/DSP", "GRT/DSP are not valid arguments for this command"), |
| 309 |
139: ("PLOTONLY", "Argument can only be used with PLOT command"), |
| 310 |
140: ("?? PWRON", "PWRON is not a valid argument for this command"), |
| 311 |
141: ("BAD ARG", "Argument can only be used with FDIAG command"), |
| 312 |
142: ("BAD ARG", "Query expected for FDIAG command"), |
| 313 |
143: ("NO PRESL", "No preselector hardware to use command with (HP 8562B)"), |
| 314 |
200: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 315 |
201: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 316 |
250: ("OUTOF RG", "ADC input is outside of ADC range"), |
| 317 |
251: ("NO IRQ", "Microprocessor not receiving interrupt from ADC"), |
| 318 |
300: ("YTO UNLK", "YTO (1ST LO) phase-locked loop (PLL) is unlocked"), |
| 319 |
301: ("YTO UNLK", "YTO PLL is unlocked"), |
| 320 |
302: ("OFF UNLK", "Offset Roller Oscillator PLL is unlocked"), |
| 321 |
303: ("XFR UNLK", "Transfer Roller Oscillator PLL is unlocked"), |
| 322 |
304: ("ROL UNLK", "Main Roller Oscillator PLL is unlocked"), |
| 323 |
305: ("FREQ ACC", "Frequency accuracy error"), |
| 324 |
306: ("FREQ ACC", "Frequency accuracy error"), |
| 325 |
307: ("FREQ ACC", "Frequency accuracy error"), |
| 326 |
308: ("FREQ ACC", "Frequency accuracy error"), |
| 327 |
309: ("FREQ ACC", "Frequency accuracy error"), |
| 328 |
310: ("FREQ ACC", "Frequency accuracy error"), |
| 329 |
311: ("FREQ ACC", "Frequency accuracy error"), |
| 330 |
312: ("FREQ ACC", "Frequency accuracy error"), |
| 331 |
313: ("FREQ ACC", "Frequency accuracy error"), |
| 332 |
314: ("FREQ ACC", "Frequency accuracy error"), |
| 333 |
315: ("FREQ ACC", "Frequency accuracy error"), |
| 334 |
316: ("FREQ ACC", "Frequency accuracy error"), |
| 335 |
317: ("FREQ ACC", "Frequency accuracy error"), |
| 336 |
318: ("FREQ ACC", "Frequency accuracy error"), |
| 337 |
319: ("FREQ ACC", "Frequency accuracy error"), |
| 338 |
320: ("FREQ ACC", "Frequency accuracy error"), |
| 339 |
321: ("FREQ ACC", "Frequency accuracy error"), |
| 340 |
322: ("FREQ ACC", "Frequency accuracy error"), |
| 341 |
323: ("FREQ ACC", "Frequency accuracy error"), |
| 342 |
324: ("FREQ ACC", "Frequency accuracy error"), |
| 343 |
325: ("FREQ ACC", "Frequency accuracy error"), |
| 344 |
326: ("FREQ ACC", "Frequency accuracy error"), |
| 345 |
327: ("OFF UNLK", "Offset Roller Oscillator PLL is unlocked"), |
| 346 |
328: ("FREQ ACC", "Frequency accuracy error"), |
| 347 |
329: ("FREQ ACC", "Frequency accuracy error"), |
| 348 |
331: ("FREQ ACC", "Frequency accuracy error"), |
| 349 |
333: ("600 UNLK", "600 MHz Reference Oscillator PLL is unlocked"), |
| 350 |
334: ("LO AMPL", "YTO (ist LO) unleveled"), |
| 351 |
400: ("AMPL 100", "Unable to adjust amplitude of 100 Hz resolution bandwidth"), |
| 352 |
401: ("AMPL 300", "Unable to adjust amplitude of 300 Hz resolution bandwidth"), |
| 353 |
402: ("AMPL 1K", "Unable to adjust amplitude of 1 kHz resolution bandwidth"), |
| 354 |
403: ("AMPL 3K", "Unable to adjust amplitude of 3 kHz resolution bandwidth"), |
| 355 |
404: ("AMPL 10K", "Unable to adjust amplitude of 10 kHz resolution bandwidth"), |
| 356 |
405: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 357 |
406: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 358 |
407: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 359 |
408: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 360 |
409: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 361 |
410: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 362 |
411: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 363 |
412: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 364 |
413: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 365 |
414: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 366 |
415: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 367 |
416: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 368 |
417: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 369 |
418: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 370 |
419: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 371 |
420: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 372 |
421: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 373 |
422: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 374 |
423: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 375 |
424: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 376 |
425: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 377 |
426: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 378 |
427: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 379 |
428: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 380 |
429: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 381 |
430: ("RBW 300", "Unable to adjust 300 Hz resolution bandwidth"), |
| 382 |
431: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 383 |
432: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 384 |
433: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 385 |
434: ("RBW 300", "Unable to adjust 300 Hz resolution bandwidth"), |
| 386 |
435: ("RBW 301", "Unable to adjust 300 Hz resolution bandwidth"), |
| 387 |
436: ("RBW 302", "Unable to adjust 300 Hz resolution bandwidth"), |
| 388 |
437: ("RBW 303", "Unable to adjust 300 Hz resolution bandwidth"), |
| 389 |
438: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 390 |
439: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 391 |
440: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 392 |
441: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 393 |
442: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 394 |
443: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 395 |
444: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 396 |
445: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 397 |
446: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 398 |
447: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 399 |
448: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 400 |
449: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 401 |
450: ("IF SYSTM", "IF hardware failure Check other error messages"), |
| 402 |
451: ("IF SYSTM", "IF hardware failure Check other error messages"), |
| 403 |
452: ("IF SYSTM", "IF hardware failure Check other error messages"), |
| 404 |
454: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 405 |
455: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 406 |
456: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 407 |
457: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 408 |
458: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 409 |
459: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 410 |
460: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 411 |
461: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 412 |
462: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 413 |
463: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 414 |
464: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 415 |
465: ("FREQ ACC", "Unable to adjust step gain amplifiers"), |
| 416 |
466: ("LIN AMPL", "Unable to adjust linear amplitude scale"), |
| 417 |
467: ("LOG AMPL", "Unable to adjust log amplitude scale"), |
| 418 |
468: ("LOG AMPL", "Unable to adjust log amplitude scale"), |
| 419 |
469: ("LOG AMPL", "Unable to adjust log amplitude scale"), |
| 420 |
470: ("LOG AMPL", "Unable to adjust log amplitude scale"), |
| 421 |
471: ("RBW 30K", "Unable to adjust 30 kHz resolution bandwidth"), |
| 422 |
472: ("RBW 100K", "Unable to adjust 100 kHz resolution bandwidth"), |
| 423 |
473: ("RBW 300K", "Unable to adjust 300 kHz resolution bandwidth"), |
| 424 |
474: ("RBW 1M", "Unable to adjust 1 MHz resolution bandwidth"), |
| 425 |
475: ("RBW 30K", "Unable to adjust 30 kHz resolution bandwidth"), |
| 426 |
476: ("RBW 100K", "Unable to adjust 30 kHz resolution bandwidth"), |
| 427 |
477: ("RBW 300K", "Unable to adjust 300 kHz resolution bandwidth"), |
| 428 |
478: ("RBW 1M", "Unable to adjust 1 MHz resolution bandwidth"), |
| 429 |
483: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 430 |
484: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 431 |
485: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 432 |
486: ("RBW 300", "Unable to adjust 300 Hz resolution bandwidth"), |
| 433 |
487: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 434 |
488: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 435 |
489: ("RBW 101", "Unable to adjust 100 Hz resolution bandwidth"), |
| 436 |
490: ("RBW 102", "Unable to adjust 100 Hz resolution bandwidth"), |
| 437 |
491: ("RBW 103", "Unable to adjust 100 Hz resolution bandwidth"), |
| 438 |
492: ("RBW 300", "Unable to adjust 300 Hz resolution bandwidth"), |
| 439 |
493: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 440 |
494: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 441 |
495: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 442 |
496: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 443 |
497: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 444 |
498: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 445 |
499: ("CAL UNLK", "A16 IF Adjustment Cal Oscillator is unlocked"), |
| 446 |
500: ("AMPL 30K", "Unable to adjust amplitude of 30 kHz resolution bandwidth"), |
| 447 |
501: ("AMPL 1M", "Unable to adjust amplitude of 100 kHz resolution bandwidth"), |
| 448 |
502: ("AMPL 3M", "Unable to adjust amplitude of 300 kHz resolution bandwidth"), |
| 449 |
503: ("AMPL 1M", "Unable to adjust amplitude of 1 MHz resolution bandwidth"), |
| 450 |
504: ("AMPL 30K", "Unable to adjust amplitude of 30 kHz resolution bandwidth"), |
| 451 |
505: ("AMPL 1M", "Unabie to adjust amplitude of 100 kHz resolution bandwidth"), |
| 452 |
506: ("AMPL 3M", "Unable to adjust amplitude of 300 kHz resolution bandwidth"), |
| 453 |
507: ("AMPL 1M", "Unable to adjust amplitude of 1 MHz resolution bandwidth"), |
| 454 |
508: ("AMPL 30K", "Unable to adjust amplitude of 30 kHz resolution bandwidth"), |
| 455 |
509: ("AMPL 1M", "Unable to adjust amplitude of 100 kHz resolution bandwidth"), |
| 456 |
510: ("AMPL 3M", "Unable to adjust amplitude of 300 kHz resolution bandwidth"), |
| 457 |
511: ("AMPL 1M", "Unable to adjust amplitude of 1 MHz resolution bandwidth"), |
| 458 |
512: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 459 |
513: ("RBW 300", "Unable to adjust 300 Hz resolution bandwidth"), |
| 460 |
514: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 461 |
515: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 462 |
516: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 463 |
517: ("RBW 100", "Unable to adjust 100 Hz resolution bandwidth"), |
| 464 |
518: ("RBW 300", "Unable to adjust 300 Hz resolution bandwidth"), |
| 465 |
519: ("RBW 1K", "Unable to adjust 1 kHz resolution bandwidth"), |
| 466 |
520: ("RBW 3K", "Unable to adjust 3 kHz resolution bandwidth"), |
| 467 |
521: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth"), |
| 468 |
522: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth SYM POLE 1"), |
| 469 |
523: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth SYM POLE 2"), |
| 470 |
524: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth SYM POLE 3"), |
| 471 |
525: ("RBW 10K", "Unable to adjust 10 kHz resolution bandwidth SYM POLE 4"), |
| 472 |
526: ("RBW <300", "Unable to adjust <300 Hz resolution bandwidths"), |
| 473 |
527: ("RBW <301", "Step gain correction failed for <300 Hz resolution bandwidth"), |
| 474 |
528: ("RBW <302", "Unable to adjust <300 Hz resolution bandwidths"), |
| 475 |
529: ("RBW <303", "Unable to adjust <300 Hz resolution bandwidths"), |
| 476 |
530: ("RBW <304", "Unable to adjust <300 Hz resolution bandwidths"), |
| 477 |
531: ( |
| 478 |
"RBW <305", "Unable to adjust gain versus frequency for resoultion bandwidths <300 Hz"), |
| 479 |
532: ("RBW <306", "Absolute gain data for resolution bandwidths <300 Hz not acceptable"), |
| 480 |
533: ("RBW <307", "Unable to adjust <300 Hz resolution bandwidths"), |
| 481 |
534: ("RBW <308", "Unable to adjust frequency accuracy for resolution bandwidths <100 Hz"), |
| 482 |
535: ("RBW <309", "Unable to adjust <300 Hz resolution bandwidths"), |
| 483 |
536: ("RBW <310", "Unable to adjust <300 Hz resolution bandwidths"), |
| 484 |
537: ("RBW <311", "Unable to adjust <300 Hz resolution bandwidths"), |
| 485 |
538: ("RBW <312", "Unable to adjust <300 Hz resolution bandwidths"), |
| 486 |
539: ("RBW <313", "Unable to adjust <300 Hz resolution bandwidths"), |
| 487 |
540: ("RBW <314", "Unable to adjust <300 Hz resolution bandwidths"), |
| 488 |
551: ("AMPL", "Unable to adjust step gain amplifiers"), |
| 489 |
552: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 490 |
553: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 491 |
554: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 492 |
555: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 493 |
556: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 494 |
557: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 495 |
558: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 496 |
559: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 497 |
560: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 498 |
561: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 499 |
562: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 500 |
563: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 501 |
564: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 502 |
565: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 503 |
566: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 504 |
567: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 505 |
568: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 506 |
569: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 507 |
570: ("LOG AMPL", "Unable to adjust amplitude of log scale"), |
| 508 |
571: ("AMPL", "Unable to adjust step gain amplifiers"), |
| 509 |
572: ("AMPL 1M", "Unable to adjust amplitude of 1 MHz resolution bandwidth"), |
| 510 |
573: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 511 |
574: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 512 |
575: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 513 |
576: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 514 |
577: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 515 |
581: ("AMPL", "Unable to adjust 100 kHz and <10 kHz resolution bandwidths"), |
| 516 |
582: ("AMPL", "Unable to adjust 100 kHz and <10 kHz resolution bandwidths"), |
| 517 |
583: ("RBW 30K", "Unable to adjust 30 kHz resolution bandwidth"), |
| 518 |
584: ("RBW 100K", "Unable to adjust 100 kHz resolution bandwidth"), |
| 519 |
585: ("RBW 300K", "Unable to adjust 300 kHz resolution bandwidth"), |
| 520 |
586: ("RBW 1M", "Unable to adjust 1 MHz resolution bandwidth"), |
| 521 |
587: ("RBW 30K", "Unable to adjust 30 kHz resolution bandwidth"), |
| 522 |
588: ("RBW 300K", "Unable to adjust 100 kHz resolution bandwidth"), |
| 523 |
589: ("RBW 300K", "Unable to adjust 300 kHz resolution bandwidth"), |
| 524 |
590: ("RBW 1M", "Unable to adjust 1 MHz resolution bandwidth"), |
| 525 |
591: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 526 |
592: ("LOG AMPL", "Unable to adjust amplitude in log scale"), |
| 527 |
600: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 528 |
601: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 529 |
650: ("OUTOF RG", "ADC input is outside of the ADC range"), |
| 530 |
651: ("NO IRQ", "Microprocessor is not receiving interrupt from ADC"), |
| 531 |
700: ("EEROM", "Checksum error of EEROM A2U501"), |
| 532 |
701: ("AMPL CAL", "Checksum error of frequency response correction data"), |
| 533 |
702: ("ELAP TIM", "Checksum error of elapsed time data"), |
| 534 |
703: ("AMPL CAL", "Checksum error of frequency response correction data"), |
| 535 |
704: ("PRESELCT", "Checksum error of customer preselector peak data"), |
| 536 |
705: ("ROM U306", "Checksum error of program ROM A2U306"), |
| 537 |
706: ("ROM U307", "Checksum error of program ROM A2U307"), |
| 538 |
707: ("ROM U308", "Checksum error of program ROM A2U308"), |
| 539 |
708: ("ROM U309", "Checksum error of program ROM A2U309"), |
| 540 |
709: ("ROM U310", "Checksum error of program ROM A2U310"), |
| 541 |
710: ("ROM U311", "Checksum error of program ROM A2U311"), |
| 542 |
711: ("RAM U303", "Checksum error of system RAM A2U303"), |
| 543 |
712: ("RAM U302", "Checksum error of system RAM A2U302"), |
| 544 |
713: ("RAM U301", "Checksum error of system RAM A2U301"), |
| 545 |
714: ("RAM U300", "Checksum error of system RAM A2U300"), |
| 546 |
715: ("RAM U305", "Checksum error of system RAM A2U305"), |
| 547 |
716: ("RAM U304", "Checksum error of system RAM A2U304"), |
| 548 |
717: ("BAD uP!!", "Microprocessor not fully operational"), |
| 549 |
718: ("BATTERY?", "Nonvolatile RAM not working; check battery"), |
| 550 |
750: ("SYSTEM", "Hardware/ firmware interaction; check other errors"), |
| 551 |
751: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 552 |
752: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 553 |
753: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 554 |
754: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 555 |
755: ("SYSTEM", "Hardware/firmware interaction; check other errors"), |
| 556 |
900: ("TG UNLVL", "Tracking generator output is unleveled"), |
| 557 |
901: ("TGFrqLmt", |
| 558 |
"Tracking generator output unleveled because START FREQ is set " |
| 559 |
"below tracking generator frequency limit (300 kHz)"), |
| 560 |
902: ("BAD NORM", |
| 561 |
"The state of the stored trace does not match the current state of the analyzer"), |
| 562 |
903: ("&> DLMT", "Unnormalized trace A is off-screen with trace math or normalization on"), |
| 563 |
904: ( |
| 564 |
"&> DLMT", |
| 565 |
"Calibration trace (trace B) is off-screen with trace math or normalization on") |
| 566 |
} |
| 567 |
|
| 568 |
# integer representation of error code |
| 569 |
code = 0 |
| 570 |
|
| 571 |
def __init__(self, code): |
| 572 |
"""Initialize an ErrorCode. |
| 573 |
|
| 574 |
:param code: Representing an error as id or short description |
| 575 |
:type code: str, int |
| 576 |
""" |
| 577 |
if not (isinstance(code, int) or isinstance(code, str)): |
| 578 |
print(type(code)) |
| 579 |
raise TypeError("Initialziation type for code must be integer or string") |
| 580 |
|
| 581 |
try: |
| 582 |
self.code = int(code) |
| 583 |
if self.code not in self.__error_code_list.keys(): |
| 584 |
raise ValueError() |
| 585 |
|
| 586 |
except (ValueError, TypeError): |
| 587 |
raise ValueError("This error code doesn't exist") |
| 588 |
|
| 589 |
(self.short, self.long) = self.__error_code_list[self.code] |
| 590 |
|
| 591 |
def __repr__(self): |
| 592 |
return "ErrorCode(\"" + self.short + " - " + self.long + "\")" |
| 593 |
|
| 594 |
def __eq__(self, other): |
| 595 |
return self.code == other.code |
| 596 |
|
| 597 |
|
| 598 |
class HP856Xx(Instrument): |
| 599 |
"""Represents the HP856XX series spectrum analyzers. |
| 600 |
|
| 601 |
Don't use this class directly - use their derivative classes |
| 602 |
|
| 603 |
.. note:: |
| 604 |
Most command descriptions are taken from the document: |
| 605 |
'HP 8560A, 8561B Operating & Programming' |
| 606 |
""" |
| 607 |
|
| 608 |
def __init__(self, adapter, name="Hewlett-Packard HP856Xx", **kwargs): |
| 609 |
super().__init__( |
| 610 |
adapter, |
| 611 |
name, |
| 612 |
includeSCPI=False, |
| 613 |
send_end=True, |
| 614 |
**kwargs, |
| 615 |
) |
| 616 |
|
| 617 |
def adjust_all(self): |
| 618 |
"""Activate the local oscillator (LO) and intermediate frequency (IF) |
| 619 |
alignment routines. These are the same routines that occur when is switched on. |
| 620 |
Commands following 'adjust_all' are not executed until after the analyzer has finished the |
| 621 |
alignment routines. |
| 622 |
""" |
| 623 |
self.write("ADJALL") |
| 624 |
|
| 625 |
def set_crt_adjustment_pattern(self): |
| 626 |
"""Activate a CRT adjustment pattern, shown in Figure 5-3. Use the |
| 627 |
X POSN, Y POSN, and TRACE ALIGN adjustments (available from the rear panel) to |
| 628 |
align the display. Use X POSN and Y POSN to move the display horizontally and vertically, |
| 629 |
respectively. Use TRACE ALIGN to straighten a tilted display. To remove the pattern from |
| 630 |
the screen, execute the :meth:`preset` command.""" |
| 631 |
self.write("ADJCRT") |
| 632 |
|
| 633 |
adjust_if = Instrument.control( |
| 634 |
"ADJIF?", "ADJIF %s", |
| 635 |
""" |
| 636 |
Control the automatic IF adjustment. This function is normally |
| 637 |
on. Because the IF is continuously adjusting, executing the IF alignment routine is seldom |
| 638 |
necessary. When the IF adjustment is not active, an "A" appears on the left side of the |
| 639 |
display. |
| 640 |
|
| 641 |
- `"FULL"` IF adjustment is done for all IF settings. |
| 642 |
- `"CURR"` IF adjustment is done only for the IF settings currently displayed. |
| 643 |
- `False` turns the continuous IF adjustment off. |
| 644 |
- `True` reactivates the continuous IF adjustment. |
| 645 |
|
| 646 |
Type: :code:`bool, str` |
| 647 |
""", |
| 648 |
validator=strict_discrete_set, |
| 649 |
map_values=True, |
| 650 |
values={True: "1", False: "0", "FULL": "FULL", "CURR": "CURR"}, |
| 651 |
cast=str |
| 652 |
) |
| 653 |
|
| 654 |
trace_a_minus_b_enabled = Instrument.control( |
| 655 |
"AMB?", "AMB %s", |
| 656 |
""" |
| 657 |
Control subtraction of the contents of trace B from trace A. |
| 658 |
It places the result, in dBm (when in log mode), in trace A. When in linear mode, |
| 659 |
the result is in volts. If trace A is in clear-write or max-hold mode, this function is |
| 660 |
continuous. When AMB is active, an "M" appears on the left side of the display. |
| 661 |
:attr:`trace_a_minus_b_plus_dl` overrides AMB. |
| 662 |
|
| 663 |
Type: :code:`bool` |
| 664 |
|
| 665 |
.. warning:: |
| 666 |
|
| 667 |
The displayed amplitude of each trace element falls in one of 600 data points. |
| 668 |
There are 10 points of overrange, which corresponds to one-sixth of a division |
| 669 |
Kg of overrange. When adding or subtracting trace data, any results exceeding |
| 670 |
this limit are clipped at the limit. |
| 671 |
""", |
| 672 |
validator=strict_discrete_set, |
| 673 |
map_values=True, |
| 674 |
values={True: "1", False: "0"}, |
| 675 |
cast=str |
| 676 |
) |
| 677 |
|
| 678 |
trace_a_minus_b_plus_dl_enabled = Instrument.control( |
| 679 |
"AMBPL?", "AMBPL %s", |
| 680 |
""" |
| 681 |
Control subtraction of trace B from trace A and addition to the display line, |
| 682 |
and stores the result in dBm (when in log mode) in trace A. When in linear |
| 683 |
mode, the result is in volts. If trace A is in clear-write or max-hold mode, this function |
| 684 |
is continuous. When this function is active, an "M" appears on the left side of the display. |
| 685 |
|
| 686 |
Type: :code:`bool` |
| 687 |
|
| 688 |
.. warning:: |
| 689 |
|
| 690 |
The displayed amplitude of each trace element falls in one of 600 data points. |
| 691 |
There are 10 points of overrange, which corresponds to one-sixth of a division |
| 692 |
Kg of overrange. When adding or subtracting trace data, any results exceeding |
| 693 |
this limit are clipped at the limit. |
| 694 |
""", |
| 695 |
validator=strict_discrete_set, |
| 696 |
map_values=True, |
| 697 |
values={True: "1", False: "0"}, |
| 698 |
cast=str |
| 699 |
) |
| 700 |
|
| 701 |
annotation_enabled = Instrument.control( |
| 702 |
"ANNOT?", "ANNOT %s", |
| 703 |
""" |
| 704 |
Set the display annotation off or on. |
| 705 |
|
| 706 |
Type: :code:`bool` |
| 707 |
""", |
| 708 |
validator=strict_discrete_set, |
| 709 |
map_values=True, |
| 710 |
values={True: "1", False: "0"}, |
| 711 |
cast=str |
| 712 |
) |
| 713 |
|
| 714 |
attenuation = Instrument.control( |
| 715 |
"AT?", "AT %s", |
| 716 |
""" |
| 717 |
Control the input attenuation in decade steps from 10 to 70 db (type 'int') or set to |
| 718 |
'AUTO' and 'MAN'(ual) |
| 719 |
|
| 720 |
Type: :code:`str`, :code:`int` |
| 721 |
|
| 722 |
.. code-block:: python |
| 723 |
|
| 724 |
instr.attenuation = 'AUTO' |
| 725 |
instr.attenuation = 60 |
| 726 |
|
| 727 |
""", |
| 728 |
validator=joined_validators(strict_discrete_set, truncated_discrete_set), |
| 729 |
values=[["AUTO", "MAN"], np.arange(10, 80, 10)], |
| 730 |
cast=int, |
| 731 |
) |
| 732 |
|
| 733 |
amplitude_unit = Instrument.control( |
| 734 |
"AUNITS?", "AUNITS %s", |
| 735 |
""" |
| 736 |
Control the amplitude unit with a selection of the following parameters: string |
| 737 |
'DBM', 'DBMV', 'DBUV', 'V', 'W', 'AUTO', 'MAN' or use the enum :class:`AmplitudeUnits` |
| 738 |
|
| 739 |
Type: :code:`str` |
| 740 |
|
| 741 |
.. code-block:: python |
| 742 |
|
| 743 |
instr.amplitude_unit = 'dBmV' |
| 744 |
instr.amplitude_unit = AmplitudeUnits.dBmV |
| 745 |
|
| 746 |
""", |
| 747 |
validator=strict_discrete_set, |
| 748 |
values=[str(e).upper() for e in AmplitudeUnits], |
| 749 |
set_process=lambda v: str(v).upper() |
| 750 |
) |
| 751 |
|
| 752 |
def write(self, command, **kwargs): |
| 753 |
if "{amplitude_unit}" in command: |
| 754 |
command = command.format(amplitude_unit=self.amplitude_unit) |
| 755 |
super().write(command, **kwargs) |
| 756 |
|
| 757 |
def set_auto_couple(self): |
| 758 |
"""Set the video bandwidth, resolution bandwidth, input attenuation, |
| 759 |
sweep time, and center frequency step-size to coupled mode. |
| 760 |
|
| 761 |
These functions can be recoupled individually or all at once. |
| 762 |
The spectrum analyzer chooses appropriate values for these |
| 763 |
functions. The video bandwidth and resolution bandwidth are set |
| 764 |
according to the coupled ratios stored under :attr:`resolution_bandwidth_to_span_ratio` |
| 765 |
and :attr:`video_bandwidth_to_resolution_bandwidth`. If |
| 766 |
no ratios are chosen, default ratios (1.0 and 0.011, |
| 767 |
respectively) are used instead. |
| 768 |
""" |
| 769 |
self.write("AUTOCPL") |
| 770 |
|
| 771 |
def exchange_traces(self): |
| 772 |
"""Exchange the contents of trace A with those of trace B. |
| 773 |
|
| 774 |
If the traces are in clear-write or max-hold mode, the mode is |
| 775 |
changed to view. Otherwise, the traces remain in their initial |
| 776 |
mode. |
| 777 |
""" |
| 778 |
self.write("AXB") |
| 779 |
|
| 780 |
def blank_trace(self, trace): |
| 781 |
"""Blank the chosen trace from the display. The current contents of the |
| 782 |
trace remain in the trace but are not updated. |
| 783 |
|
| 784 |
.. code-block:: python |
| 785 |
|
| 786 |
instr.blank_trace('TRA') |
| 787 |
instr.blank_trace(Trace.A) |
| 788 |
|
| 789 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 790 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 791 |
|
| 792 |
:type trace: str |
| 793 |
:raises TypeError: Type isn't 'string' |
| 794 |
:raises ValueError: Value is 'TRA' nor 'TRB' |
| 795 |
""" |
| 796 |
if not isinstance(trace, str): |
| 797 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 798 |
|
| 799 |
if trace not in [e for e in Trace]: |
| 800 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 801 |
trace)) |
| 802 |
self.write("BLANK " + trace) |
| 803 |
|
| 804 |
def subtract_display_line_from_trace_b(self): |
| 805 |
"""Subtract the display line from trace B and places the result in dBm |
| 806 |
(when in log mode) in trace B, which is then set to view mode. |
| 807 |
|
| 808 |
In linear mode, the results are in volts. |
| 809 |
""" |
| 810 |
self.write("BML") |
| 811 |
|
| 812 |
center_frequency = Instrument.control( |
| 813 |
"CF?", "CF %.11E Hz", |
| 814 |
""" |
| 815 |
Control the center frequency in hertz and sets the spectrum analyzer to center |
| 816 |
frequency / span mode. |
| 817 |
|
| 818 |
The span remains constant; the start and stop frequencies change as |
| 819 |
the center frequency changes. |
| 820 |
|
| 821 |
Type: :code:`float` |
| 822 |
|
| 823 |
.. code-block:: python |
| 824 |
|
| 825 |
instr.center_frequency = 300.5e6 |
| 826 |
if instr.center_frequency == 200e3: |
| 827 |
print("Correct frequency") |
| 828 |
|
| 829 |
""", |
| 830 |
validator=strict_range, |
| 831 |
values=[0, 1], |
| 832 |
dynamic=True |
| 833 |
) |
| 834 |
|
| 835 |
def clear_write_trace(self, trace): |
| 836 |
"""Set the chosen trace to clear-write mode. This mode sets each |
| 837 |
element of the chosen trace to the bottom-screen value; then new data |
| 838 |
from the detector is put in the trace with each sweep. |
| 839 |
|
| 840 |
.. code-block:: python |
| 841 |
|
| 842 |
instr.clear_write_trace('TRA') |
| 843 |
instr.clear_write_trace(Trace.A) |
| 844 |
|
| 845 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 846 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 847 |
|
| 848 |
:type trace: str |
| 849 |
:raises TypeError: Type isn't 'string' |
| 850 |
:raises ValueError: Value is 'TRA' nor 'TRB' |
| 851 |
""" |
| 852 |
if not isinstance(trace, str): |
| 853 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 854 |
|
| 855 |
if trace not in [e for e in Trace]: |
| 856 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 857 |
trace)) |
| 858 |
|
| 859 |
self.write("CLRW " + trace) |
| 860 |
|
| 861 |
def set_continuous_sweep(self): |
| 862 |
"""Set the instrument to continuous-sweep mode. |
| 863 |
|
| 864 |
This mode enables another sweep at the completion of the current |
| 865 |
sweep once the trigger conditions are met. |
| 866 |
""" |
| 867 |
self.write("CONTS") |
| 868 |
|
| 869 |
coupling = Instrument.control( |
| 870 |
"COUPLE?", "COUPLE %s", |
| 871 |
""" |
| 872 |
Control the input coupling of the spectrum analyzer. |
| 873 |
AC coupling protects the input of the analyzer from damaging dc signals, while limiting |
| 874 |
the lower frequency-range to 100 kHz (although the analyzer will tune down to 0 Hz with |
| 875 |
signal attenuation). |
| 876 |
|
| 877 |
Type: :code:`str` |
| 878 |
|
| 879 |
Takes a representation of the coupling mode, either from :class:`CouplingMode` or |
| 880 |
use 'AC' / 'DC' |
| 881 |
|
| 882 |
.. code-block:: python |
| 883 |
|
| 884 |
instr.coupling = 'AC' |
| 885 |
instr.coupling = CouplingMode.DC |
| 886 |
|
| 887 |
if instr.coupling == CouplingMode.DC: |
| 888 |
pass |
| 889 |
|
| 890 |
""", |
| 891 |
validator=strict_discrete_set, |
| 892 |
values=[e for e in CouplingMode] |
| 893 |
) |
| 894 |
|
| 895 |
demodulation_mode = Instrument.control( |
| 896 |
"DEMOD?", "DEMOD %s", |
| 897 |
""" |
| 898 |
Control the demodulation mode of the spectrum analyzer. Either AM or FM demodulation, |
| 899 |
or turns the demodulation — off. |
| 900 |
Place a marker on a desired signal and then set :attr:`demodulation_mode`; |
| 901 |
demodulation takes place on this signal. If no marker is on, :attr:`demodulation_mode` |
| 902 |
automatically places a marker at the center of the trace and demodulates the frequency at |
| 903 |
that marker position. Use the volume and squelch controls to adjust the speaker and listen. |
| 904 |
|
| 905 |
Type: :code:`str` |
| 906 |
|
| 907 |
Takes a representation of the demodulation mode, either from :class:`DemodulationMode` or |
| 908 |
use 'OFF', 'AM', 'FM' |
| 909 |
|
| 910 |
.. code-block:: python |
| 911 |
|
| 912 |
instr.demodulation_mode = 'AC' |
| 913 |
instr.demodulation_mode = DemodulationMode.AM |
| 914 |
|
| 915 |
if instr.demodulation_mode == DemodulationMode.FM: |
| 916 |
instr.demodulation_mode = Demodulation.OFF |
| 917 |
|
| 918 |
""", |
| 919 |
validator=strict_discrete_set, |
| 920 |
values=[e for e in DemodulationMode] |
| 921 |
) |
| 922 |
|
| 923 |
demodulation_agc_enabled = Instrument.control( |
| 924 |
"DEMODAGC?", "DEMODAGC %s", |
| 925 |
""" |
| 926 |
Control the demodulation automatic gain control (AGC). |
| 927 |
The AGC keeps the volume of the speaker relatively constant during AM demodulation. AGC |
| 928 |
is available only during AM demodulation and when the frequency span is greater than 0 Hz. |
| 929 |
|
| 930 |
Type: :code:`bool` |
| 931 |
|
| 932 |
.. code-block:: python |
| 933 |
|
| 934 |
instr.demodulation_agc = True |
| 935 |
|
| 936 |
if instr.demodulation_agc: |
| 937 |
instr.demodulation_agc = False |
| 938 |
|
| 939 |
""", |
| 940 |
validator=strict_discrete_set, |
| 941 |
map_values=True, |
| 942 |
values={True: "1", False: "0"}, |
| 943 |
cast=str |
| 944 |
) |
| 945 |
|
| 946 |
demodulation_time = Instrument.control( |
| 947 |
"DEMODT?", "DEMODT %.11E", |
| 948 |
""" |
| 949 |
Control the amount of time that the sweep pauses at the marker to |
| 950 |
demodulate a signal. The default value is 1 second. When the frequency span equals 0 Hz, |
| 951 |
demodulation is continuous, except when between sweeps. For truly continuous demodulation, |
| 952 |
set the frequency span to 0 Hz and the trigger mode to single sweep (see TM). |
| 953 |
Minimum 100 ms to maximum 60 s |
| 954 |
|
| 955 |
Type: :code:`float` |
| 956 |
|
| 957 |
.. code-block:: python |
| 958 |
|
| 959 |
# set the demodulation time to 1.2 seconds |
| 960 |
instr.demodulation_time = 1.2 |
| 961 |
|
| 962 |
if instr.demodulation_time == 10: |
| 963 |
pass |
| 964 |
|
| 965 |
""", |
| 966 |
validator=strict_range, |
| 967 |
values=[100e-3, 60], |
| 968 |
) |
| 969 |
|
| 970 |
detector_mode = Instrument.control( |
| 971 |
"DET?", "DET %s", |
| 972 |
""" |
| 973 |
Control the IF detector used for acquiring measurement data. |
| 974 |
This is normally a coupled function, in which the spectrum analyzer selects the |
| 975 |
appropriate detector mode. Four modes are available: normal, positive, negative, and sample. |
| 976 |
|
| 977 |
Type: :code:`str` |
| 978 |
|
| 979 |
Takes a representation of the detector mode, either from :class:`DetectionModes` or |
| 980 |
use 'NEG', 'NRM', 'POS', 'SMP' |
| 981 |
|
| 982 |
.. code-block:: python |
| 983 |
|
| 984 |
instr.detector_mode = DetectionModes.SMP |
| 985 |
instr.detector_mode = 'NEG' |
| 986 |
|
| 987 |
if instr.detector_mode == DetectionModes.SMP: |
| 988 |
pass |
| 989 |
|
| 990 |
""", |
| 991 |
validator=strict_discrete_set, |
| 992 |
values=[e for e in DetectionModes] |
| 993 |
) |
| 994 |
|
| 995 |
# now implemented as a property but due to the ability of the underlying gpib command to |
| 996 |
# specify the unit, there would be an alternative implementation as a method to allow the user |
| 997 |
# to modify the setting unit without manipulating it via the 'amplitude_unit' property |
| 998 |
display_line = Instrument.control( |
| 999 |
"DL?", "DL %g.11E {amplitude_unit}", |
| 1000 |
""" |
| 1001 |
Control the horizontal display line for use as a visual aid or for |
| 1002 |
computational purposes. The default value is 0 dBm. |
| 1003 |
|
| 1004 |
Type: :code:`float` |
| 1005 |
|
| 1006 |
Takes a value with the unit of :attr:`amplitude_unit` |
| 1007 |
|
| 1008 |
.. code-block:: python |
| 1009 |
|
| 1010 |
instr.display_line = -10 |
| 1011 |
|
| 1012 |
if instr.display_line == 0: |
| 1013 |
pass |
| 1014 |
|
| 1015 |
""" |
| 1016 |
) |
| 1017 |
|
| 1018 |
display_line_enabled = Instrument.setting( |
| 1019 |
"DL %s", |
| 1020 |
""" |
| 1021 |
Set the horizontal display line for use as a visual aid either on or off. |
| 1022 |
|
| 1023 |
.. code-block:: python |
| 1024 |
|
| 1025 |
instr.display_line_enabled = False |
| 1026 |
|
| 1027 |
""", |
| 1028 |
map_values=True, |
| 1029 |
validator=strict_discrete_set, |
| 1030 |
values={True: "ON", False: "OFF"} |
| 1031 |
) |
| 1032 |
|
| 1033 |
done = Instrument.measurement( |
| 1034 |
"DONE?", |
| 1035 |
""" |
| 1036 |
Get back (e.g. return) when all commands in a command string |
| 1037 |
entered before 'done' has been completed. Sending a :meth:`trigger_sweep` command |
| 1038 |
before 'done' ensures that the spectrum analyzer will complete a full sweep before |
| 1039 |
continuing on in a program. |
| 1040 |
Depending on the timeout a timeout error from the adapter will raise before the spectrum |
| 1041 |
analyzer can finish due to an extreme long sweep time |
| 1042 |
|
| 1043 |
.. code-block:: python |
| 1044 |
|
| 1045 |
instr.trigger_sweep() |
| 1046 |
|
| 1047 |
# wait for a full sweep and than 'do_something' |
| 1048 |
if instr.done: |
| 1049 |
do_something() |
| 1050 |
|
| 1051 |
""" |
| 1052 |
) |
| 1053 |
|
| 1054 |
def check_done(self): |
| 1055 |
""" |
| 1056 |
Return when all commands in a command string |
| 1057 |
entered before :meth:'check_done' has been completed. Sending a :meth:`trigger_sweep` |
| 1058 |
command before 'check_done' ensures that the spectrum analyzer will complete a full sweep |
| 1059 |
before continuing on in a program. Depending on the timeout a timeout error from the |
| 1060 |
adapter will raise before the spectrum analyzer can finish due to an extreme long sweep |
| 1061 |
time. |
| 1062 |
|
| 1063 |
.. code-block:: python |
| 1064 |
|
| 1065 |
instr.trigger_sweep() |
| 1066 |
|
| 1067 |
# wait for a full sweep and than 'do_something' |
| 1068 |
instr.check_done() |
| 1069 |
do_something() |
| 1070 |
|
| 1071 |
""" |
| 1072 |
# no error checking because there is no possibility to return anything else than '1' |
| 1073 |
self.ask("DONE?") |
| 1074 |
|
| 1075 |
errors = Instrument.measurement( |
| 1076 |
"ERR?", |
| 1077 |
""" |
| 1078 |
Get a list of errors present (of type :class:`ErrorCode`). An empty list means there |
| 1079 |
are no errors. Reading 'errors' clears all HP-IB errors. For best results, enter error |
| 1080 |
data immediately after querying for errors. |
| 1081 |
|
| 1082 |
Type: :class:`ErrorCode` |
| 1083 |
|
| 1084 |
.. code-block:: python |
| 1085 |
|
| 1086 |
errors = instr.errors |
| 1087 |
if len(errors) > 0: |
| 1088 |
print(errors[0].code) |
| 1089 |
|
| 1090 |
for error in errors: |
| 1091 |
print(error) |
| 1092 |
|
| 1093 |
if ErrorCode(112) in errors: |
| 1094 |
print("yeah") |
| 1095 |
|
| 1096 |
Example result of this python snippet: |
| 1097 |
|
| 1098 |
.. code-block:: python |
| 1099 |
|
| 1100 |
112 |
| 1101 |
ErrorCode("??CMD?? - Unrecognized command") |
| 1102 |
ErrorCode("NOP NUM - Command cannot have numeric units") |
| 1103 |
yeah |
| 1104 |
|
| 1105 |
""", |
| 1106 |
cast=ErrorCode, |
| 1107 |
get_process=lambda v: v if isinstance(v, list) else [] |
| 1108 |
) |
| 1109 |
|
| 1110 |
elapsed_time = Instrument.measurement( |
| 1111 |
"EL?", |
| 1112 |
""" |
| 1113 |
Get the elapsed time (in hours) of analyzer operation. |
| 1114 |
This value can be reset only by Hewlett-Packard. |
| 1115 |
|
| 1116 |
Type: :code:`int` |
| 1117 |
|
| 1118 |
.. code-block:: python |
| 1119 |
|
| 1120 |
print(elapsed_time) |
| 1121 |
1998 |
| 1122 |
|
| 1123 |
""", |
| 1124 |
cast=int |
| 1125 |
) |
| 1126 |
|
| 1127 |
start_frequency = Instrument.control( |
| 1128 |
"FA?", "FA %.11E Hz", |
| 1129 |
""" |
| 1130 |
Control the start frequency and set the spectrum analyzer to start-frequency/ |
| 1131 |
stop-frequency mode. If the start frequency exceeds the stop frequency, the stop frequency |
| 1132 |
increases to equal the start frequency plus 100 Hz. The center frequency and span change |
| 1133 |
with changes in the start frequency. |
| 1134 |
|
| 1135 |
Type: :code:`float` |
| 1136 |
|
| 1137 |
.. code-block:: python |
| 1138 |
|
| 1139 |
instr.start_frequency = 300.5e6 |
| 1140 |
if instr.start_frequency == 200e3: |
| 1141 |
print("Correct frequency") |
| 1142 |
|
| 1143 |
""", |
| 1144 |
validator=strict_range, |
| 1145 |
values=[0, 1], |
| 1146 |
dynamic=True |
| 1147 |
) |
| 1148 |
|
| 1149 |
stop_frequency = Instrument.control( |
| 1150 |
"FB?", "FB %.11E Hz", |
| 1151 |
""" |
| 1152 |
Control the stop frequency and set the spectrum analyzer to start-frequency/ |
| 1153 |
stop-frequency mode. If the stop frequency is less than the start frequency, the start |
| 1154 |
frequency decreases to equal the stop frequency minus 100 Hz. The center frequency and |
| 1155 |
span change with changes in the stop frequency. |
| 1156 |
|
| 1157 |
Type: :code:`float` |
| 1158 |
|
| 1159 |
.. code-block:: python |
| 1160 |
|
| 1161 |
instr.stop_frequency = 300.5e6 |
| 1162 |
if instr.stop_frequency == 200e3: |
| 1163 |
print("Correct frequency") |
| 1164 |
|
| 1165 |
""", |
| 1166 |
validator=strict_range, |
| 1167 |
values=[0, 1], |
| 1168 |
dynamic=True |
| 1169 |
) |
| 1170 |
|
| 1171 |
sampling_frequency = Instrument.measurement( |
| 1172 |
"FDIAG SMP,?", |
| 1173 |
""" |
| 1174 |
Get the sampling oscillator frequency corresponding to the current start |
| 1175 |
frequency. |
| 1176 |
Diagnostic Attribute |
| 1177 |
|
| 1178 |
Type: :code:`float` |
| 1179 |
""" |
| 1180 |
) |
| 1181 |
|
| 1182 |
lo_frequency = Instrument.measurement( |
| 1183 |
"FDIAG LO,?", |
| 1184 |
""" |
| 1185 |
Get the first local oscillator frequency corresponding to the current start |
| 1186 |
frequency. |
| 1187 |
Diagnostic Attribute |
| 1188 |
|
| 1189 |
Type: :code:`float` |
| 1190 |
""" |
| 1191 |
) |
| 1192 |
|
| 1193 |
mroll_frequency = Instrument.measurement( |
| 1194 |
"FDIAG MROLL,?", |
| 1195 |
""" |
| 1196 |
Get the main roller oscillator frequency corresponding to the current start |
| 1197 |
frequency, except then the resolution bandwidth is less than or equal to 100 Hz. |
| 1198 |
|
| 1199 |
Diagnostic Attribute |
| 1200 |
|
| 1201 |
Type: :code:`float` |
| 1202 |
""" |
| 1203 |
) |
| 1204 |
|
| 1205 |
oroll_frequency = Instrument.measurement( |
| 1206 |
"FDIAG OROLL,?", |
| 1207 |
""" |
| 1208 |
Get the offset roller oscillator frequency corresponding to the current start |
| 1209 |
frequency, except when the resolution bandwidth is less than or equal to 100 Hz. |
| 1210 |
|
| 1211 |
Diagnostic Attribute |
| 1212 |
|
| 1213 |
Type: :code:`float` |
| 1214 |
""" |
| 1215 |
) |
| 1216 |
|
| 1217 |
xroll_frequency = Instrument.measurement( |
| 1218 |
"FDIAG XROLL,?", |
| 1219 |
""" |
| 1220 |
Get the transfer roller oscillator frequency corresponding to the current start |
| 1221 |
frequency, except when the resolution bandwidth is less than or equal to 100 Hz. |
| 1222 |
|
| 1223 |
Diagnostic Attribute |
| 1224 |
|
| 1225 |
Type: :code:`float` |
| 1226 |
""" |
| 1227 |
) |
| 1228 |
|
| 1229 |
sampler_harmonic_number = Instrument.measurement( |
| 1230 |
"FDIAG HARM,?", |
| 1231 |
""" |
| 1232 |
Get the sampler harmonic number corresponding to the current start |
| 1233 |
frequency. |
| 1234 |
|
| 1235 |
Diagnostic Attribute |
| 1236 |
|
| 1237 |
Type: :code:`int` |
| 1238 |
""", |
| 1239 |
get_process=lambda v: int(float(v)) |
| 1240 |
) |
| 1241 |
|
| 1242 |
# practically you could also write "OFF" to actively disable it or reset via "IP" |
| 1243 |
frequency_display_enabled = Instrument.measurement( |
| 1244 |
"FDSP?", |
| 1245 |
""" |
| 1246 |
Get the state of all annotations that describes the spectrum analyzer frequency. |
| 1247 |
returns 'False' if no annotations are shown and vice versa 'True'. This includes the start |
| 1248 |
and stop frequencies, the center frequency, the frequency span, marker readouts, the center |
| 1249 |
frequency step-size, and signal identification to center frequency. To retrieve the |
| 1250 |
frequency data, query the spectrum analyzer. |
| 1251 |
|
| 1252 |
Type: :code:`bool` |
| 1253 |
|
| 1254 |
.. code-block:: python |
| 1255 |
|
| 1256 |
if instr.frequency_display: |
| 1257 |
print("Frequencies get displayed") |
| 1258 |
|
| 1259 |
""", |
| 1260 |
map_values=True, |
| 1261 |
values={True: "1", False: "0"}, |
| 1262 |
cast=str |
| 1263 |
) |
| 1264 |
|
| 1265 |
def do_fft(self, source, destination, window): |
| 1266 |
"""Calculate and show a discrete Fourier transform. |
| 1267 |
|
| 1268 |
The FFT command performs a discrete Fourier transform on the source |
| 1269 |
trace array and stores the logarithms of the magnitudes of the results |
| 1270 |
in the destination array. The maximum length of any of the traces is |
| 1271 |
601 points. FFT is designed to be used in transforming zero-span |
| 1272 |
amplitude-modulation information into the frequency domain. Performing |
| 1273 |
an FFT on a frequency sweep will not provide time-domain results. The |
| 1274 |
FFT results are displayed on the spectrum analyzer in a logarithmic |
| 1275 |
amplitude scale. For the horizontal dimension, the frequency at the |
| 1276 |
left side of the graph is 0 Hz, and at the right side is Finax- Fmax is |
| 1277 |
equal to 300 divided by sweep time. As an example, if the sweep time of |
| 1278 |
the analyzer is 60 ms, Fmax equals 5 kHz. The FFT algorithm assumes |
| 1279 |
that the sampled signal is periodic with an integral number of periods |
| 1280 |
within the time-record length (that is, the sweep time of the |
| 1281 |
analyzer). Given this assumption, the transform computed is that of a |
| 1282 |
time waveform of infinite duration, formed of concatenated time |
| 1283 |
records. In actual measurements, the number of periods of the sampled |
| 1284 |
signal within the time record may not be integral. In this case, there |
| 1285 |
is a step discontinuity at the intersections of the concatenated time |
| 1286 |
records in the assumed time waveform of infinite duration. This step |
| 1287 |
discontinuity causes measurement errors, both amplitude uncertainty |
| 1288 |
(where the signal level appears to vary with small changes in |
| 1289 |
frequency) and frequency resolution (due to filter shape factor and |
| 1290 |
sidelobes). Windows are weighting functions that are applied to the |
| 1291 |
input data to force the ends of that data smoothly to zero, thus |
| 1292 |
reducing the step discontinuity and reducing measuremen errors. |
| 1293 |
|
| 1294 |
:param source: A representation of the trace, either from :class:`Trace` or |
| 1295 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 1296 |
:param destination: A representation of the trace, either from :class:`Trace` or |
| 1297 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 1298 |
:param window: A representation of the trace, either from :class:`Trace` or |
| 1299 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 1300 |
|
| 1301 |
:type source: str |
| 1302 |
:type destination: str |
| 1303 |
:type window: str |
| 1304 |
""" |
| 1305 |
if not isinstance(source, str): |
| 1306 |
raise TypeError("Should be of type string but is '%s'" % type(source)) |
| 1307 |
|
| 1308 |
if not isinstance(destination, str): |
| 1309 |
raise TypeError("Should be of type string but is '%s'" % type(destination)) |
| 1310 |
|
| 1311 |
if not isinstance(window, str): |
| 1312 |
raise TypeError("Should be of type string but is '%s'" % type(window)) |
| 1313 |
|
| 1314 |
if source not in [e for e in Trace]: |
| 1315 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 1316 |
source)) |
| 1317 |
if destination not in [e for e in Trace]: |
| 1318 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 1319 |
destination)) |
| 1320 |
if window not in [e for e in Trace]: |
| 1321 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 1322 |
window)) |
| 1323 |
self.write("FFT %s,%s,%s" % (source, destination, window)) |
| 1324 |
|
| 1325 |
frequency_offset = Instrument.control( |
| 1326 |
"FOFFSET?", "FOFFSET %.11E Hz", |
| 1327 |
""" |
| 1328 |
Control an offset added to the displayed absolute-frequency values, |
| 1329 |
including marker-frequency values. |
| 1330 |
|
| 1331 |
It does not affect the frequency range of the sweep, nor |
| 1332 |
does it affect relative frequency readouts. When this function is active, an "F" appears on |
| 1333 |
the left side of the display. |
| 1334 |
Changes all the following frequency measurements. |
| 1335 |
|
| 1336 |
Type: :code:`float` |
| 1337 |
|
| 1338 |
.. code-block:: python |
| 1339 |
|
| 1340 |
instr.frequency_offset = 2e6 |
| 1341 |
if instr.frequency_offset == 2e6: |
| 1342 |
print("Correct frequency") |
| 1343 |
|
| 1344 |
""", |
| 1345 |
validator=strict_range, |
| 1346 |
values=[0, 1], |
| 1347 |
dynamic=True |
| 1348 |
) |
| 1349 |
|
| 1350 |
frequency_reference_source = Instrument.control( |
| 1351 |
"FREF?", "FREF %s", |
| 1352 |
""" |
| 1353 |
Control the frequency reference source. |
| 1354 |
Select either the internal frequency reference (INT) or supply your own external |
| 1355 |
reference (EXT). An external reference must be 10 MHz (+100 Hz) at a minimum amplitude of |
| 1356 |
0 dBm. Connect the external reference to J9 (10 MHz REF IN/OUT) on the rear panel. When |
| 1357 |
the external mode is selected, an "X" appears on the left edge of the display. |
| 1358 |
|
| 1359 |
Type: :code:`str` |
| 1360 |
|
| 1361 |
Takes element of :class:`FrequencyReference` or use 'INT', 'EXT' |
| 1362 |
|
| 1363 |
.. code-block:: python |
| 1364 |
|
| 1365 |
instr.frequency_reference_source = 'INT' |
| 1366 |
instr.frequency_reference_source = FrequencyReference.EXT |
| 1367 |
|
| 1368 |
if instr.frequency_reference_source == FrequencyReference.INT: |
| 1369 |
instr.frequency_reference_source = FrequencyReference.EXT |
| 1370 |
|
| 1371 |
""", |
| 1372 |
validator=strict_discrete_set, |
| 1373 |
values=[e for e in FrequencyReference] |
| 1374 |
) |
| 1375 |
|
| 1376 |
def set_full_span(self): |
| 1377 |
"""Set the spectrum analyzer to the full frequency span as defined by |
| 1378 |
the instrument. |
| 1379 |
|
| 1380 |
The full span is 2.9 GHz for the HP 8560A. For the HP 8561B, the |
| 1381 |
full span is 6.5 GHz. |
| 1382 |
""" |
| 1383 |
self.write("FS") |
| 1384 |
|
| 1385 |
graticule_enabled = Instrument.control( |
| 1386 |
"GRAT?", "GRAT %s", |
| 1387 |
""" |
| 1388 |
Control the display graticule. Switch it either on or off. |
| 1389 |
|
| 1390 |
Type: :class:`bool` |
| 1391 |
|
| 1392 |
.. code-block:: python |
| 1393 |
|
| 1394 |
instr.graticule = True |
| 1395 |
|
| 1396 |
if instr.graticule: |
| 1397 |
pass |
| 1398 |
|
| 1399 |
""", |
| 1400 |
map_values=True, |
| 1401 |
values={True: "1", False: "0"}, |
| 1402 |
validator=strict_discrete_set, |
| 1403 |
cast=str |
| 1404 |
) |
| 1405 |
|
| 1406 |
def hold(self): |
| 1407 |
"""Freeze the active function at its current value. |
| 1408 |
|
| 1409 |
If no function is active, no operation takes place. |
| 1410 |
""" |
| 1411 |
self.write("HD") |
| 1412 |
|
| 1413 |
id = Instrument.measurement( |
| 1414 |
"ID?", |
| 1415 |
""" |
| 1416 |
Get the identification of the device with software and hardware revision (e.g. HP8560A,002, |
| 1417 |
H03) |
| 1418 |
|
| 1419 |
Type: :class:`str` |
| 1420 |
|
| 1421 |
.. code-block:: python |
| 1422 |
|
| 1423 |
print(instr.id) |
| 1424 |
HP8560A,002,H02 |
| 1425 |
|
| 1426 |
""", |
| 1427 |
maxsplit=0, |
| 1428 |
cast=str |
| 1429 |
) |
| 1430 |
|
| 1431 |
def preset(self): |
| 1432 |
"""Set the spectrum analyzer to a known, predefined state. |
| 1433 |
|
| 1434 |
'preset' does not affect the contents of any data or trace |
| 1435 |
registers or stored preselector data. 'preset' does not clear |
| 1436 |
the input or output data buffers; |
| 1437 |
""" |
| 1438 |
self.write("IP") |
| 1439 |
|
| 1440 |
logarithmic_scale = Instrument.control( |
| 1441 |
"LG?", "LG %d DB", |
| 1442 |
""" |
| 1443 |
Control the logarithmic amplitude scale. When in linear |
| 1444 |
mode, querying 'logarithmic_scale' returns a “0”. |
| 1445 |
Allowed values are 0, 1, 2, 5, 10 |
| 1446 |
|
| 1447 |
Type: :class:`int` |
| 1448 |
|
| 1449 |
.. code-block:: python |
| 1450 |
|
| 1451 |
if instr.logarithmic_scale: |
| 1452 |
pass |
| 1453 |
|
| 1454 |
# set the scale to 10 db per division |
| 1455 |
instr.logarithmic_scale = 10 |
| 1456 |
|
| 1457 |
""", |
| 1458 |
cast=int, |
| 1459 |
validator=strict_discrete_set, |
| 1460 |
values=[0, 1, 2, 5, 10] |
| 1461 |
) |
| 1462 |
|
| 1463 |
def set_linear_scale(self): |
| 1464 |
"""Set the spectrum analyzers display to linear amplitude scale. |
| 1465 |
|
| 1466 |
Measurements made on a linear scale can be read out in any |
| 1467 |
units. |
| 1468 |
""" |
| 1469 |
self.write("LN") |
| 1470 |
|
| 1471 |
def set_minimum_hold(self, trace): |
| 1472 |
"""Update the chosen trace with the minimum signal level detected at |
| 1473 |
each trace-data point from subsequent sweeps. This function employs the |
| 1474 |
negative peak detector (refer to the :attr:`detector_mode` command). |
| 1475 |
|
| 1476 |
.. code-block:: python |
| 1477 |
|
| 1478 |
instr.minimum_hold('TRA') |
| 1479 |
instr.minimum_hold(Trace.A) |
| 1480 |
|
| 1481 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 1482 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 1483 |
|
| 1484 |
:type trace: str |
| 1485 |
:raises TypeError: Type isn't 'string' |
| 1486 |
:raises ValueError: Value is 'TRA' nor 'TRB' |
| 1487 |
""" |
| 1488 |
if not isinstance(trace, str): |
| 1489 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 1490 |
|
| 1491 |
if trace not in [e for e in Trace]: |
| 1492 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 1493 |
trace)) |
| 1494 |
|
| 1495 |
self.write("MINH %s" % trace) |
| 1496 |
|
| 1497 |
marker_amplitude = Instrument.measurement( |
| 1498 |
"MKA?", |
| 1499 |
""" |
| 1500 |
Get the amplitude of the active marker. If no marker is active, MKA |
| 1501 |
places a marker at the center of the trace and returns that amplitude value. |
| 1502 |
In the :meth:`amplitude_unit` unit. |
| 1503 |
|
| 1504 |
Type: :code:`float` |
| 1505 |
|
| 1506 |
.. code-block:: python |
| 1507 |
|
| 1508 |
level = instr.marker_amplitude |
| 1509 |
unit = instr.amplitude_unit |
| 1510 |
print("Level: %f %s" % (level, unit)) |
| 1511 |
|
| 1512 |
""" |
| 1513 |
) |
| 1514 |
|
| 1515 |
def set_marker_to_center_frequency(self): |
| 1516 |
"""Set the center frequency to the frequency value of an active |
| 1517 |
marker.""" |
| 1518 |
self.write("MKCF") |
| 1519 |
|
| 1520 |
marker_delta = Instrument.control( |
| 1521 |
"MKD?", "MKD %.11E Hz", |
| 1522 |
""" |
| 1523 |
Control a second marker on the trace. The parameter value specifies the distance |
| 1524 |
in frequency or time (when in zero span) between the two markers. |
| 1525 |
If queried - returns the frequency or time of the second marker. |
| 1526 |
|
| 1527 |
Type: :code:`float` |
| 1528 |
|
| 1529 |
.. code-block:: python |
| 1530 |
|
| 1531 |
# place second marker 1 MHz apart from the first marker |
| 1532 |
instr.marker_delta = 1e6 |
| 1533 |
|
| 1534 |
# print frequency of second marker in case it got moved automatically |
| 1535 |
print(instr.marker_delta) |
| 1536 |
|
| 1537 |
""" |
| 1538 |
) |
| 1539 |
|
| 1540 |
# the documentation mentions this command, but it doesn't work on my unit and a |
| 1541 |
# reference unit so I leave it here for reference but commented out |
| 1542 |
# |
| 1543 |
# marker_reciprocal = Instrument.control( |
| 1544 |
# "MKDR?", "MKDR %.11E", |
| 1545 |
# """ |
| 1546 |
# Return the reciprocal of the frequency or time (when in zero span) |
| 1547 |
# difference between two markers. |
| 1548 |
# """ |
| 1549 |
# ) |
| 1550 |
|
| 1551 |
marker_frequency = Instrument.control( |
| 1552 |
"MKF?", "MKF %.11E Hz", |
| 1553 |
""" |
| 1554 |
Control the frequency of the active marker. |
| 1555 |
Default units are in Hertz. |
| 1556 |
|
| 1557 |
Type: :code:`float` |
| 1558 |
|
| 1559 |
.. code-block:: python |
| 1560 |
|
| 1561 |
# place marker no. 1 at 100 MHz |
| 1562 |
instr.marker_frequency = 100e6 |
| 1563 |
|
| 1564 |
# print frequency of the marker in case it got moved automatically |
| 1565 |
print(instr.marker_frequency) |
| 1566 |
|
| 1567 |
""", |
| 1568 |
validator=strict_range, |
| 1569 |
values=[0, 1], |
| 1570 |
dynamic=True |
| 1571 |
) |
| 1572 |
|
| 1573 |
frequency_counter_mode_enabled = Instrument.setting( |
| 1574 |
"MKFC %s", |
| 1575 |
""" |
| 1576 |
Set the device into a frequency counter mode that counts the frequency of the active |
| 1577 |
marker or the difference in frequency between two markers. If no marker |
| 1578 |
is active, 'frequency_counter_mode_enabled' places a marker at the center of |
| 1579 |
the trace and counts that marker frequency. The frequency counter |
| 1580 |
provides a more accurate frequency reading; it pauses at the marker, |
| 1581 |
counts the value, then continues the sweep. To adjust the frequency |
| 1582 |
counter resolution, use the 'frequency_counter_resolution' command. To |
| 1583 |
return the counter value, use the 'marker_frequency' command. |
| 1584 |
|
| 1585 |
.. code-block:: python |
| 1586 |
|
| 1587 |
instr.frequency_counter_mode_enabled = True |
| 1588 |
""", |
| 1589 |
map_values=True, |
| 1590 |
values={True: "ON", False: "OFF"}, |
| 1591 |
validator=strict_discrete_set |
| 1592 |
) |
| 1593 |
|
| 1594 |
frequency_counter_resolution = Instrument.control( |
| 1595 |
"MKFCR?", "MKFCR %d Hz", |
| 1596 |
""" |
| 1597 |
Control the resolution of the frequency counter. Refer to the 'frequency_counter_mode' |
| 1598 |
command. The default value is 10 kHz. |
| 1599 |
|
| 1600 |
Type :code:`int` |
| 1601 |
|
| 1602 |
.. code-block:: python |
| 1603 |
|
| 1604 |
# activate frequency counter mode |
| 1605 |
instr.frequency_counter_mode = True |
| 1606 |
|
| 1607 |
# adjust resolution to 1 Hz |
| 1608 |
instr.frequency_counter_resolution = 1 |
| 1609 |
|
| 1610 |
if instr.frequency_counter_resolution: |
| 1611 |
pass |
| 1612 |
|
| 1613 |
""", |
| 1614 |
validator=strict_range, |
| 1615 |
values=[1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6], |
| 1616 |
maxsplit=0, |
| 1617 |
preprocess_reply=lambda v: str(int(float(v))), |
| 1618 |
cast=int |
| 1619 |
) |
| 1620 |
|
| 1621 |
def set_marker_minimum(self): |
| 1622 |
"""Place an active marker on the minimum signal detected on a trace.""" |
| 1623 |
self.write("MKMIN") |
| 1624 |
|
| 1625 |
# here would be the implementation of the command 'marker_normal' ('MKN') but |
| 1626 |
# it has no advantage over the 'marker_frequency' command except if no marker is active it |
| 1627 |
# places it automagically to the center of the trace (I think there's no sense in |
| 1628 |
# implementing it here) |
| 1629 |
|
| 1630 |
marker_noise_mode_enabled = Instrument.control( |
| 1631 |
"MKNOISE?", "MKNOISE %s", |
| 1632 |
""" |
| 1633 |
Control the detector mode to sample and compute the average of 32 data points (16 points |
| 1634 |
on one side of the marker, the marker itself, and 15 points on the other side of the |
| 1635 |
marker). This average is corrected for effects of the log or linear amplifier, bandwidth |
| 1636 |
shape factor, IF detector, and resolution bandwidth. If two markers are on (whether in |
| 1637 |
'marker_delta' mode or 1/marker delta mode), 'marker_noise_mode_enabled' works on the active |
| 1638 |
marker and not on the anchor marker. This allows you to measure signal-to-noise density |
| 1639 |
directly. To query the value, use the 'marker_amplitude' command. |
| 1640 |
|
| 1641 |
Type: :code:`bool` |
| 1642 |
|
| 1643 |
.. code-block:: python |
| 1644 |
|
| 1645 |
# activate signal-to-noise density mode |
| 1646 |
instr.marker_noise_mode_enabled = True |
| 1647 |
|
| 1648 |
# get noise density by `marker_amplitude` |
| 1649 |
print("Signal-to-noise density: %d dbm / Hz" % instr.marker_amplitude) |
| 1650 |
|
| 1651 |
""", |
| 1652 |
map_values=True, |
| 1653 |
values={True: "1", False: "0"}, |
| 1654 |
cast=str |
| 1655 |
) |
| 1656 |
|
| 1657 |
def deactivate_marker(self, all_markers=False): |
| 1658 |
"""Turn off the active marker or, if specified, turn off all markers. |
| 1659 |
|
| 1660 |
:param all_markers: If True the call deactivates all markers, if false only the currently |
| 1661 |
active marker (optional) |
| 1662 |
:type all_markers: bool |
| 1663 |
|
| 1664 |
.. code-block:: python |
| 1665 |
|
| 1666 |
# place first marker at 300 MHz |
| 1667 |
instr.marker_frequency = 300e6 |
| 1668 |
|
| 1669 |
# place second marker 2 MHz apart from first |
| 1670 |
instr.marker_delta = 2e6 |
| 1671 |
|
| 1672 |
# deactivate active marker (delta marker) |
| 1673 |
instr.deactivate_marker() |
| 1674 |
|
| 1675 |
# deactivate all markers |
| 1676 |
instr.deactivate_marker(all_markers=True) |
| 1677 |
""" |
| 1678 |
if all_markers: |
| 1679 |
self.write("MKOFF ALL") |
| 1680 |
else: |
| 1681 |
self.write("MKOFF") |
| 1682 |
|
| 1683 |
def search_peak(self, mode): |
| 1684 |
"""Place a marker on the highest point on a trace, the next-highest |
| 1685 |
point, the next-left peak, or the next-right peak. The default is 'HI' |
| 1686 |
(highest point). The trace peaks must meet the criteria of the marker |
| 1687 |
threshold and peak excursion functions in order for a peak to be found. |
| 1688 |
See also the :attr:`peak_threshold` and :attr:`peak_excursion` |
| 1689 |
commands. |
| 1690 |
|
| 1691 |
:param mode: Takes 'HI', 'NH', 'NR', 'NL' or the enumeration :class:`PeakSearchMode` |
| 1692 |
:type mode: str |
| 1693 |
|
| 1694 |
.. code-block:: python |
| 1695 |
|
| 1696 |
instr.search_peak('NL') |
| 1697 |
instr.search_peak(PeakSearchMode.NextHigh) |
| 1698 |
""" |
| 1699 |
if not isinstance(mode, str): |
| 1700 |
raise TypeError("Should be of type string but is '%s'" % type(mode)) |
| 1701 |
|
| 1702 |
if mode not in [e for e in PeakSearchMode]: |
| 1703 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 1704 |
([e for e in PeakSearchMode], mode)) |
| 1705 |
|
| 1706 |
self.write("MKPK %s" % mode) |
| 1707 |
|
| 1708 |
marker_threshold = Instrument.control( |
| 1709 |
"MKPT?", "MKPT %g {amplitude_unit}", |
| 1710 |
""" |
| 1711 |
Control the minimum amplitude level from which a peak on the trace can |
| 1712 |
be detected. The default value is -130 dBm. See also the :attr:`peak_excursion` command. |
| 1713 |
Any portion of a peak that falls below the peak threshold is used to satisfy the peak |
| 1714 |
excursion criteria. For example, a peak that is equal to 3 dB above the threshold when |
| 1715 |
the peak excursion is equal to 6 dB will be found if the peak extends an additional 3 dB |
| 1716 |
or more below the threshold level. Maximum 30 db to minimum -200 db. |
| 1717 |
|
| 1718 |
Type: :code:`signed int` |
| 1719 |
|
| 1720 |
.. code-block:: python |
| 1721 |
|
| 1722 |
instr.marker_threshold = -70 |
| 1723 |
if instr.marker_threshold > -80: |
| 1724 |
pass |
| 1725 |
|
| 1726 |
""", |
| 1727 |
validator=strict_range, |
| 1728 |
values=[-200, 30] |
| 1729 |
) |
| 1730 |
|
| 1731 |
peak_excursion = Instrument.control( |
| 1732 |
"MKPX?", "MKPX %g DB", |
| 1733 |
""" |
| 1734 |
Control what constitutes a peak on a trace. The chosen value specifies |
| 1735 |
the amount that a trace must increase monotonically, then decrease monotonically, in order |
| 1736 |
to be a peak. For example, if the peak excursion is 10 dB, the amplitude of the sides of a |
| 1737 |
candidate peak must descend at least 10 dB in order to be considered a peak (see Figure 5-4) |
| 1738 |
The default value is 6 dB. In linear mode, enter the marker peak excursion as a unit-less |
| 1739 |
number. |
| 1740 |
Any portion of a peak that falls below the peak threshold is also used to satisfy the peak |
| 1741 |
excursion criteria. For example, a peak that is equal to 3 dB above the threshold when the |
| 1742 |
peak excursion is equal to 6 dB will be found if the peak extends an additional 3 dB or more |
| 1743 |
below the threshold level. |
| 1744 |
|
| 1745 |
Type: :code:`float` |
| 1746 |
|
| 1747 |
.. code-block:: python |
| 1748 |
|
| 1749 |
instr.peak_excursion = 2 |
| 1750 |
if instr.peak_excursion == 2: |
| 1751 |
pass |
| 1752 |
|
| 1753 |
""", |
| 1754 |
validator=strict_range, |
| 1755 |
values=[0.1, 99] |
| 1756 |
) |
| 1757 |
|
| 1758 |
def set_marker_to_reference_level(self): |
| 1759 |
"""Set the reference level to the amplitude of an active marker. |
| 1760 |
|
| 1761 |
If no marker is active, 'marker_to_reference_level' places a |
| 1762 |
marker at the center of the trace and uses that marker amplitude |
| 1763 |
to set the reference level. |
| 1764 |
""" |
| 1765 |
self.write("MKRL") |
| 1766 |
|
| 1767 |
def set_marker_delta_to_span(self): |
| 1768 |
"""Set the frequency span equal to the frequency difference between two |
| 1769 |
markers on a trace. |
| 1770 |
|
| 1771 |
The start frequency is set equal to the frequency of the left- |
| 1772 |
most marker and the stop frequency is set equal to the frequency |
| 1773 |
of the right-most marker. |
| 1774 |
""" |
| 1775 |
self.write("MKSP") |
| 1776 |
|
| 1777 |
def set_marker_to_center_frequency_step_size(self): |
| 1778 |
"""Set the center frequency step-size equal to the frequency value of |
| 1779 |
the active marker.""" |
| 1780 |
self.write("MKSS") |
| 1781 |
|
| 1782 |
marker_time = Instrument.control( |
| 1783 |
"MKT?", "MKT %gS", |
| 1784 |
""" |
| 1785 |
Control the marker's time value. Default units are seconds. |
| 1786 |
|
| 1787 |
Type: :code:`float` |
| 1788 |
|
| 1789 |
.. code-block:: python |
| 1790 |
|
| 1791 |
# set marker at sweep time corresponding second two |
| 1792 |
instr.marker_time = 2 |
| 1793 |
|
| 1794 |
if instr.marker_time == 2: |
| 1795 |
pass |
| 1796 |
|
| 1797 |
""" |
| 1798 |
) |
| 1799 |
|
| 1800 |
marker_signal_tracking_enabled = Instrument.control( |
| 1801 |
"MKTRACK?", "MKTRACK %s", |
| 1802 |
""" |
| 1803 |
Control whether the center frequency follows the active marker. |
| 1804 |
|
| 1805 |
This is done after every sweep, thus maintaining the marker value at the |
| 1806 |
center frequency. This allows you to “zoom in” quickly from a wide span to a narrow one, |
| 1807 |
without losing the signal from the screen. Or, use 'marker_signal_tracking_enabled' to keep |
| 1808 |
a slowly drifting signal centered on the display. When this function is active, |
| 1809 |
a "K" appears on the left edge of the display. |
| 1810 |
|
| 1811 |
Type: :code:`bool` |
| 1812 |
""", |
| 1813 |
map_values=True, |
| 1814 |
validator=strict_discrete_set, |
| 1815 |
values={True: "1", False: "0"}, |
| 1816 |
cast=str |
| 1817 |
) |
| 1818 |
|
| 1819 |
mixer_level = Instrument.control( |
| 1820 |
"ML?", "ML %d DB", |
| 1821 |
""" |
| 1822 |
Control the maximum signal level that is at the input mixer. The |
| 1823 |
attenuator automatically adjusts to ensure that this level is not exceeded for signals less |
| 1824 |
than the reference level. From -80 to -10 DB. |
| 1825 |
|
| 1826 |
Type: :code:`int` |
| 1827 |
""", |
| 1828 |
validator=strict_range, |
| 1829 |
cast=int, |
| 1830 |
values=[-80, -10] |
| 1831 |
) |
| 1832 |
|
| 1833 |
def set_maximum_hold(self, trace): |
| 1834 |
"""Set the chosen trace with the maximum signal level detected at each |
| 1835 |
trace-data point from subsequent sweeps. This function employs the |
| 1836 |
positive peak detector (refer to the :attr:`detector_mode` command). |
| 1837 |
The detector mode can be changed, if desired, after max hold is |
| 1838 |
initialized. |
| 1839 |
|
| 1840 |
.. code-block:: python |
| 1841 |
|
| 1842 |
instr.maximum_hold('TRA') |
| 1843 |
instr.maximum_hold(Trace.A) |
| 1844 |
|
| 1845 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 1846 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 1847 |
|
| 1848 |
:type trace: str |
| 1849 |
:raises TypeError: Type isn't 'string' |
| 1850 |
:raises ValueError: Value is 'TRA' nor 'TRB' |
| 1851 |
""" |
| 1852 |
if not isinstance(trace, str): |
| 1853 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 1854 |
|
| 1855 |
if trace not in [e for e in Trace]: |
| 1856 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 1857 |
trace)) |
| 1858 |
|
| 1859 |
self.write("MXMH %s" % trace) |
| 1860 |
|
| 1861 |
normalize_trace_data_enabled = Instrument.control( |
| 1862 |
"NORMLIZE?", "NORMLIZE %s", |
| 1863 |
""" |
| 1864 |
Control the normalization routine for |
| 1865 |
stimulus-response measurements. This function subtracts trace B from trace A, offsets the |
| 1866 |
result by the value of the normalized reference position |
| 1867 |
(:attr:`normalized_reference_level`), and displays the result in trace A. |
| 1868 |
'normalize_trace_data_enabled' is intended for use with the :meth:`store_open` and |
| 1869 |
:meth:`store_short` or :meth:`store_thru` commands. These functions are used to store a |
| 1870 |
reference trace into trace B. |
| 1871 |
Refer to the respective command descriptions for more information. |
| 1872 |
Accurate normalization occurs only if the reference trace and the measured trace are |
| 1873 |
on-screen. If any of these traces are off-screen, an error message will be displayed. |
| 1874 |
If the error message ERR 903 A > DLMT is displayed, the range level (RL) can be adjusted |
| 1875 |
to move the measured response within the displayed measurement range of the analyzer. If |
| 1876 |
ERR 904 B > DLMT is displayed, the calibration is invalid and a thru or open/short |
| 1877 |
calibration must be performed. |
| 1878 |
If active (ON), the 'normalize_trace_data' command is automatically turned off with an |
| 1879 |
instrument preset (IP) or at power on. |
| 1880 |
|
| 1881 |
Type: :code:`bool` |
| 1882 |
""", |
| 1883 |
map_values=True, |
| 1884 |
validator=strict_discrete_set, |
| 1885 |
values={True: "1", False: "0"}, |
| 1886 |
cast=str |
| 1887 |
) |
| 1888 |
|
| 1889 |
normalized_reference_level = Instrument.control( |
| 1890 |
"NRL?", "NRL %d {amplitude_unit}", |
| 1891 |
""" |
| 1892 |
Control the normalized reference level. It is intended to be used with the |
| 1893 |
:attr:`normalize_trace_data` command. When using 'normalized_reference_level', the input |
| 1894 |
attenuator and IF step gains are not affected. This function is a trace-offset function |
| 1895 |
enabling the user to offset the displayed trace without introducing hardware-switching |
| 1896 |
errors into the stimulus-response measurement. The unit of measure for |
| 1897 |
'normalized_reference_level' is dB. In absolute power mode (dBm), reference level ( |
| 1898 |
:attr:`reference_level`) affects the gain and RF attenuation settings of the instrument, |
| 1899 |
which affects the measurement or dynamic range. In normalized mode |
| 1900 |
(relative power or dB-measurement mode), NRL offsets the trace data on-screen and does |
| 1901 |
not affect the instrument gain or attenuation settings. This allows the displayed |
| 1902 |
normalized trace to be moved without decreasing the measurement accuracy due to changes |
| 1903 |
in gain or RF attenuation. If the measurement range must be changed to bring trace data |
| 1904 |
on-screen, then the range level should be adjusted. Adjusting the range-level normalized |
| 1905 |
mode has the same effect on the instrument settings as does reference level in absolute |
| 1906 |
power mode (normalize off). |
| 1907 |
|
| 1908 |
Type: :code:`int` |
| 1909 |
|
| 1910 |
.. code-block:: python |
| 1911 |
|
| 1912 |
# reference level in case of normalization to -30 DB |
| 1913 |
instr.normalized_reference_level = -30 |
| 1914 |
|
| 1915 |
if instr.normalized_reference_level == -30: |
| 1916 |
pass |
| 1917 |
""", |
| 1918 |
validator=strict_range, |
| 1919 |
values=[-200, 30], |
| 1920 |
cast=int |
| 1921 |
) |
| 1922 |
|
| 1923 |
normalized_reference_position = Instrument.control( |
| 1924 |
"NRPOS?", "NRPOS %f DB", |
| 1925 |
""" |
| 1926 |
Control the normalized reference-position that corresponds to the |
| 1927 |
position on the graticule where the difference between the measured and calibrated traces |
| 1928 |
resides. The dB value of the normalized reference-position is equal to the normalized |
| 1929 |
reference level. The normalized reference-position may be adjusted between 0.0 and 10.0, |
| 1930 |
corresponding to the bottom and top graticule lines, respectively. |
| 1931 |
|
| 1932 |
Type: :code:`float` |
| 1933 |
|
| 1934 |
.. code-block:: python |
| 1935 |
|
| 1936 |
instr.normalized_reference_position = 5.5 |
| 1937 |
|
| 1938 |
if instr.normalized_reference_position == 5.5: |
| 1939 |
pass |
| 1940 |
""", |
| 1941 |
validator=strict_range, |
| 1942 |
values=[0.0, 10.0] |
| 1943 |
) |
| 1944 |
|
| 1945 |
display_parameters = Instrument.measurement( |
| 1946 |
"OP?", |
| 1947 |
""" |
| 1948 |
Get the location of the lower left (P1) and upper right (P2) vertices as a tuple of |
| 1949 |
the display window. |
| 1950 |
|
| 1951 |
Type: :code:`tuple` |
| 1952 |
|
| 1953 |
.. code-block:: python |
| 1954 |
|
| 1955 |
repr(instr.display_parameters) |
| 1956 |
(72, 16, 712, 766) |
| 1957 |
|
| 1958 |
""", |
| 1959 |
maxsplit=4, |
| 1960 |
cast=int, |
| 1961 |
get_process=tuple |
| 1962 |
) |
| 1963 |
|
| 1964 |
def plot(self, p1x, p1y, p2x, p2y): |
| 1965 |
"""Copies the specified display contents onto any HP-GL plotter. Set |
| 1966 |
the plotter address to 5, select the Pi and P2 positions, and then |
| 1967 |
execute the plot command. P1 and P2 correspond to the lower-left and |
| 1968 |
upper-right plotter positions, respectively. If P1 and P2 are not |
| 1969 |
specified, default values (either preloaded from power-up or sent in |
| 1970 |
via a previous plot command) are used. Once PLOT is executed, no |
| 1971 |
subsequent commands are executed until PLOT is done. |
| 1972 |
|
| 1973 |
:param p1x: plotter-dependent value that specify the lower-left plotter position x-axis |
| 1974 |
:type p1x: int |
| 1975 |
:param p1y: plotter-dependent value that specify the lower-left plotter position y-axis |
| 1976 |
:type p1y: int |
| 1977 |
:param p2x: plotter-dependent values that specify the upper-right plotter position x-axis |
| 1978 |
:type p2x: int |
| 1979 |
:param p2y: plotter-dependent values that specify the upper-right plotter position y-axis |
| 1980 |
:type p2y: int |
| 1981 |
""" |
| 1982 |
if not (isinstance(p1x, int) or isinstance(p1y, int) or isinstance(p2x, int) or |
| 1983 |
isinstance(p2y, int)): |
| 1984 |
raise TypeError("Should be of type int") |
| 1985 |
|
| 1986 |
self.write("PLOT %d,%d,%d,%d" % (p1x, p1y, p2x, p2y)) |
| 1987 |
|
| 1988 |
protect_state_enabled = Instrument.control( |
| 1989 |
"PSTATE?", "PSTATE %s", |
| 1990 |
""" |
| 1991 |
Control the storing of any new data in the state or trace registers. |
| 1992 |
If set to 'True', the registers are “locked”; the data in them cannot be erased or |
| 1993 |
overwritten, although the data can be recalled. To “unlock” the registers, and store new |
| 1994 |
data, set 'protect_state_enabled' to off by selecting 'False' as the parameter. |
| 1995 |
|
| 1996 |
Type: :code:`bool` |
| 1997 |
""", |
| 1998 |
map_values=True, |
| 1999 |
validator=strict_discrete_set, |
| 2000 |
values={True: "1", False: "0"}, |
| 2001 |
cast=str |
| 2002 |
) |
| 2003 |
|
| 2004 |
def get_power_bandwidth(self, trace, percent): |
| 2005 |
"""Measure the combined power of all signal responses contained in a |
| 2006 |
trace array. The command then computes the bandwidth equal to a |
| 2007 |
percentage of the total power. For example, if 100% is specified, the |
| 2008 |
power bandwidth equals the current frequency span. If 50% is specified, |
| 2009 |
trace elements are eliminated from either end of the array, until the |
| 2010 |
combined power of the remaining trace elements equals half of the total |
| 2011 |
power computed. The frequency span of these remaining trace elements is |
| 2012 |
the power bandwidth output to the controller. |
| 2013 |
|
| 2014 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 2015 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 2016 |
:param percent: Percentage of total power 0 ... 100 % |
| 2017 |
:type trace: str |
| 2018 |
:type percent: float |
| 2019 |
|
| 2020 |
.. code-block:: python |
| 2021 |
|
| 2022 |
# reset spectrum analyzer |
| 2023 |
instr.preset() |
| 2024 |
|
| 2025 |
# set to single sweep mode |
| 2026 |
instr.sweep_single() |
| 2027 |
|
| 2028 |
instr.center_frequency = 300e6 |
| 2029 |
instr.span = 1e6 |
| 2030 |
|
| 2031 |
instr.maximum_hold() |
| 2032 |
|
| 2033 |
instr.trigger_sweep() |
| 2034 |
|
| 2035 |
if instr.done: |
| 2036 |
pbw = instr.power_bandwidth(Trace.A, 99.0) |
| 2037 |
print("The power bandwidth at 99 percent is %f kHz" % (pbw / 1e3)) |
| 2038 |
""" |
| 2039 |
ran = np.arange(0, 100, 0.1) |
| 2040 |
|
| 2041 |
if not isinstance(trace, str): |
| 2042 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 2043 |
|
| 2044 |
if not isinstance(percent, float): |
| 2045 |
raise TypeError("Should be of type float but is '%s'" % type(percent)) |
| 2046 |
|
| 2047 |
if trace not in [e for e in Trace]: |
| 2048 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2049 |
([e for e in Trace], trace)) |
| 2050 |
|
| 2051 |
if percent not in ran: |
| 2052 |
raise ValueError("Only accepts values in the range of %s but was '%s'" % |
| 2053 |
(ran, percent)) |
| 2054 |
|
| 2055 |
return float(self.ask("PWRBW %s,%.1f?" % (trace, percent))) |
| 2056 |
|
| 2057 |
resolution_bandwidth = Instrument.control( |
| 2058 |
"RB?", "RB %s", |
| 2059 |
""" |
| 2060 |
Control the resolution bandwidth. This is normally a coupled function that |
| 2061 |
is selected according to the ratio selected by the RBR command. If no ratio is selected, a |
| 2062 |
default ratio (0.011) is used. The bandwidth, which ranges from 10 Hz to 2 MHz, may also be |
| 2063 |
selected manually. |
| 2064 |
|
| 2065 |
Type: :code:`str, dec` |
| 2066 |
""", |
| 2067 |
validator=joined_validators(strict_discrete_set, truncated_discrete_set), |
| 2068 |
values=[["AUTO", "MAN"], np.arange(10, 2e6)], |
| 2069 |
set_process=lambda v: v if isinstance(v, str) else f"{int(v)} Hz", |
| 2070 |
get_process=lambda v: v if isinstance(v, str) else int(v) |
| 2071 |
) |
| 2072 |
|
| 2073 |
resolution_bandwidth_to_span_ratio = Instrument.control( |
| 2074 |
"RBR?", "RBR %.3f", |
| 2075 |
""" |
| 2076 |
Control the coupling ratio between the resolution bandwidth and the |
| 2077 |
frequency span. When the frequency span is changed, the resolution bandwidth is changed |
| 2078 |
to satisfy the selected ratio. The ratio ranges from 0.002 to 0.10. The “UP” and “DN” |
| 2079 |
parameters adjust the ratio in a 1, 2, 5 sequence. The default ratio is 0.011. |
| 2080 |
""", |
| 2081 |
validator=strict_range, |
| 2082 |
values=np.arange(0.002, 0.10, 0.001) |
| 2083 |
) |
| 2084 |
|
| 2085 |
def recall_open_short_average(self): |
| 2086 |
"""Set the internally stored open/short average reference trace into |
| 2087 |
trace B. The instrument state is also set to the stored open/short |
| 2088 |
reference state. |
| 2089 |
|
| 2090 |
.. code-block:: python |
| 2091 |
|
| 2092 |
instr.preset() |
| 2093 |
instr.sweep_single() |
| 2094 |
instr.start_frequency = 300e3 |
| 2095 |
instr.stop_frequency = 1e9 |
| 2096 |
|
| 2097 |
instr.source_power_enabled = True |
| 2098 |
instr.sweep_couple = SweepCoupleMode.StimulusResponse |
| 2099 |
instr.source_peak_tracking() |
| 2100 |
|
| 2101 |
input("CONNECT OPEN. PRESS CONTINUE WHEN READY TO STORE.") |
| 2102 |
instr.trigger_sweep() |
| 2103 |
instr.done() |
| 2104 |
instr.store_open() |
| 2105 |
|
| 2106 |
input("CONNECT SHORT. PRESS CONTINUE WHEN READY TO STORE AND AVERAGE.") |
| 2107 |
instr.trigger_sweep() |
| 2108 |
instr.done() |
| 2109 |
instr.store_short() |
| 2110 |
|
| 2111 |
input("RECONNECT DUT. PRESS CONTINUE WHEN READY.") |
| 2112 |
instr.trigger_sweep() |
| 2113 |
instr.done() |
| 2114 |
|
| 2115 |
instr.normalize = True |
| 2116 |
|
| 2117 |
instr.trigger_sweep() |
| 2118 |
instr.done() |
| 2119 |
|
| 2120 |
instr.normalized_reference_position = 8 |
| 2121 |
instr.trigger_sweep() |
| 2122 |
|
| 2123 |
instr.preset() |
| 2124 |
# demonstrate recall of open/short average trace |
| 2125 |
instr.recall_open_short_average() |
| 2126 |
instr.trigger_sweep() |
| 2127 |
""" |
| 2128 |
self.write("RCLOSCAL") |
| 2129 |
|
| 2130 |
def recall_state(self, inp): |
| 2131 |
"""Set to the display a previously saved instrument state. See |
| 2132 |
:meth:`save_state`. |
| 2133 |
|
| 2134 |
:param inp: State to be recalled: either storage slot 0 ... 9 or 'LAST' or 'PWRON' |
| 2135 |
:param inp: str, int |
| 2136 |
|
| 2137 |
.. code-block:: python |
| 2138 |
|
| 2139 |
instr.save_state(7) |
| 2140 |
instr.preset() |
| 2141 |
instr.recall_state(7) |
| 2142 |
""" |
| 2143 |
values = ["LAST", "PWRON"] + [str(f) for f in range(0, 9)] |
| 2144 |
if not (isinstance(inp, str) or isinstance(inp, int)): |
| 2145 |
raise TypeError("Should be of type 'str' or 'int' but is '%s'" % type(inp)) |
| 2146 |
|
| 2147 |
if str(inp) not in values: |
| 2148 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2149 |
(values, str(inp))) |
| 2150 |
|
| 2151 |
self.write("RCLS %s" % str(inp)) |
| 2152 |
|
| 2153 |
def recall_trace(self, trace, number): |
| 2154 |
"""Recalls previously saved trace data to the display. See |
| 2155 |
:meth:`save_trace`. Either as Trace A or Trace B. |
| 2156 |
|
| 2157 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 2158 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 2159 |
:param number: Storage location from 0 ... 7 where to store the trace |
| 2160 |
:type trace: str |
| 2161 |
:type number: int |
| 2162 |
|
| 2163 |
.. code-block:: python |
| 2164 |
|
| 2165 |
instr.preset() |
| 2166 |
instr.center_frequency = 300e6 |
| 2167 |
instr.span = 20e6 |
| 2168 |
|
| 2169 |
instr.save_trace(Trace.A, 7) |
| 2170 |
instr.preset() |
| 2171 |
|
| 2172 |
# reload - at 7 stored trace - to Trace B |
| 2173 |
instr.recall_trace(Trace.B, 7) |
| 2174 |
""" |
| 2175 |
ran = range(0, 7) |
| 2176 |
if not isinstance(trace, str): |
| 2177 |
raise TypeError("Should be of type str but is '%s'" % type(trace)) |
| 2178 |
|
| 2179 |
if not isinstance(number, int): |
| 2180 |
raise TypeError("Should be of type int but is '%s'" % type(number)) |
| 2181 |
|
| 2182 |
if trace not in [e for e in Trace]: |
| 2183 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2184 |
([e for e in Trace], trace)) |
| 2185 |
|
| 2186 |
if number not in ran: |
| 2187 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2188 |
(ran, number)) |
| 2189 |
|
| 2190 |
self.write("RCLT %s,%s" % (trace, number)) |
| 2191 |
|
| 2192 |
def recall_thru(self): |
| 2193 |
"""Recalls the internally stored thru-reference trace into trace B. |
| 2194 |
|
| 2195 |
The instrument state is also set to the stored thru-reference |
| 2196 |
state. |
| 2197 |
""" |
| 2198 |
self.write("RCLTHRU") |
| 2199 |
|
| 2200 |
firmware_revision = Instrument.measurement( |
| 2201 |
"REV?", |
| 2202 |
""" |
| 2203 |
Get the revision date code of the spectrum analyzer firmware. |
| 2204 |
|
| 2205 |
Type: :code:`datetime.date` |
| 2206 |
""", |
| 2207 |
get_process=lambda v: datetime.strptime(v, '%y%m%d').date(), |
| 2208 |
cast=str |
| 2209 |
) |
| 2210 |
|
| 2211 |
reference_level = Instrument.control( |
| 2212 |
"RL?", "RL %g {amplitude_unit}", |
| 2213 |
""" |
| 2214 |
Control the reference level, or range level when in normalized mode. (Range level |
| 2215 |
functions the same as reference level.) The reference level is the top horizontal line on |
| 2216 |
the graticule. For best measurement accuracy, place the peak of a signal of interest on the |
| 2217 |
reference-level line. The spectrum analyzer input attenuator is coupled to the reference |
| 2218 |
level and automatically adjusts to avoid compression of the input signal. Refer also to |
| 2219 |
:attr:`amplitude_unit`. Minimum reference level is -120.0 dBm or 2.2 uV |
| 2220 |
|
| 2221 |
Type: :code:`float` |
| 2222 |
""" |
| 2223 |
) |
| 2224 |
|
| 2225 |
reference_level_calibration = Instrument.control( |
| 2226 |
"RLCAL?", "RLCAL %g", |
| 2227 |
""" |
| 2228 |
Control the calibration of the reference level remotely and retuns the |
| 2229 |
current calibration. To calibrate the reference level, connect the 300 MHz calibration |
| 2230 |
signal to the RF input. Set the center frequency to 300 MHz, the frequency span to 20 |
| 2231 |
MHz, and the reference level to -10 dBm. Use the RLCAL command to move the input signal |
| 2232 |
to the reference level. When the signal peak falls directly on the reference-level line, |
| 2233 |
the reference level is calibrated. Storing this value in the analyzer in EEROM can be |
| 2234 |
done only from the front panel. The RLCAL command, when queried, returns the current value. |
| 2235 |
|
| 2236 |
Type: :code:`float` |
| 2237 |
|
| 2238 |
.. code-block:: python |
| 2239 |
|
| 2240 |
# connect cal signal to rf input |
| 2241 |
instr.preset() |
| 2242 |
instr.amplitude_unit = AmplitudeUnits.DBM |
| 2243 |
instr.center_frequency = 300e6 |
| 2244 |
instr.span = 100e3 |
| 2245 |
instr.reference_level = 0 |
| 2246 |
instr.trigger_sweep() |
| 2247 |
|
| 2248 |
instr.peak_search(PeakSearchMode.High) |
| 2249 |
level = instr.marker_amplitude |
| 2250 |
rlcal = instr.reference_level_calibration - int((level + 10) / 0.17) |
| 2251 |
instr.reference_level_calibration = rlcal |
| 2252 |
""", |
| 2253 |
cast=int, |
| 2254 |
validator=strict_range, |
| 2255 |
values=[-33, 33] |
| 2256 |
) |
| 2257 |
|
| 2258 |
reference_offset = Instrument.control( |
| 2259 |
"ROFFSET?", "ROFFSET %d DB", |
| 2260 |
""" |
| 2261 |
Control an offset applied to all amplitude readouts (for example, the |
| 2262 |
reference level and marker amplitude). The offset is in dB, regardless of the selected scale |
| 2263 |
and units. The offset can be useful to account for gains of losses in accessories connected |
| 2264 |
to the input of the analyzer. When this function is active, an "R" appears on the left |
| 2265 |
edge of the display. |
| 2266 |
|
| 2267 |
Type: :code:`int` |
| 2268 |
""", |
| 2269 |
cast=int, |
| 2270 |
values=[-100, 100], |
| 2271 |
validator=strict_range |
| 2272 |
) |
| 2273 |
|
| 2274 |
request_service_conditions = Instrument.control( |
| 2275 |
"RQS?", "RQS %d", |
| 2276 |
""" |
| 2277 |
Control a bit mask that specifies which service requests can interrupt |
| 2278 |
a program sequence. |
| 2279 |
|
| 2280 |
.. code-block:: python |
| 2281 |
|
| 2282 |
instr.request_service_conditions = StatusRegister.ERROR_PRESENT | StatusRegister.TRIGGER |
| 2283 |
|
| 2284 |
print(instr.request_service_conditions) |
| 2285 |
StatusRegister.ERROR_PRESENT|TRIGGER |
| 2286 |
""", |
| 2287 |
get_process=lambda v: StatusRegister(int(v)) |
| 2288 |
) |
| 2289 |
|
| 2290 |
def save_state(self, inp): |
| 2291 |
"""Saves the currently displayed instrument state in the specified |
| 2292 |
state register. |
| 2293 |
|
| 2294 |
:param inp: State to be recalled: either storage slot 0 ... 9 or 'LAST' or 'PWRON' |
| 2295 |
:param inp: str, int |
| 2296 |
|
| 2297 |
.. code-block:: python |
| 2298 |
|
| 2299 |
instr.preset() |
| 2300 |
instr.center_frequency = 300e6 |
| 2301 |
instr.span = 20e6 |
| 2302 |
instr.save_state("PWRON") |
| 2303 |
""" |
| 2304 |
values = ["PWRON"] + [str(f) for f in range(0, 9)] |
| 2305 |
if not (isinstance(inp, str) or isinstance(inp, int)): |
| 2306 |
raise TypeError("Should be of type 'str' or 'int' but is '%s'" % type(inp)) |
| 2307 |
|
| 2308 |
if str(inp) not in values: |
| 2309 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2310 |
(values, str(inp))) |
| 2311 |
|
| 2312 |
self.write("SAVES %s" % str(inp)) |
| 2313 |
|
| 2314 |
def save_trace(self, trace, number): |
| 2315 |
"""Saves the selected trace in the specified trace register. |
| 2316 |
|
| 2317 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 2318 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 2319 |
:param number: Storage location from 0 ... 7 where to store the trace |
| 2320 |
:type trace: str |
| 2321 |
:type number: int |
| 2322 |
|
| 2323 |
.. code-block:: python |
| 2324 |
|
| 2325 |
instr.preset() |
| 2326 |
instr.center_frequency = 300e6 |
| 2327 |
instr.span = 20e6 |
| 2328 |
|
| 2329 |
instr.save_trace(Trace.A, 7) |
| 2330 |
instr.preset() |
| 2331 |
|
| 2332 |
# reload - at 7 stored trace - to Trace B |
| 2333 |
instr.recall_trace(Trace.B, 7) |
| 2334 |
""" |
| 2335 |
ran = range(0, 7) |
| 2336 |
if not isinstance(trace, str): |
| 2337 |
raise TypeError("Should be of type str but is '%s'" % type(trace)) |
| 2338 |
|
| 2339 |
if not isinstance(number, int): |
| 2340 |
raise TypeError("Should be of type int but is '%s'" % type(number)) |
| 2341 |
|
| 2342 |
if trace not in [e for e in Trace]: |
| 2343 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2344 |
([e for e in Trace], trace)) |
| 2345 |
|
| 2346 |
if number not in ran: |
| 2347 |
raise ValueError("Only accepts values of [%s] but was '%s'" % |
| 2348 |
(ran, number)) |
| 2349 |
|
| 2350 |
self.write("SAVET %s,%s" % (trace, number)) |
| 2351 |
|
| 2352 |
serial_number = Instrument.measurement( |
| 2353 |
"SER?", |
| 2354 |
""" |
| 2355 |
Get the spectrum analyzer serial number. |
| 2356 |
""", |
| 2357 |
cast=str |
| 2358 |
) |
| 2359 |
|
| 2360 |
def sweep_single(self): |
| 2361 |
"""Sets the spectrum analyzer into single-sweep mode. |
| 2362 |
|
| 2363 |
This mode allows only one sweep when trigger conditions are met. |
| 2364 |
When this function is active, an 'S' appears on the left edge of |
| 2365 |
the display. |
| 2366 |
""" |
| 2367 |
self.write("SNGLS") |
| 2368 |
|
| 2369 |
span = Instrument.control( |
| 2370 |
"SP?", "SP %s", |
| 2371 |
""" |
| 2372 |
Control the frequency span. The center frequency does not change with |
| 2373 |
changes in the frequency span; start and stop frequencies do change. Setting the frequency |
| 2374 |
span to 0 Hz effectively allows an amplitude-versus-time mode in which to view signals. This |
| 2375 |
is especially useful for viewing modulation. Querying SP will leave the analyzer in center |
| 2376 |
frequency /span mode. |
| 2377 |
""", |
| 2378 |
validator=joined_validators(strict_discrete_set, strict_range), |
| 2379 |
values=[["FULL", "ZERO"], [float("-inf"), float("inf")]], |
| 2380 |
set_process=lambda v: v if isinstance(v, str) else "%.11E Hz" % v, |
| 2381 |
get_process=lambda v: v if isinstance(v, str) else v |
| 2382 |
) |
| 2383 |
|
| 2384 |
squelch = Instrument.control( |
| 2385 |
"SQUELCH?", "SQUELCH %s", |
| 2386 |
""" |
| 2387 |
Control the squelch level for demodulation. When this function is |
| 2388 |
on, a dashed line indicating the squelch level appears on the display. |
| 2389 |
A marker must be active and above the squelch line for demodulation to occur. Refer to |
| 2390 |
the :attr:`demodulation_mode` command. The default value is -120 dBm. |
| 2391 |
|
| 2392 |
Type: :code:`str,int` |
| 2393 |
|
| 2394 |
.. code-block:: python |
| 2395 |
|
| 2396 |
instr.preset() |
| 2397 |
instr.start_frequency = 88e6 |
| 2398 |
instr.stop_frequency = 108e6 |
| 2399 |
|
| 2400 |
instr.peak_search(PeakSearchMode.High) |
| 2401 |
instr.demodulation_time = 10 |
| 2402 |
|
| 2403 |
instr.squelch = -60 |
| 2404 |
instr.demodulation_mode = DemodulationMode.FM |
| 2405 |
""", |
| 2406 |
validator=joined_validators(strict_discrete_set, strict_range), |
| 2407 |
values=[["ON", "OFF"], range(-220, 30)], |
| 2408 |
set_process=lambda v: v if isinstance(v, str) else f"{v} {{amplitude_unit}}" |
| 2409 |
) |
| 2410 |
|
| 2411 |
squelch_enabled = Instrument.setting( |
| 2412 |
"SQUELCH %s", |
| 2413 |
""" |
| 2414 |
Set squelch for demodulation active or inactive. For further information see :attr:`squelch` |
| 2415 |
""", |
| 2416 |
map_values=True, |
| 2417 |
values={True: "ON", False: "OFF"}, |
| 2418 |
validator=strict_discrete_set |
| 2419 |
) |
| 2420 |
|
| 2421 |
def request_service(self, input): |
| 2422 |
"""Triggers a service request. This command allows you to force a |
| 2423 |
service request and test a program designed to handle service requests. |
| 2424 |
However, the service request can be triggered only if it is first |
| 2425 |
masked using the :attr:`request_service_conditions` command. |
| 2426 |
|
| 2427 |
:param input: Bits to emulate a service request |
| 2428 |
:type input: :class:`StatusRegister` |
| 2429 |
""" |
| 2430 |
if input not in range(0, 255): |
| 2431 |
raise ValueError("Bit mask needs to be between 0 ... 255") |
| 2432 |
|
| 2433 |
self.write("SRQ %d" % input) |
| 2434 |
|
| 2435 |
# `center_frequency_step_size` would be a command but is pretty unnecesary |
| 2436 |
|
| 2437 |
sweep_time = Instrument.control( |
| 2438 |
"ST?", "ST %s", |
| 2439 |
""" |
| 2440 |
Control the sweep time. This is normally a coupled function which is |
| 2441 |
automatically set to the optimum value allowed by the current instrument settings. |
| 2442 |
Alternatively, you may specify the sweep time. Note that when the specified sweep time is |
| 2443 |
too fast for the current instrument settings, the instrument is no longer calibrated and the |
| 2444 |
message 'MEAS UNCAL' appears on the display. The sweep time cannot be adjusted when the |
| 2445 |
resolution bandwidth is set to 10 Hz, 30 Hz, or 100 Hz. |
| 2446 |
|
| 2447 |
Type: :code:`str, float` |
| 2448 |
|
| 2449 |
Real from 50E—3 to 100 when the span is greater than 0 Hz; 50E—6 to 60 when |
| 2450 |
the span equals 0 Hz. When the resolution bandwidth is <100 Hz, the sweep time |
| 2451 |
cannot be adjusted. |
| 2452 |
""", |
| 2453 |
validator=joined_validators(strict_discrete_set, strict_range), |
| 2454 |
values=[["AUTO", "MAN"], np.arange(50E-6, 100)], |
| 2455 |
set_process=lambda v: v if isinstance(v, str) else ("%.3f S" % v) |
| 2456 |
) |
| 2457 |
|
| 2458 |
status = Instrument.measurement( |
| 2459 |
"STB?", |
| 2460 |
""" |
| 2461 |
Get the decimal equivalent of the bits set in the |
| 2462 |
status byte (see the RQS and SRQ commands). STB is equivalent to a serial poll command. |
| 2463 |
The RQS and associated bits are cleared in the same way that a serial poll command would |
| 2464 |
clear them. |
| 2465 |
""", |
| 2466 |
get_process=lambda v: StatusRegister(int(v)) |
| 2467 |
) |
| 2468 |
|
| 2469 |
def store_open(self): |
| 2470 |
"""Save the current instrument state and trace A into nonvolatile |
| 2471 |
memory. |
| 2472 |
|
| 2473 |
This command must be used in conjunction with the |
| 2474 |
:meth:`store_short` command and must precede the |
| 2475 |
:meth:`store_short` command. The data obtained during the store |
| 2476 |
open procedure is averaged with the data obtained during the |
| 2477 |
:meth:`store_short` procedure to provide an open/short |
| 2478 |
calibration. The instrument state (that is, instrument settings) |
| 2479 |
must not change between the :meth:`store_open` and |
| 2480 |
:meth:`store_short` operations in order for the open/short |
| 2481 |
calibration to be valid. Refer to the :meth:`store_short` |
| 2482 |
command description for more information. |
| 2483 |
""" |
| 2484 |
self.write("STOREOPEN") |
| 2485 |
|
| 2486 |
def store_short(self): |
| 2487 |
"""Take currently displayed trace A data and averages this data with |
| 2488 |
previously stored open data, and stores it in trace B. |
| 2489 |
|
| 2490 |
This command is used in conjunction with the :meth:`store_open` |
| 2491 |
command and must be preceded by it for proper operation. Refer |
| 2492 |
to the :meth:`store_open` command description for more |
| 2493 |
information. The state of the open/short average trace is stored |
| 2494 |
in state register #8. |
| 2495 |
""" |
| 2496 |
self.write("STORESHORT") |
| 2497 |
|
| 2498 |
def store_thru(self): |
| 2499 |
"""Store a thru-calibration trace into trace B and into the nonvolatile |
| 2500 |
memory of the spectrum analyzer. |
| 2501 |
|
| 2502 |
The state of the thru information is stored in state register |
| 2503 |
#9. |
| 2504 |
""" |
| 2505 |
self.write("STORETHRU") |
| 2506 |
|
| 2507 |
sweep_couple = Instrument.control( |
| 2508 |
"SWPCPL?", "SWPCPL %s", |
| 2509 |
""" |
| 2510 |
Control the sweep couple mode which is either a stimulus-response or spectrum-analyzer |
| 2511 |
auto-coupled sweep time. In stimulus-response mode, auto-coupled sweep times are usually |
| 2512 |
much faster for swept-response measurements. Stimulus-response auto-coupled sweep times |
| 2513 |
are typicallly valid in stimulus-response measurements when the system’s frequency span is |
| 2514 |
less than 20 times the bandwidth of the device under test. |
| 2515 |
|
| 2516 |
Type: :code:`str` or :class:`SweepCoupleMode` |
| 2517 |
""", |
| 2518 |
validator=strict_discrete_set, |
| 2519 |
values=[e for e in SweepCoupleMode] |
| 2520 |
) |
| 2521 |
|
| 2522 |
sweep_output = Instrument.control( |
| 2523 |
"SWPOUT?", "SWPOUT %s", |
| 2524 |
""" |
| 2525 |
Control the sweep-related signal that is available from J8 on the rear |
| 2526 |
panel. FAV provides a dc ramp of 0.5V/GHz. RAMP provides a 0—10 V ramp corresponding |
| 2527 |
to the sweep ramp that tunes the first local oscillator (LO). For the HP 8561B, in multiband |
| 2528 |
sweeps one ramp is provided for each frequency band. |
| 2529 |
|
| 2530 |
Type: :code:`str` or :class:`SweepOut` |
| 2531 |
""", |
| 2532 |
validator=strict_discrete_set, |
| 2533 |
values=[e for e in SweepOut] |
| 2534 |
) |
| 2535 |
|
| 2536 |
trace_data_format = Instrument.control( |
| 2537 |
"TDF?", "TDF %s", |
| 2538 |
""" |
| 2539 |
Control the format used to input and output trace data (see the |
| 2540 |
TRA/TRB command, You must specify the desired format when |
| 2541 |
transferring data from the spectrum analyzer to a computer; this is optional when |
| 2542 |
transferring data to the analyzer. |
| 2543 |
|
| 2544 |
Type: :code:`str` or :class:`TraceDataFormat` |
| 2545 |
|
| 2546 |
.. warning:: |
| 2547 |
Only needed for manual read out of trace data. Don't use this if you don't know what |
| 2548 |
You are doing. |
| 2549 |
""", |
| 2550 |
validator=strict_discrete_set, |
| 2551 |
values=[e for e in TraceDataFormat] |
| 2552 |
) |
| 2553 |
|
| 2554 |
threshold = Instrument.control( |
| 2555 |
"TH?", "TH %.2E {amplitude_unit}", |
| 2556 |
""" |
| 2557 |
Control the minimum amplitude level and clips data at this value. Default |
| 2558 |
value is -90 dBm. See also - :attr:`marker_threshold` does not clip data below its threshold |
| 2559 |
|
| 2560 |
Type: :code:`str, float` range -200 to 30 |
| 2561 |
|
| 2562 |
.. note:: |
| 2563 |
When a trace is in max-hold mode, if the threshold is raised above any of the |
| 2564 |
trace data, the data below the threshold will be permanently lost. |
| 2565 |
""", |
| 2566 |
validator=strict_discrete_set, |
| 2567 |
values=np.arange(-200, 30), |
| 2568 |
) |
| 2569 |
|
| 2570 |
threshold_enabled = Instrument.setting( |
| 2571 |
"TH %s", |
| 2572 |
""" |
| 2573 |
Set the threshold active or inactive. See :attr:`threshold` |
| 2574 |
""", |
| 2575 |
map_values=True, |
| 2576 |
values={True: "ON", False: "OFF"}, |
| 2577 |
validator=strict_discrete_set |
| 2578 |
) |
| 2579 |
|
| 2580 |
def set_title(self, string): |
| 2581 |
"""Sets character data in the title area of the display, which is in |
| 2582 |
the upper-right corner. |
| 2583 |
|
| 2584 |
A title can be up to two rows of sixteen characters each, Carriage |
| 2585 |
return and line feed characters are not allowed. |
| 2586 |
""" |
| 2587 |
if not isinstance(string, str): |
| 2588 |
raise TypeError("Parameter should be of type 'str'") |
| 2589 |
|
| 2590 |
if len(string) > 32: |
| 2591 |
raise ValueError("Title should have maximum 32 chars but has '%d'" % len(string)) |
| 2592 |
|
| 2593 |
self.write("TITLE@%s@" % string) |
| 2594 |
|
| 2595 |
trigger_mode = Instrument.control( |
| 2596 |
"TM?", "TM %s", |
| 2597 |
""" |
| 2598 |
Control the trigger mode. Selected trigger conditions must be met in order for |
| 2599 |
a sweep to occur. For the available modes refer to :class:`TriggerMode`. |
| 2600 |
When any trigger mode other than free run is selected, |
| 2601 |
a "T" appears on the left edge of the display. |
| 2602 |
""", |
| 2603 |
validator=strict_discrete_set, |
| 2604 |
values=[e for e in TriggerMode] |
| 2605 |
) |
| 2606 |
|
| 2607 |
def _get_trace_data(self, trace): |
| 2608 |
self.write("TDF M") |
| 2609 |
|
| 2610 |
amp_units = str(self.ask("AUNITS?")) |
| 2611 |
ref_lvl = float(self.ask("RL?")) |
| 2612 |
log_scale = float(self.ask("LG?")) |
| 2613 |
|
| 2614 |
cmd_str = "" |
| 2615 |
if trace is Trace.A: |
| 2616 |
cmd_str += "TRA?" |
| 2617 |
elif trace is Trace.B: |
| 2618 |
cmd_str += "TRB?" |
| 2619 |
|
| 2620 |
values = self.values(cmd_str, cast=int) |
| 2621 |
|
| 2622 |
if amp_units is AmplitudeUnits.W: |
| 2623 |
# calculate dbm from watts |
| 2624 |
ref_lvl = (10 * log10(ref_lvl)) + 30 |
| 2625 |
elif amp_units is AmplitudeUnits.DBUV: |
| 2626 |
# calculate dbm from dbuv in 50 Ohm system |
| 2627 |
ref_lvl = ref_lvl - 107 |
| 2628 |
elif amp_units is AmplitudeUnits.V: |
| 2629 |
# calculate dbm from volts in 50 Ohm system |
| 2630 |
ref_lvl = 20 * log10((ref_lvl / 0.05) ** 0.5) |
| 2631 |
elif amp_units is AmplitudeUnits.DBMV: |
| 2632 |
# calculate dbm from dbmv |
| 2633 |
ref_lvl = ref_lvl - 46.9897 |
| 2634 |
|
| 2635 |
result_values = [] |
| 2636 |
for value in values: |
| 2637 |
if log_scale != 0: |
| 2638 |
result_value = round(ref_lvl + (log_scale * ((value - 600) / 60)), 2) |
| 2639 |
result_values.append(result_value) |
| 2640 |
else: |
| 2641 |
raise NotImplementedError("Linear scaling isn't supported by get_trace_data_ ") |
| 2642 |
|
| 2643 |
return result_values |
| 2644 |
|
| 2645 |
def get_trace_data_a(self): |
| 2646 |
""" |
| 2647 |
Get the data of trace A as a list. |
| 2648 |
|
| 2649 |
The function returns the 601 data points as a list in the amplitude format. |
| 2650 |
Right now it doesn't support the linear scaling due to the manual just being wrong. |
| 2651 |
""" |
| 2652 |
return self._get_trace_data(Trace.A) |
| 2653 |
|
| 2654 |
def get_trace_data_b(self): |
| 2655 |
""" |
| 2656 |
Get the data of trace B as a list. |
| 2657 |
|
| 2658 |
The function returns the 601 data points as a list in the amplitude format. |
| 2659 |
Right now it doesn't support the linear scaling due to the manual just being wrong. |
| 2660 |
""" |
| 2661 |
return self._get_trace_data(Trace.B) |
| 2662 |
|
| 2663 |
set_trace_data_a = Instrument.setting( |
| 2664 |
"TDF P;TRA %s", |
| 2665 |
""" |
| 2666 |
Set the trace data of trace A. |
| 2667 |
|
| 2668 |
.. warning:: |
| 2669 |
|
| 2670 |
The string based method this attribute is using takes its time. Something around 5000ms |
| 2671 |
timeout at the adapter seems to work well. |
| 2672 |
""", |
| 2673 |
set_process=lambda v: (','.join([str(i) for i in v])), |
| 2674 |
) |
| 2675 |
|
| 2676 |
set_trace_data_b = Instrument.setting( |
| 2677 |
"TDF P;TRB %s", |
| 2678 |
""" |
| 2679 |
Set the trace data of trace B also allows to write the data. |
| 2680 |
|
| 2681 |
.. warning:: |
| 2682 |
|
| 2683 |
The string based method this attribute is using takes its time. Something around 5000ms |
| 2684 |
timeout at the adapter seems to work well. |
| 2685 |
""", |
| 2686 |
set_process=lambda v: (','.join([str(i) for i in v])) |
| 2687 |
) |
| 2688 |
|
| 2689 |
def trigger_sweep(self): |
| 2690 |
"""Command the spectrum analyzer to take one full sweep across the trace display. |
| 2691 |
Commands following TS are not executed until after the analyzer has finished the trace |
| 2692 |
sweep. This ensures that the instrument is set to a known condition before subsequent |
| 2693 |
commands are executed. |
| 2694 |
""" |
| 2695 |
self.write("TS") |
| 2696 |
|
| 2697 |
def create_fft_trace_window(self, trace, window_mode): |
| 2698 |
"""Creates a window trace array for the fast Fourier transform (FFT) function. |
| 2699 |
|
| 2700 |
The trace-window function creates a trace array according to three built-in |
| 2701 |
algorithms: UNIFORM, HANNING, and FLATTOP. When used with the FFT command, |
| 2702 |
the three algorithms give resultant passband shapes that represent a compromise among |
| 2703 |
amplitude uncertainty, sensitivity, and frequency resolution. Refer to the FFT command |
| 2704 |
description for more information. |
| 2705 |
|
| 2706 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 2707 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 2708 |
:type trace: str |
| 2709 |
:param window_mode: A representation of the window mode, either from :class:`WindowType` or |
| 2710 |
use 'HANNING', 'FLATTOP' or 'UNIFORM' |
| 2711 |
:type window_mode: str |
| 2712 |
""" |
| 2713 |
|
| 2714 |
if not isinstance(trace, str): |
| 2715 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 2716 |
|
| 2717 |
if trace not in [e for e in Trace]: |
| 2718 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 2719 |
trace)) |
| 2720 |
|
| 2721 |
if not isinstance(window_mode, str): |
| 2722 |
raise TypeError("Should be of type string but is '%s'" % type(window_mode)) |
| 2723 |
|
| 2724 |
if window_mode not in [e for e in WindowType]: |
| 2725 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in |
| 2726 |
WindowType], |
| 2727 |
window_mode)) |
| 2728 |
|
| 2729 |
self.write("TWNDOW %s,%s" % (trace, window_mode)) |
| 2730 |
|
| 2731 |
video_average = Instrument.control( |
| 2732 |
"VAVG?", "VAVG %d", |
| 2733 |
""" |
| 2734 |
Control the video averaging function. Video averaging smooths the |
| 2735 |
displayed trace without using a narrow bandwidth. 'video_average' sets the IF detector to |
| 2736 |
sample mode (see the DET command) and smooths the trace by averaging successive traces |
| 2737 |
with each other. If desired, you can change the detector mode during video averaging. |
| 2738 |
Video averaging is available only for trace A, and trace A must be in clear-write mode for |
| 2739 |
'video_average' to operate. After 'video_average' is executed, the number of sweeps that |
| 2740 |
have been averaged appears at the top of the analyzer screen. Using video averaging |
| 2741 |
allows you to view changes to the entire trace much faster than using narrow video |
| 2742 |
filters. Narrow video filters require long sweep times, which may not be desired. Video |
| 2743 |
averaging, though requiring more sweeps, uses faster sweep times; in some cases, it can |
| 2744 |
produce a smooth trace as fast as a video filter. |
| 2745 |
|
| 2746 |
Type: :code:`str, int` |
| 2747 |
""", |
| 2748 |
validator=strict_range, |
| 2749 |
values=np.arange(1, 999), |
| 2750 |
cast=int |
| 2751 |
) |
| 2752 |
|
| 2753 |
video_average_enabled = Instrument.setting( |
| 2754 |
"VAVG %s", |
| 2755 |
""" |
| 2756 |
Set the video averaging either active or inactive. See :attr:`video_average` |
| 2757 |
""", |
| 2758 |
map_values=True, |
| 2759 |
values={True: "ON", False: "OFF"}, |
| 2760 |
validator=strict_discrete_set |
| 2761 |
) |
| 2762 |
|
| 2763 |
video_bandwidth = Instrument.control( |
| 2764 |
"VB?", "VB %s", |
| 2765 |
""" |
| 2766 |
Control the video bandwidth. This is normally a coupled function that |
| 2767 |
is selected according to the ratio selected by the VBR command. (If no ratio is selected, |
| 2768 |
a default ratio, 1.0, is used instead.) Video bandwidth filters (or smooths) post-detected |
| 2769 |
video information. The bandwidth, which ranges from 1 Hz to 3 MHz, may also be selected |
| 2770 |
manually. If the specified video bandwidth is less than 300 Hz and the resolution bandwidth |
| 2771 |
is greater than or equal to 300 Hz, the IF detector is set to sample mode. Reducing the |
| 2772 |
video bandwidth or increasing the number of video averages will usually smooth the trace |
| 2773 |
by about as much for the same total measurement time. Reducing the video bandwidth to |
| 2774 |
one-third or less of the resolution bandwidth is desirable when the number of video |
| 2775 |
averages is above 25. For the case where the number of video averages is very large, and |
| 2776 |
the video bandwidth is equal to the resolution bandwidth, internal mathematical limitations |
| 2777 |
allow about 0.4 dB overresponse to noise on the logarithmic scale. The overresponse is |
| 2778 |
negligible (less than 0.1 dB) for narrower video bandwidths. |
| 2779 |
|
| 2780 |
Type: :code:`int` |
| 2781 |
""", |
| 2782 |
validator=joined_validators(strict_discrete_set, strict_range), |
| 2783 |
values=[["AUTO", "MAN"], np.arange(1, 3e6)], |
| 2784 |
cast=int, |
| 2785 |
set_process=lambda v: v if isinstance(v, str) else f"{v} Hz" |
| 2786 |
) |
| 2787 |
|
| 2788 |
video_bandwidth_to_resolution_bandwidth = Instrument.control( |
| 2789 |
"VBR?", "VBR %.3f", |
| 2790 |
""" |
| 2791 |
Control the coupling ratio between the video bandwidth and the |
| 2792 |
resolution bandwidth. Thus, when the resolution bandwidth is changed, the video bandwidth |
| 2793 |
changes to satisfy the ratio. The ratio ranges from 0.003 to 3 in a 1, 3, 10 sequence. The |
| 2794 |
default ratio is 1. When a new ratio is selected, the video bandwidth changes to satisfy the |
| 2795 |
new ratio—the resolution bandwidth does not change value. |
| 2796 |
""", |
| 2797 |
validator=strict_range, |
| 2798 |
values=np.arange(0.002, 0.10, 0.001) |
| 2799 |
) |
| 2800 |
|
| 2801 |
def view_trace(self, trace): |
| 2802 |
"""Display the current contents of the selected trace, but does not update |
| 2803 |
the contents. View mode may be executed before a sweep is complete when :meth:`sweep_single` |
| 2804 |
and :meth:`trigger_sweep` are not used. |
| 2805 |
|
| 2806 |
:param trace: A representation of the trace, either from :class:`Trace` or |
| 2807 |
use 'TRA' for Trace A or 'TRB' for Trace B |
| 2808 |
:type trace: str |
| 2809 |
:raises TypeError: Type isn't 'string' |
| 2810 |
:raises ValueError: Value is 'TRA' nor 'TRB' |
| 2811 |
""" |
| 2812 |
if not isinstance(trace, str): |
| 2813 |
raise TypeError("Should be of type string but is '%s'" % type(trace)) |
| 2814 |
|
| 2815 |
if trace not in [e for e in Trace]: |
| 2816 |
raise ValueError("Only accepts values of [%s] but was '%s'" % ([e for e in Trace], |
| 2817 |
trace)) |
| 2818 |
self.write("VIEW " + trace) |
| 2819 |
|
| 2820 |
video_trigger_level = Instrument.control( |
| 2821 |
"VTL?", "VTL %.3f {amplitude_unit}", |
| 2822 |
""" |
| 2823 |
Control the video trigger level when the trigger mode is set to VIDEO (refer |
| 2824 |
to the :attr:`trigger_mode` command). A dashed line appears on the display to indicate the |
| 2825 |
level. The default value is 0 dBm. Range -220 to 30. |
| 2826 |
|
| 2827 |
Type: :code:`float` |
| 2828 |
""", |
| 2829 |
validator=strict_range, |
| 2830 |
values=[-220, 30] |
| 2831 |
) |
| 2832 |
|
| 2833 |
|
| 2834 |
class HP8560A(HP856Xx): |
| 2835 |
"""Represents the HP 8560A Spectrum Analyzer and provides a high-level |
| 2836 |
interface for interacting with the instrument. |
| 2837 |
|
| 2838 |
.. code-block:: python |
| 2839 |
|
| 2840 |
from pymeasure.instruments.hp import HP8560A |
| 2841 |
from pymeasure.instruments.hp.hp856Xx import AmplitudeUnits |
| 2842 |
|
| 2843 |
sa = HP8560A("GPIB::1") |
| 2844 |
|
| 2845 |
sa.amplitude_unit = AmplitudeUnits.DBUV |
| 2846 |
sa.start_frequency = 299.5e6 |
| 2847 |
sa.stop_frequency = 300.5e6 |
| 2848 |
|
| 2849 |
print(sa.marker_amplitude) |
| 2850 |
""" |
| 2851 |
|
| 2852 |
# HP8560A is able to go up to 2.9 GHz |
| 2853 |
MAX_FREQUENCY = 2.9e9 |
| 2854 |
|
| 2855 |
def __init__(self, adapter, name="Hewlett-Packard HP8560A", **kwargs): |
| 2856 |
super().__init__( |
| 2857 |
adapter, |
| 2858 |
name, |
| 2859 |
**kwargs, |
| 2860 |
) |
| 2861 |
|
| 2862 |
self.center_frequency_values = [0, self.MAX_FREQUENCY] |
| 2863 |
self.start_frequency_values = [0, self.MAX_FREQUENCY] |
| 2864 |
self.stop_frequency_values = [0, self.MAX_FREQUENCY] |
| 2865 |
self.frequency_offset_values = [0, self.MAX_FREQUENCY] |
| 2866 |
self.marker_frequency_values = [0, self.MAX_FREQUENCY] |
| 2867 |
self.span_values = [["FULL", "ZERO"], [0, self.MAX_FREQUENCY]] |
| 2868 |
|
| 2869 |
source_leveling_control = Instrument.control( |
| 2870 |
"SRCALC?", "SRCALC %s", |
| 2871 |
""" |
| 2872 |
Control if internal or external leveling is used with the |
| 2873 |
built-in tracking generator. |
| 2874 |
Takes either 'INT', 'EXT' or members of enumeration :class:`SourceLevelingControlMode` |
| 2875 |
|
| 2876 |
Type: :code:`str` |
| 2877 |
|
| 2878 |
.. code-block:: python |
| 2879 |
|
| 2880 |
instr.preset() |
| 2881 |
instr.sweep_single() |
| 2882 |
instr.center_frequency = 300e6 |
| 2883 |
instr.span = 1e6 |
| 2884 |
|
| 2885 |
instr.source_power = -5 |
| 2886 |
|
| 2887 |
instr.trigger_sweep() |
| 2888 |
instr.source_leveling_control = SourceLevelingControlMode.External |
| 2889 |
|
| 2890 |
if ErrorCode(900) in instr.errors: |
| 2891 |
print("UNLEVELED CONDITION. CHECK LEVELING LOOP.") |
| 2892 |
|
| 2893 |
.. note:: |
| 2894 |
Only available with an HP 8560A Option 002. |
| 2895 |
""", |
| 2896 |
validator=strict_discrete_set, |
| 2897 |
values=[e for e in SourceLevelingControlMode] |
| 2898 |
) |
| 2899 |
|
| 2900 |
tracking_adjust_coarse = Instrument.control( |
| 2901 |
"SRCCRSTK?", "SRCCRSTK %d", |
| 2902 |
""" |
| 2903 |
Control the coarse adjustment to the frequency of the built-in |
| 2904 |
tracking-generator oscillator. Once enabled, this adjustment is made in |
| 2905 |
digital-to-analogconverter (DAC) values from 0 to 255. For fine adjustment, refer to the |
| 2906 |
:attr:`tracking_adjust_fine` command description. |
| 2907 |
|
| 2908 |
Type: :code:`int` |
| 2909 |
|
| 2910 |
.. note:: |
| 2911 |
Only available with an HP 8560A Option 002. |
| 2912 |
""", |
| 2913 |
validator=strict_range, |
| 2914 |
values=[0, 255], |
| 2915 |
cast=int |
| 2916 |
) |
| 2917 |
|
| 2918 |
tracking_adjust_fine = Instrument.control( |
| 2919 |
"SRCFINTK?", "SRCFINTK %d", |
| 2920 |
""" |
| 2921 |
Control the fine adjustment of the frequency of the built-in |
| 2922 |
tracking-generator oscillator. Once enabled, this adjustment is made in |
| 2923 |
digital-to-analogconverter (DAC) values from 0 to 255. For coarse adjustment, refer to |
| 2924 |
the :attr:`tracking_adjust_coarse` command description. |
| 2925 |
|
| 2926 |
Type: :code:`int` |
| 2927 |
|
| 2928 |
.. note:: |
| 2929 |
Only available with an HP 8560A Option 002. |
| 2930 |
""", |
| 2931 |
validator=strict_range, |
| 2932 |
values=[0, 255], |
| 2933 |
cast=int |
| 2934 |
) |
| 2935 |
|
| 2936 |
source_power_offset = Instrument.control( |
| 2937 |
"SRCPOFS?", "SRCPOFS %g {amplitude_unit}", |
| 2938 |
""" |
| 2939 |
Control the offset of the displayed power of the built-in tracking generator so that |
| 2940 |
it is equal to the measured power at the input of the spectrum analyzer. This function may |
| 2941 |
be used to take into account system losses (for example, cable loss) or gains (for example, |
| 2942 |
preamplifier gain) reflecting the actual power delivered to the device under test. |
| 2943 |
|
| 2944 |
Type: :code:`int` |
| 2945 |
|
| 2946 |
.. note:: |
| 2947 |
Only available with an HP 8560A Option 002. |
| 2948 |
""", |
| 2949 |
validator=strict_range, |
| 2950 |
values=[-100, 100], |
| 2951 |
cast=int |
| 2952 |
) |
| 2953 |
|
| 2954 |
source_power_step = Instrument.control( |
| 2955 |
"SRCPSTP?", "SRCPSTP %.2f DB", |
| 2956 |
""" |
| 2957 |
Control the step size of the source power level, source power offset, and |
| 2958 |
power-sweep range functions. Range: 0.1 ... 12.75 DB with 0.05 steps. |
| 2959 |
|
| 2960 |
Type: :code:`float` |
| 2961 |
|
| 2962 |
.. note:: |
| 2963 |
Only available with an HP 8560A Option 002. |
| 2964 |
""", |
| 2965 |
validator=strict_range, |
| 2966 |
values=np.arange(0.1, 12.75, 0.05) |
| 2967 |
) |
| 2968 |
|
| 2969 |
source_power_sweep = Instrument.control( |
| 2970 |
"SRCPSWP?", "SRCPSWP %.2f DB", |
| 2971 |
""" |
| 2972 |
Control the power-sweep function, where the |
| 2973 |
output power of the tracking generator is swept over the power-sweep range chosen. The |
| 2974 |
starting source power level is set using the :attr:`source_power` command. The output power |
| 2975 |
of the tracking generator is swept according to the sweep rate of the spectrum analyzer. |
| 2976 |
|
| 2977 |
Type: :code:`str, float` |
| 2978 |
|
| 2979 |
.. note:: |
| 2980 |
Only available with an HP 8560A Option 002. |
| 2981 |
""", |
| 2982 |
validator=truncated_discrete_set, |
| 2983 |
values=np.arange(0.1, 12.75, 0.05), |
| 2984 |
) |
| 2985 |
|
| 2986 |
source_power_sweep_enabled = Instrument.setting( |
| 2987 |
"SRCPSWP %s", |
| 2988 |
""" |
| 2989 |
Set the power sweep active or inactive. See :attr:`source_power_sweep`. |
| 2990 |
""", |
| 2991 |
map_values=True, |
| 2992 |
values={True: "ON", False: "OFF"}, |
| 2993 |
validator=strict_discrete_set |
| 2994 |
) |
| 2995 |
|
| 2996 |
source_power = Instrument.control( |
| 2997 |
"SRCPWR?", "SRCPWR %s", |
| 2998 |
""" |
| 2999 |
Control the built-in tracking generator's output power. |
| 3000 |
|
| 3001 |
Type: :code:`str, float` |
| 3002 |
|
| 3003 |
.. note:: |
| 3004 |
Only available with an HP 8560A Option 002. |
| 3005 |
""", |
| 3006 |
validator=joined_validators(strict_discrete_set, truncated_discrete_set), |
| 3007 |
values=[["OFF", "ON"], np.arange(-10, 2.8, 0.05)], |
| 3008 |
set_process=lambda v: v if isinstance(v, str) else ("%.2f {amplitude_unit}" % v) |
| 3009 |
) |
| 3010 |
|
| 3011 |
source_power_enabled = Instrument.setting( |
| 3012 |
"SRCPWR %s", |
| 3013 |
""" |
| 3014 |
Set the built-in tracking generator on or off. See :attr:`source_power` |
| 3015 |
""", |
| 3016 |
map_values=True, |
| 3017 |
values={True: "ON", False: "OFF"}, |
| 3018 |
validator=strict_discrete_set |
| 3019 |
) |
| 3020 |
|
| 3021 |
def activate_source_peak_tracking(self): |
| 3022 |
"""Activate a routine which automatically adjusts both the coarse and |
| 3023 |
fine-tracking adjustments to obtain the peak response of the tracking |
| 3024 |
generator on the spectrum-analyzer display. Tracking peak is not |
| 3025 |
necessary for resolution bandwidths greater than or equal to 300 kHz. A |
| 3026 |
thru connection should be made prior to peaking in order to ensure |
| 3027 |
accuracy. |
| 3028 |
|
| 3029 |
.. note:: |
| 3030 |
Only available with an HP 8560A Option 002. |
| 3031 |
""" |
| 3032 |
self.write("SRCTKPK") |
| 3033 |
|
| 3034 |
|
| 3035 |
class HP8561B(HP856Xx): |
| 3036 |
"""Represents the HP 8561B Spectrum Analyzer and provides a high-level |
| 3037 |
interface for interacting with the instrument. |
| 3038 |
|
| 3039 |
.. code-block:: python |
| 3040 |
|
| 3041 |
from pymeasure.instruments.hp import 8561B |
| 3042 |
from pymeasure.instruments.hp.hp856Xx import AmplitudeUnits |
| 3043 |
|
| 3044 |
sa = HP8560A("GPIB::1") |
| 3045 |
|
| 3046 |
sa.amplitude_unit = AmplitudeUnits.DBUV |
| 3047 |
sa.start_frequency = 6.4e9 |
| 3048 |
sa.stop_frequency = 6.5e9 |
| 3049 |
|
| 3050 |
print(sa.marker_amplitude) |
| 3051 |
""" |
| 3052 |
|
| 3053 |
# HP8561B is able to go up to 6.5 GHz |
| 3054 |
MAX_FREQUENCY = 6.5e9 |
| 3055 |
|
| 3056 |
def __init__(self, adapter, name="Hewlett-Packard HP8561B", **kwargs): |
| 3057 |
super().__init__( |
| 3058 |
adapter, |
| 3059 |
name, |
| 3060 |
**kwargs, |
| 3061 |
) |
| 3062 |
|
| 3063 |
self.center_frequency_values = [0, self.MAX_FREQUENCY] |
| 3064 |
self.start_frequency_values = [0, self.MAX_FREQUENCY] |
| 3065 |
self.stop_frequency_values = [0, self.MAX_FREQUENCY] |
| 3066 |
self.frequency_offset_values = [0, self.MAX_FREQUENCY] |
| 3067 |
self.marker_frequency_values = [0, self.MAX_FREQUENCY] |
| 3068 |
self.span_values = [["FULL", "ZERO"], [0, self.MAX_FREQUENCY]] |
| 3069 |
|
| 3070 |
conversion_loss = Instrument.control( |
| 3071 |
"CNVLOSS?", "CNVLOSS %s DB", |
| 3072 |
""" |
| 3073 |
Control the compensation for losses outside the instrument when in external |
| 3074 |
mixer mode (such as losses within connector cables, external mixers, etc.). |
| 3075 |
'conversion_loss' specifies the mean conversion loss for the current harmonic band. |
| 3076 |
In a full frequency band (such as band K), the mean conversion loss is defined as the |
| 3077 |
minimum loss plus the maximum loss for that band divided by two. |
| 3078 |
Adjusting for conversion loss allows the system to remain |
| 3079 |
calibrated (that is, the displayed amplitude values have the conversion loss incorporated |
| 3080 |
into them). The default value for any band is 30 dB. The spectrum analyzer must be in |
| 3081 |
external-mixer mode in order for this command to work. When in internal-mixer mode, |
| 3082 |
querying 'conversion_loss' returns a zero. |
| 3083 |
""", |
| 3084 |
validator=strict_range, |
| 3085 |
values=[0, float("inf")] |
| 3086 |
) |
| 3087 |
|
| 3088 |
def set_fullband(self, band): |
| 3089 |
"""Select a commonly-used, external-mixer frequency band, as shown in |
| 3090 |
the table. The harmonic lock function :attr:`harmonic_number_lock` is |
| 3091 |
also set; this locks the harmonic of the chosen band. External-mixing |
| 3092 |
functions are not available with an HP 8560A Option 002. Takes |
| 3093 |
frequency band letter as string. |
| 3094 |
|
| 3095 |
.. list-table:: Title |
| 3096 |
:widths: 25 25 25 25 |
| 3097 |
:header-rows: 1 |
| 3098 |
|
| 3099 |
* - Frequency Band |
| 3100 |
- Frequency Range (GHz) |
| 3101 |
- Mixing Harmonic |
| 3102 |
- Conversion Loss |
| 3103 |
* - K |
| 3104 |
- 18.0 — 26.5 |
| 3105 |
- 6 |
| 3106 |
- 30 dB |
| 3107 |
* - A |
| 3108 |
- 26.5 — 40.0 |
| 3109 |
- 8 |
| 3110 |
- 30 dB |
| 3111 |
* - Q |
| 3112 |
- 33.0—50.0 |
| 3113 |
- 10 |
| 3114 |
- 30 dB |
| 3115 |
* - U |
| 3116 |
- 40.0—60.0 |
| 3117 |
- 10 |
| 3118 |
- 30 dB |
| 3119 |
* - V |
| 3120 |
- 50.0—75.0 |
| 3121 |
- 14 |
| 3122 |
- 30 dB |
| 3123 |
* - E |
| 3124 |
- 60.0—-90.0 |
| 3125 |
- 16 |
| 3126 |
- 30 dB |
| 3127 |
* - W |
| 3128 |
- 75.0—110.0 |
| 3129 |
- 18 |
| 3130 |
- 30 dB |
| 3131 |
* - F |
| 3132 |
- 90.0—140.0 |
| 3133 |
- 24 |
| 3134 |
- 30 dB |
| 3135 |
* - D |
| 3136 |
- 110.0—170.0 |
| 3137 |
- 30 |
| 3138 |
- 30 dB |
| 3139 |
* - G |
| 3140 |
- 140.0—220.0 |
| 3141 |
- 36 |
| 3142 |
- 30 dB |
| 3143 |
* - Y |
| 3144 |
- 170.0—260.0 |
| 3145 |
- 44 |
| 3146 |
- 30 dB |
| 3147 |
* - J |
| 3148 |
- 220.0—325.0 |
| 3149 |
- 54 |
| 3150 |
- 30 dB |
| 3151 |
""" |
| 3152 |
frequency_mapping = { |
| 3153 |
"K": [18e9, 26.5e9], |
| 3154 |
"A": [26.5e9, 40e9], |
| 3155 |
"Q": [33e9, 50e9], |
| 3156 |
"U": [40e9, 60e9], |
| 3157 |
"V": [50e9, 75e9], |
| 3158 |
"E": [60e9, 90e9], |
| 3159 |
"W": [75e9, 110e9], |
| 3160 |
"F": [90e9, 140e9], |
| 3161 |
"D": [110e9, 170e9], |
| 3162 |
"G": [140e9, 220e9], |
| 3163 |
"Y": [170e9, 260e9], |
| 3164 |
"J": [220e9, 325e9], |
| 3165 |
} |
| 3166 |
|
| 3167 |
if not isinstance(band, str): |
| 3168 |
raise TypeError("Frequency band should be of type string but is '%s'" % type(band)) |
| 3169 |
|
| 3170 |
if band not in frequency_mapping.keys(): |
| 3171 |
raise ValueError("Should be one of the available bands but is '%s'" % band) |
| 3172 |
|
| 3173 |
self.center_frequency_values = frequency_mapping[band] |
| 3174 |
self.start_frequency_values = frequency_mapping[band] |
| 3175 |
self.stop_frequency_values = frequency_mapping[band] |
| 3176 |
|
| 3177 |
self.write("FULLBAND %s" % band) |
| 3178 |
|
| 3179 |
harmonic_number_lock = Instrument.control( |
| 3180 |
"HNLOCK?", "HNLOCK %d", |
| 3181 |
""" |
| 3182 |
Control the lock to a chosen harmonic so only that harmonic is used to sweep |
| 3183 |
an external frequency band. To select a frequency band, use the 'fullband' command; it |
| 3184 |
selects an appropriate harmonic for the desired band. To change the harmonic number, use |
| 3185 |
'harmonic_number_lock'. |
| 3186 |
Note that 'harmonic_number_lock' also works in internal-mixing modes. |
| 3187 |
Once 'fullband' or 'harmonic_number_lock' are set, only center frequencies and spans that |
| 3188 |
fall within the frequency band of the current harmonic may be entered. When the |
| 3189 |
'set_full_span' command is activated, the span is limited to the frequency band of the |
| 3190 |
selected harmonic. |
| 3191 |
""", |
| 3192 |
validator=strict_range, |
| 3193 |
values=[1, 54], |
| 3194 |
cast=int |
| 3195 |
) |
| 3196 |
|
| 3197 |
harmonic_number_lock_enabled = Instrument.setting( |
| 3198 |
"HNLOCK %s", |
| 3199 |
""" |
| 3200 |
Set the harmonic number locking active or inactive. See :attr:`harmonic_number_lock`. |
| 3201 |
""", |
| 3202 |
map_values=True, |
| 3203 |
values={True: "ON", False: "OFF"}, |
| 3204 |
validator=strict_discrete_set |
| 3205 |
) |
| 3206 |
|
| 3207 |
def unlock_harmonic_number(self): |
| 3208 |
"""Unlock the harmonic number, allowing you to select frequencies and |
| 3209 |
spans outside the range of the locked harmonic number. |
| 3210 |
|
| 3211 |
Also, when HNUNLK is executed, more than one harmonic can then |
| 3212 |
be used to sweep across a desired span. For example, sweep a |
| 3213 |
span from 18 GHz to 40 GHz. In this case, the analyzer will |
| 3214 |
automatically sweep first using 6—, then using 8—. |
| 3215 |
""" |
| 3216 |
self.write("HUNLK") |
| 3217 |
|
| 3218 |
def set_signal_identification_to_center_frequency(self): |
| 3219 |
"""Set the center frequency to the frequency obtained from the command |
| 3220 |
SIGID. |
| 3221 |
|
| 3222 |
SIGID must be in AUTO mode and have found a valid result for |
| 3223 |
this command to execute properly. Use SIGID on signals greater |
| 3224 |
than 18 GHz {i.e., in external mixing mode). SIGID and IDCF may |
| 3225 |
also be used on signals less than 6.5 GHz in an HP 8561B. |
| 3226 |
""" |
| 3227 |
self.write("IDCF") |
| 3228 |
|
| 3229 |
signal_identification_frequency = Instrument.measurement( |
| 3230 |
"IDFREQ?", |
| 3231 |
""" |
| 3232 |
Measure the frequency of the last identified signal. After an instrument preset or an |
| 3233 |
invalid signal identification, IDFREQ returns a “0”. |
| 3234 |
""" |
| 3235 |
) |
| 3236 |
|
| 3237 |
mixer_bias = Instrument.control( |
| 3238 |
"MBIAS?", "MBIAS %.3f MA", |
| 3239 |
""" |
| 3240 |
Set the bias for an external mixer that requires diode bias for efficient |
| 3241 |
mixer operation. The bias, which is provided on the center conductor of the IF input, is |
| 3242 |
activated when MBIAS is executed. A "+" or "—" appears on the left edge of the spectrum |
| 3243 |
analyzer display, indicating that positive or negative bias is on. When the bias is |
| 3244 |
turned off, MBIAS is set to 0. Default units are in milliamps. |
| 3245 |
""", |
| 3246 |
validator=strict_range, |
| 3247 |
values=[float(-10E3), int(10E3)], |
| 3248 |
cast=float |
| 3249 |
) |
| 3250 |
|
| 3251 |
mixer_bias_enabled = Instrument.setting( |
| 3252 |
"MBIAS %s", |
| 3253 |
""" |
| 3254 |
Control the bias for an external mixer. See :attr:`mixer_bias`. |
| 3255 |
""", |
| 3256 |
map_values=True, |
| 3257 |
values={True: "ON", False: "OFF"}, |
| 3258 |
validator=strict_discrete_set |
| 3259 |
) |
| 3260 |
|
| 3261 |
mixer_mode = Instrument.control( |
| 3262 |
"MXRMODE?", "MXRMODE %s", |
| 3263 |
""" |
| 3264 |
Control the mixer mode. Select either the internal mixer |
| 3265 |
or supply an external mixer. Takes enum 'MixerMode' or string 'INT', 'EXT' |
| 3266 |
""", |
| 3267 |
validator=strict_discrete_set, |
| 3268 |
values=[e for e in MixerMode] |
| 3269 |
) |
| 3270 |
|
| 3271 |
def peak_preselector(self): |
| 3272 |
"""Peaks the preselector in the HP 8561B Spectrum Analyzer. |
| 3273 |
|
| 3274 |
Make sure the entire frequency span is in high band, set the |
| 3275 |
desired trace to clear-write mode, place a marker on a desired |
| 3276 |
signal, then execute PP. The peaking routine zooms to zero span, |
| 3277 |
peaks the preselector tracking, then returns to the original |
| 3278 |
position. To read the new preselector peaking number, use the |
| 3279 |
PSDAC command. Commands following PP are not executed until |
| 3280 |
after the analyzer has finished peaking the preselector. |
| 3281 |
""" |
| 3282 |
self.write("PP") |
| 3283 |
|
| 3284 |
preselector_dac_number = Instrument.control( |
| 3285 |
"PSDAC?", "PSDAC %d", |
| 3286 |
""" |
| 3287 |
Control the preselector peak DAC number. For use with an |
| 3288 |
HP 8561B Spectrum Analyzer. |
| 3289 |
|
| 3290 |
Type: :code:`int` |
| 3291 |
""", |
| 3292 |
cast=int, |
| 3293 |
validator=strict_range, |
| 3294 |
values=[0, 255] |
| 3295 |
) |
| 3296 |
|
| 3297 |
signal_identification = Instrument.control( |
| 3298 |
"SIGID?", "SIGID %s", |
| 3299 |
""" |
| 3300 |
Control the signal identification for identifying signals for the external |
| 3301 |
mixing frequency bands. |
| 3302 |
Two signal identification methods are available. AUTO employs the image response method |
| 3303 |
for locating correct mixer responses. Place a marker on the desired signal, then activate |
| 3304 |
signal_identification = 'AUTO'. The frequency of a correct response appears in the active |
| 3305 |
function block. Use this mode before executing the |
| 3306 |
:meth:`signal_identification_to_center_frequency` command. The second method of signal |
| 3307 |
identification, 'MAN', shifts responses both horizontally and vertically. A correct |
| 3308 |
response is shifted horizontally by less than 80 kHz. To ensure accuracy in MAN mode, |
| 3309 |
limit the frequency span to less than 20 MHz. |
| 3310 |
Where True = manual mode is active and False = auto mode is active or |
| 3311 |
'signal_identification' is off. |
| 3312 |
""", |
| 3313 |
map_values=True, |
| 3314 |
validator=strict_discrete_set, |
| 3315 |
values={True: "1", False: "0", "AUTO": "AUTO", "MAN": "MAN"}, |
| 3316 |
cast=str |
| 3317 |
) |