Debian Codegraph @

pymeasure/instruments/hp/hp437b.py

raw
1 from pymeasure.instruments import Instrument
2 from pymeasure.instruments.validators import strict_discrete_set, strict_range
3 from enum import IntEnum, IntFlag
4
5 import logging
6
7 log = logging.getLogger(__name__)
8 log.addHandler(logging.NullHandler())
9
10
11 class MeasurementUnit(IntEnum):
12 """Enumeration to represent the measurement unit the power meter will measure in"""
13
14 WATTS = 0
15
16 DBM = 1
17
18 PERCENT = 2
19
20 DB = 3
21
22
23 class SensorType(IntEnum):
24 """Enumeration to represent the selected sensor type for the power meter"""
25
26 #: Default (100% for all frequencies)
27 DEFAULT = 0
28
29 HP_8481A = 1
30
31 #: HP 8482A, 8482B, 8482H
32 HP_8482X = 2
33
34 HP_8483A = 3
35
36 HP_8481D = 4
37
38 HP_8485A = 5
39
40 HP_R8486A = 6
41
42 HP_Q8486A = 7
43
44 HP_R8486D = 8
45
46 HP_8487A = 9
47
48
49 class OperatingMode(IntEnum):
50 """Enumeration to represent the operating mode the power meter is currently in"""
51
52 NORMAL = 0
53
54 ZEROING = 6
55
56 CALIBRATION = 8
57
58
59 class TriggerMode(IntEnum):
60 """Enumeration to represent the trigger mode the power meter is currently in"""
61
62 HOLD = 0
63
64 FREE_RUNNING = 3
65
66
67 class GroupTriggerMode(IntEnum):
68 """Enumeration to represent the group execute trigger mode the power meter is currently in"""
69
70 IGNORE = 0
71
72 TRIGGER_IMMEDIATE = 1
73
74 TRIGGER_DELAY = 2
75
76
77 class EventStatusRegister(IntFlag):
78 """Enumeration to represent the Event Status Register."""
79
80 #: The bit is set when the power meter's LINE switch is set from STDBY to ON
81 POWER_ON = 128
82
83 #: This bit is set when an incorrect HP-IB code is sent to the power meter. For example,
84 # the command “QX” is a command error.
85 COMMAND_ERROR = 32
86
87 #: This bit is set when incorrect data is sent to the power meter. For example, the command
88 # “FR-3GZ” is an execution error.
89 EXECUTION_ERROR = 16
90
91 #: This bit is set true whenever a measurement error (error 1-49) occurs.
92 DEVICE_DEPENDENT_ERROR = 8
93
94
95 Errors = {
96 1: "Power meter cannot zero the sensor",
97 5: "Power meter cannot calibrate sensor",
98 11: "Input overload on sensor",
99 15: "Sensor’s zero reference has drifted negative",
100 17: "Input power on sensor is too high for current range",
101 21: "Power reading over high limit",
102 23: "Power reading under low limit",
103 31: "No sensor connected to the input",
104 33: "Both front and rear sensor inputs, have sensors connected (Option 002 or Option 003 only)",
105 50: "Entered cal factor is out of range",
106 51: "Entered offset is out of range",
107 52: "Entered range number is out of range",
108 54: "Entered recall register number is out of range",
109 55: "Entered storage register number is out of range",
110 56: "Entered reference cal factor is out of range",
111 57: "RAM ID check failure",
112 61: "Stack RAM failure",
113 62: "ROM checksum failure",
114 64: "RAM failure",
115 65: "Analog I/O PIA Failure",
116 66: "Keyboard and Display PIA Failure",
117 67: "Analog-to-Digital converter Failure",
118 68: "HP-IB failure",
119 69: "Timer failure",
120 70: "Keyboard/Display controller failure",
121 71: "Keyboard data failure",
122 72: "Data line to A3U26 is open.",
123 73: "Keyboard/Display controller self-test failure",
124 74: "Display not responding",
125 75: "Digital failure",
126 }
127
128
129 class StatusMessage:
130 MeasurementErrorCode = (0, 1)
131 EntryErrorCode = (2, 2)
132 OperatingMode = (4, 2)
133 AutomaticRangeStatus = (6, 1)
134 Range = (7, 1)
135 # 8, 9 unused
136 AutoFilterStatus = (10, 1)
137 Filter = (11, 1)
138 # 12, 13 unused
139 LinearLogStatus = (14, 1)
140 # A
141 PowerRefStatus = (16, 1)
142 RelativeModeStatus = (17, 1)
143 TriggerMode = (18, 1)
144 GroupTriggerMode = (19, 1)
145 LimitsCheckingStatus = (20, 1)
146 LimitsStatus = (21, 1)
147 # 22 unused
148 OffsetStatus = (23, 1)
149 DutyCycleStatus = (24, 1)
150 MeasurementUnits = (25, 1)
151
152
153 def _getstatus(status_type, modifier=lambda v: v):
154 start_index, stop_offset = status_type
155 return lambda v: modifier(int(v[start_index:start_index + stop_offset]))
156
157
158 class HP437B(Instrument):
159 """Represents the HP437B Power Meters.
160
161 .. note::
162 Most command descriptions are taken from the document:
163 'Operating Manual 437B Power Meter'
164 """
165
166 def __init__(self, adapter, name="Hewlett-Packard HP437B", **kwargs):
167 super().__init__(
168 adapter,
169 name,
170 includeSCPI=False,
171 send_end=True,
172 **kwargs,
173 )
174
175 def check_errors(self):
176 errors = []
177 while True:
178 err = self.values("ERR?")
179 # exclude upper limit and lower limit hit from real errors
180 if int(err[0]) != 0 and int(err[0]) != 21 and int(err[0]) != 23:
181 log.error(f"{self.name}: {err[0]}, {Errors[err[0]]}")
182 errors.append(err)
183 else:
184 break
185 return errors
186
187 event_status = Instrument.measurement(
188 "*ESR?",
189 """
190 Get the status byte and Master Summary Status bit.
191
192 .. code-block:: python
193
194 print(instr.request_service_conditions)
195 StatusRegister.PowerOn|CommandError
196 """,
197 cast=int,
198 get_process=lambda v: EventStatusRegister(v)
199 )
200
201 def activate_auto_range(self):
202 """
203 The power meter divides each sensor’s power range into 5 ranges of
204 10 dB each. Range 1 is the most sensitive (lowest power levels), and
205 Range 5 is the least sensitive (highest power levels). Range 5 can be
206 less than 10 dB if the sensor’s power range is less than 50 dB. The
207 range can be set either automatically or manually.
208 'activate_auto_range' automatically selects the correct range for the current
209 measurement.
210 """
211 self.write("RA")
212
213 def calibrate(self, calibration_factor):
214 """
215 Calibrate a sensor to the power meter with a 'calibration_factor' in percent.
216 """
217 self.write("CL%.1fPCT" % calibration_factor)
218
219 @property
220 def calibration_factor(self):
221 """
222 Control the calibration factor of a specific power sensor at a specific input frequency.
223 (A chart or table of CAL FACTOR % versus Frequency is printed on each sensor and an
224 accompanying data sheet.) Calibration factor is entered in percent.
225 Valid entries for 'calibration_factor' range from 1.0 to 150.0%.
226 """
227 self.write("KB")
228 # returns CALFAC 097.9%
229 display_content = self.display_output
230 assert display_content[0:6] == "CALFAC"
231 self.write("EX")
232 return float(display_content[7:12])
233
234 @calibration_factor.setter
235 def calibration_factor(self, calibration_factor):
236 values = [1.0, 150.0]
237 strict_range(float(calibration_factor), values)
238
239 self.write("KB%3.1fPCT" % float(calibration_factor))
240 self.check_errors()
241
242 display_enabled = Instrument.setting(
243 "%s",
244 """
245 Set the display of the power meter active or inactive.
246 """,
247 map_values=True,
248 values={True: "DE", False: "DD"}
249 )
250
251 display_all_segments_enabled = Instrument.setting(
252 "%s",
253 """
254 Set all segments of the display of the power meter active or resume normal state.
255 """,
256 map_values=True,
257 values={True: "DA", False: "DE"}
258 )
259
260 display_user_message = Instrument.setting(
261 "DU %s",
262 """
263 Set a custom user message up to 12 alpha-numerical chars. If the string is empty or None
264 the user message gets disabled.
265 """,
266 validator=lambda x, y: x if str(x).isalnum() and len(str(x)) <= 12 else str(x)[0:12],
267 set_process=lambda v: str(v).upper().ljust(12)
268 )
269
270 display_output = Instrument.measurement(
271 "OD",
272 """
273 Get the current displayed string of values of the power meter.
274
275 .. code-block:: python
276
277 print(instr.display_output)
278 -0.23 dB REL
279
280 """,
281 cast=str
282 )
283
284 duty_cycle_enabled = Instrument.control(
285 "SM", "DC%d",
286 """
287 Control whether the duty cycle is active or inactive. See :attr:`duty_cycle`
288 """,
289 map_values=True,
290 values={True: 1, False: 0},
291 cast=int,
292 get_process=_getstatus(StatusMessage.DutyCycleStatus),
293 check_set_errors=True
294 )
295
296 @property
297 def duty_cycle(self):
298 """
299 Control the duty cycle for calculation of a pulsed input signal. This function will cause
300 the power meter to report the pulse power of a rectangular pulsed input signal. The
301 allowable range of values for 'duty_cycle' is 0.00001 to 0.99999.
302
303 Pulse power, as reported by the power meter, is a mathematical
304 representation of the pulse power rather than an actual measurement.
305 The power meter measures the average power of the pulsed input
306 signal and then divides the measurement by the duty cycle value to
307 obtain a pulse power reading.
308 """
309 self.write("DY")
310 # returns DTYCY 01.000%
311 display_content = self.display_output
312 assert display_content[0:5] == "DTYCY"
313 self.write("EX")
314 return float(display_content[6:12]) / 100.0
315
316 @duty_cycle.setter
317 def duty_cycle(self, duty_cycle):
318 values = [0.00001, 0.99999]
319 strict_range(float(duty_cycle), values)
320
321 self.write("DY%02.3fPCT" % (float(duty_cycle) * 100.0))
322 self.check_errors()
323
324 filter_automatic_enabled = Instrument.control(
325 "SM", "%s",
326 """
327 Control the filter mode. By switching over from automatic to manual (true to false)
328 the instrument implicitly keeps (holds) the filter value from the automatic selection.
329 """,
330 cast=bool,
331 get_process=_getstatus(StatusMessage.AutoFilterStatus),
332 set_process=lambda v: "FA" if v else "FH",
333 check_set_errors=True
334 )
335
336 filter = Instrument.control(
337 "SM", "FM%dEN",
338 """
339 Control the filter number for averaging. Setting a value implicitly enables the manual
340 filter mode. Setting a value of 1 basically disables the averaging.
341 """,
342 values=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512],
343 validator=strict_discrete_set,
344 get_process=_getstatus(StatusMessage.Filter, (lambda x: 2 ** x)),
345 check_set_errors=True
346 )
347
348 @property
349 def frequency(self):
350 """
351 Control the frequency of the input signal. Entering a frequency causes the power meter to
352 select a sensor-specific calibration factor. The allowed range of 'frequency'
353 values is from 0.0001 to 999.9999 GHz with a 100 kHz resolution. The unit is Hz.
354 """
355 self.write("FR")
356 # returns FR 000.0500GZ
357 display_content = self.display_output
358 assert display_content[0:2] == "FR"
359 self.write("EX")
360
361 return_value = float(display_content[3:11])
362 if display_content[11:13] == "GZ":
363 return_value *= 1e9
364 else:
365 return_value *= 1e6
366
367 return return_value
368
369 @frequency.setter
370 def frequency(self, frequency):
371 self.write("FR%08.4fGZ" % (float(frequency) / 1e9))
372 self.check_errors()
373
374 limits_enabled = Instrument.control(
375 "SM", "LM%d",
376 """
377 Control the limits checking function to allow the power meter to monitor the
378 power level at the sensor and to indicate when that power is outside
379 preset limits.
380 """,
381 map_values=True,
382 values={True: 1, False: 0},
383 cast=int,
384 get_process=_getstatus(StatusMessage.LimitsCheckingStatus),
385 check_set_errors=True
386 )
387
388 @property
389 def limit_high(self):
390 """
391 Control the upper limit for the builtin limit checking.
392 """
393 self.write("LH")
394 # returns HI +299.999dB
395 display_content = self.display_output
396 assert display_content[0:2] == "HI"
397 self.write("EX")
398 return float(display_content[3:11])
399
400 @limit_high.setter
401 def limit_high(self, limit):
402 """
403 Control the upper limit for the builtin limit checking.
404 """
405 values = [-299.999, 299.999]
406 strict_range(limit, values)
407
408 self.write("LH%7.3fEN" % limit)
409 self.check_errors()
410
411 @property
412 def limit_low(self):
413 """
414 Control the lower limit for the builtin limit checking.
415 """
416 self.write("LL")
417 # returns HI +299.999dB
418 display_content = self.display_output
419 assert display_content[0:2] == "LO"
420 self.write("EX")
421 return float(display_content[3:11])
422
423 @limit_low.setter
424 def limit_low(self, limit):
425 """
426 Control the lower limit for the builtin limit checking.
427 """
428 values = [-299.999, 299.999]
429 strict_range(limit, values)
430
431 self.write("LL%7.3fEN" % limit)
432 self.check_errors()
433
434 limit_high_hit = Instrument.measurement(
435 "SM",
436 """
437 Get if the upper limit check got triggered.
438 """,
439 map_values=True,
440 values={True: 1, False: 0},
441 cast=int,
442 get_process=_getstatus(StatusMessage.LimitsStatus),
443 )
444
445 limit_low_hit = Instrument.measurement(
446 "SM",
447 """
448 Get if the lower limit check got triggered.
449 """,
450 map_values=True,
451 values={True: 2, False: 0},
452 cast=int,
453 get_process=_getstatus(StatusMessage.LimitsStatus),
454 )
455
456 # just addressing the instrument to talk (without a query string) and read until EOI results
457 # in only reading the RF power level
458 power = Instrument.measurement(
459 "",
460 """
461 Measure the power at the power sensor attached to the power meter in the corresponding unit.
462 In case a measurement would be invalid the power meter responds with the value float('nan').
463 """,
464 get_process=lambda v: float("nan") if v == 9.0200e+40 else v
465
466 )
467
468 power_reference_enabled = Instrument.control(
469 "SM", "OC%d",
470 """
471 Control the builtin reference power source 1mW @ 50 MHz.
472 """,
473 map_values=True,
474 values={True: 1, False: 0},
475 cast=int,
476 get_process=_getstatus(StatusMessage.PowerRefStatus),
477 check_set_errors=True
478 )
479
480 offset_enabled = Instrument.control(
481 "SM", "OF%d",
482 """
483 Control the offset being applied.
484 """,
485 map_values=True,
486 values={True: 1, False: 0},
487 cast=int,
488 get_process=_getstatus(StatusMessage.OffsetStatus),
489 check_set_errors=True
490 )
491
492 @property
493 def offset(self):
494 """
495 Control the offset applied to the measured value to compensate for
496 signal gain or loss (for example, to compensate for the loss of a 10 dB
497 directional coupler). Offsets are entered in dB.
498 In case the :attr:`offset_enabled` is false this returns automatically 0.0
499 """
500 if self.offset_enabled:
501 self.write("OS")
502 # returns OFS +00.00 dB
503 display_content = self.display_output
504 assert display_content[0:3] == "OFS"
505 self.write("EX")
506 return float(display_content[4:10])
507 else:
508 return 0.0
509
510 @offset.setter
511 def offset(self, offset):
512 values = [-99.99, 99.99]
513 strict_range(offset, values)
514 self.write("OS%5.2fEN" % offset)
515
516 def reset(self):
517 self.write("*RST")
518
519 def clear_status_registers(self):
520 self.write("*CLS")
521
522 def preset(self):
523 """
524 Sets the power meter to a known state. Preset
525 conditions are shown in the following table.
526
527 .. list-table:: Preset values
528 :widths: 25 25
529 :header-rows: 1
530
531 * - Parameter
532 - Value/Condition
533 * - Frequency
534 - 50 MHz
535 * - Resolution
536 - 0.01 dB
537 * - Duty Cylce
538 - 1.000%, Off
539 * - Relative
540 - 0 dB, Off
541 * - Power Reference
542 - Off
543 * - Range
544 - Auto
545 * - Unit
546 - dBm
547 * - Low Limit
548 - -90.000 dBm
549 * - High Limit
550 - +90.000 dBm
551 * - Limit Checking
552 - Off
553 * - Trigger Mode
554 - Free Run
555 * - Group Trigger Mode
556 - Trigger with Delay
557 * - Display Function
558 - Display Enable
559 """
560 self.write("PR")
561
562 relative_mode_enabled = Instrument.control(
563 "SM", "RL%d",
564 """
565 Control the relative mode. In the relative mode the current measured power value will be
566 used as reference and any further reported value from :attr:`power` will refer to this.
567 """,
568 map_values=True,
569 values={True: 1, False: 0},
570 cast=int,
571 get_process=_getstatus(StatusMessage.RelativeModeStatus),
572 check_set_errors=True
573 )
574
575 measurement_unit = Instrument.measurement(
576 "SM",
577 """
578 Get the measurement unit the power meter is currently reporting the power values in.
579
580 Depends on: :attr:`relative_mode_enabled` and attr:`linear_display_enabled`
581
582 .. code-block:: python
583
584 instr.relative_mode_enabled = False
585 instr.linear_display_enabled = True
586
587 print(instr.measurement_unit)
588 MeasurementUnit.Watts
589
590 """,
591 values=[e for e in MeasurementUnit],
592 cast=int,
593 get_process=_getstatus(StatusMessage.MeasurementUnits, lambda v: MeasurementUnit(v)),
594 )
595
596 linear_display_enabled = Instrument.control(
597 "SM", "%s",
598 """
599 Control if the power meter displays or reports the power values in logarithmic or linear
600 units. Set `linear_display_enabled` to 'True' to activate linear value readout.
601
602 .. code-block:: python
603
604 from pymeasure.instruments.hp.hp437b import LogLin
605
606 instr.relative_mode_enabled = False
607 instr.linear_display_enabled = True
608 """,
609 validator=strict_discrete_set,
610 values={True: "LN", False: "LG"},
611 cast=bool,
612 map_values=True,
613 get_process=_getstatus(StatusMessage.LinearLogStatus, lambda v: {0: "LN", 1: "LG"}[v])
614 )
615
616 @property
617 def resolution(self):
618 """
619 Control the resolution of the power meter's measured value. Three levels of resolution
620 can be
621 set: 0.1 dB, 0.01 dB and 0.001 dB or if the selected unit is Watts 1%, 0.1% and 0.001%.
622 """
623 linear_display_enabled = self.linear_display_enabled
624 mapping = {}
625 if not linear_display_enabled:
626 mapping = {1: 0.1, 2: 0.01, 3: 0.001}
627 else:
628 mapping = {1: 1, 2: 0.1, 3: 0.01}
629
630 self.write("RE")
631 self.check_errors()
632 display_content = self.display_output
633 self.check_errors()
634 self.write("EX")
635 assert display_content[0:3] == "RES"
636
637 return mapping[int(display_content[3])]
638
639 @resolution.setter
640 def resolution(self, resolution):
641 """
642 Control the resolution of the power meter's measured value. Three levels of resolution can
643 be set: 0.1 dB, 0.01 dB and 0.001 dB or if the selected unit is Watts 1%, 0.1% and 0.001%.
644 """
645
646 linear_display_enabled = self.linear_display_enabled
647 allowed_values = {}
648 if not linear_display_enabled:
649 allowed_values = {0.1: 1, 0.01: 2, 0.001: 3}
650 else:
651 allowed_values = {1: 1, 0.1: 2, 0.01: 3}
652
653 strict_discrete_set(resolution, allowed_values.keys())
654
655 self.write(f"RE{allowed_values[resolution]}EN")
656 self.check_errors()
657
658 sensor_type = Instrument.setting(
659 "SE%dEN",
660 """
661 Set the sensor type connected to the power meter to select the corresponding calibration
662 factor.
663
664 .. code-block:: python
665
666 from pymeasure.instruments.hp.hp437b import SensorType
667
668 instr.sensor_type = SensorType.HP_8481A
669
670 """,
671 validator=strict_discrete_set,
672 values=[e for e in SensorType],
673 check_set_errors=True
674 )
675
676 def sensor_data_clear(self, sensor_id):
677 """
678 Clear the Sensor Data table of 'sensor_id' previous to entering new values.
679 """
680 values = [0, 9]
681 strict_range(sensor_id, values)
682
683 self.write(f"CT{sensor_id}")
684
685 def sensor_data_ref_cal_factor(self, sensor_id, ref_cal_factor):
686 """
687 Set the power sensor's reference calibration factor to the Sensor Data table.
688 """
689 values = [0, 9]
690 strict_range(sensor_id, values)
691
692 self.write(f"RF{sensor_id}{ref_cal_factor:4.1f}")
693 self.check_errors()
694
695 def sensor_data_write_cal_factor_table(self, sensor_id, frequency_table, cal_fac_table):
696 """
697 Write the 'calibration_table' for 'sensor_id' to the Sensor Data
698 table. And write the reference calibration factor for the 'sensor_id'.
699 Frequency is given in Hz. Calibration factor as percentage.
700
701 The power meter’s memory contains space for 10 tables, numbered
702 0—9. Tables 0-7 each contain space for 40 frequency /calibration
703 factor pairs. Tables 8 and 9 each contain space for 80
704 frequency/calibration factor pairs.
705
706 This function clears the sensor table before writing.
707
708 Example table:
709
710 .. code-block:: python
711
712 calibration_table = {
713 10e6: 100.0,
714 1e9: 96.5,
715 2e9: 97.0
716 }
717
718 instr.sensor_data_cal_factor_table(0, calibration_table.keys(),
719 calibration_table.values())
720 """
721 values = [0, 9]
722 strict_range(sensor_id, values)
723
724 if sensor_id in range(0, 7) and (len(cal_fac_table) > 40 or len(frequency_table)) > 40:
725 raise ValueError(f"For sensor id {sensor_id} there aren't more than 40 frequency "
726 f"pairs allowed")
727 if sensor_id in range(8, 9) and (len(cal_fac_table) > 80 or len(frequency_table)) > 80:
728 raise ValueError(f"For sensor id {sensor_id} there aren't more than 80 frequency "
729 f"pairs allowed")
730 if len(cal_fac_table) != len(frequency_table):
731 raise ValueError(f"Frequency table and calibration factor table must have the same "
732 f"length {len(cal_fac_table)}!={len(frequency_table)}")
733
734 self.sensor_data_clear(sensor_id)
735 for frequency, cal_factor in zip(frequency_table, cal_fac_table):
736 if frequency > 99.9e6:
737 freq_suffix = "GZ"
738 frequency /= 1e9
739 elif frequency > 99.9e3:
740 freq_suffix = "MZ"
741 frequency /= 1e6
742 else:
743 freq_suffix = "KZ"
744 frequency /= 1e3
745
746 self.write(f"ET{sensor_id} {frequency:5.2f}{freq_suffix} {cal_factor}% EN")
747 self.check_errors()
748 self.write("EX")
749 self.check_errors()
750
751 def sensor_data_read_cal_factor_table(self, sensor_id):
752 """
753 Read the Sensor Data calibration table. See :meth:`sensor_data_write_cal_factor_table`
754 Returns a tuple of frequencies as list and calibration factors as list.
755 """
756 allowed_values = [0, 9]
757 strict_range(sensor_id, allowed_values)
758
759 pairs = 80
760 if sensor_id < 8:
761 pairs = 40
762
763 frequency_data = []
764 cal_fac_data = []
765 self.write(f"ET{sensor_id}")
766 self.check_errors()
767 for i in range(0, pairs):
768 # outputs something like 38.00GZ 100.2%
769 display_content = self.display_output
770
771 frequency = float(display_content[0:5])
772 if frequency == 0:
773 break
774 if display_content[5:7] == "GZ":
775 frequency *= 1e9
776 else:
777 frequency *= 1e6
778
779 calibration_factor = float(display_content[8:13])
780 cal_fac_data.append(calibration_factor)
781 frequency_data.append(frequency)
782
783 self.write("EN")
784 self.check_errors()
785
786 self.write("EX")
787 return frequency_data, cal_fac_data
788
789 def sensor_data_write_id_label(self, sensor_id, label):
790 """
791 Set a particular power sensor’s ID label table to be modified. The sensor ID label must not
792 exceed 7 characters. For example, to identify Sensor Data table #2
793 with an ID number of 1234567:
794
795 .. code-block:: python
796
797 instr.sensor_data_id_label(2, "1234567")
798
799 """
800
801 values = [0, 9]
802 strict_range(sensor_id, values)
803
804 if len(label) > 7:
805 raise ValueError("Sensor id label must not exceed length of 7")
806
807 if not str(label).upper().isalnum():
808 raise ValueError("Sensor id label only allows 0-9, A-Z")
809
810 self.write(f"SN{sensor_id}{label}")
811
812 automatic_range_enabled = Instrument.control(
813 "SM", "%s",
814 """
815 Control the automatic range.
816 The power meter divides each sensor’s power range into 5 ranges of 10 dB each. Range 1
817 is the most sensitive (lowest power levels), and Range 5 is the least sensitive (highest
818 power levels). The range can be set either automatically or manually.
819 """,
820 get_process=_getstatus(StatusMessage.AutomaticRangeStatus, lambda v: bool(v)),
821 set_process=lambda v: "RM0EN" if v is True else "RH"
822 )
823
824 range = Instrument.control(
825 "SM", "RM%dEN",
826 """
827 Control the range to be selected manually. Valid range numbers are 1 through 5.
828 See :attr:`automatic_range_enabled` for further information.
829 """,
830 values=[1, 5],
831 validator=strict_range,
832 get_process=_getstatus(StatusMessage.Range)
833 )
834
835 def store(self, register):
836 """
837 The power meter can store instrument configurations for recall at a
838 later time. The following information can be stored in the power
839 meter’s internal registers:
840
841 - reference calibration factor value
842 - Measurement units (dBm or watts)
843 - relative value and status (on or off)
844 - power reference status (on or off)
845 - calibration factor value
846 - SENSOR ID (sensor data table selection)
847 - offset value and status (on or off)
848 - range (Auto or Set)
849 - frequency value
850 - resolution
851 - duty cycle value and status (on or off)
852 - Filter (number of readings averaged, auto or manual)
853 - Limits value and status (on or off)
854
855 Registers 1 through 10 are available for storing instrument
856 configurations.
857 """
858 values = [1, 10]
859 strict_range(register, values)
860 self.write(f"ST{register}EN")
861
862 operating_mode = Instrument.measurement(
863 "SM",
864 """
865 Get the operating mode the power meter is currently in.
866 """,
867 get_process=_getstatus(StatusMessage.OperatingMode, lambda v: OperatingMode(v))
868 )
869
870 def zero(self):
871 """
872 Adjust the power meter’s internal circuitry for a zero power indication when no power is
873 applied to the sensor.
874
875 .. note::
876
877 Ensure that no power is applied to the sensor while the power meter
878 is zeroing. Any applied RF input power will cause an erroneous
879 reading.
880
881 """
882 self.write("ZE")
883
884 trigger_mode = Instrument.control(
885 "SM", "TR%d",
886 """
887 Control the trigger mode.
888
889 The power meter has two modes of triggered operation; standby mode and free run mode.
890 Standby mode means the power meter is making measurements, but the display and HP-IB are
891 not updated until a trigger command is received. Free run means that Meter takes
892 measurements and updates the display and HP-IB continuously.
893 """,
894 values=[e for e in TriggerMode],
895 validator=strict_discrete_set,
896 get_process=_getstatus(StatusMessage.TriggerMode, lambda v: TriggerMode(v)),
897 set_process=lambda v: int(v)
898 )
899
900 def trigger_immediate(self):
901 """
902 Trigger immediate.
903
904 When the power meter receives the trigger immediate program code, it inputs one more data
905 point into the digital filter, measures the reading from the filter, and then updates
906 the display and HP-IB. (When the trigger immediate command is executed, the internal
907 digital filter is not cleared.) The power meter then waits for the measurement results to
908 be read by the controller. While waiting, the power meter can process most bus commands
909 without losing the measurement results. If the power meter receives a trigger immediate
910 command and then receives the GET (Group Execute Trigger) command, the trigger immediate
911 command will be aborted and a new measurement cycle will be executed. Once the
912 measurement results are read onto the bus, the power meter always reverts to standby/hold
913 mode. Measurement results obtained via trigger immediate are normally valid only when the
914 power meter is in a steady, settled state.
915 """
916 self.write("TR1")
917
918 def trigger_delay(self):
919 """
920 Trigger with delay.
921
922 Triggering with delay is identical to :meth:`trigger_immediate` except the power meter
923 inserts a settling-time delay before taking the requested measurement.
924 This settling time allows the internal digital filter to be updated with new values to
925 produce valid, accurate measurement results. The trigger with delay command allows time
926 for settling of the internal amplifiers and filters. It does not allow time for power
927 sensor delay. In cases of large power changes, the delay may not be sufficient for
928 complete settling. Accurate readings can be assured by taking two successive measurements
929 for comparison. Once the measurement results are displayed and read onto the bus,
930 the power meter reverts to standby mode.
931 """
932 self.write("TR2")
933
934 group_trigger_mode = Instrument.control(
935 "SM", "GT%d",
936 """
937 Control the group execute trigger mode.
938 When in remote and addressed to listen, the power meter responds to a Trigger message (
939 the Group Execute Trigger bus command [GET]) according to the programmed mode.
940 """,
941 values=[e for e in GroupTriggerMode],
942 validator=strict_discrete_set,
943 get_process=_getstatus(StatusMessage.GroupTriggerMode, lambda v: GroupTriggerMode(v)),
944 set_process=lambda v: int(v)
945 )