| 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 |
from pymeasure.instruments import Instrument, SCPIUnknownMixin |
| 26 |
from pymeasure.instruments.validators import strict_discrete_set |
| 27 |
|
| 28 |
import logging |
| 29 |
log = logging.getLogger(__name__) |
| 30 |
log.addHandler(logging.NullHandler()) |
| 31 |
|
| 32 |
|
| 33 |
class HP33120A(SCPIUnknownMixin, Instrument): |
| 34 |
""" Represents the Hewlett Packard 33120A Arbitrary Waveform |
| 35 |
Generator and provides a high-level interface for interacting |
| 36 |
with the instrument. |
| 37 |
""" |
| 38 |
|
| 39 |
def __init__(self, adapter, name="Hewlett Packard 33120A Function Generator", **kwargs): |
| 40 |
super().__init__( |
| 41 |
adapter, |
| 42 |
name, |
| 43 |
**kwargs |
| 44 |
) |
| 45 |
self.amplitude_units = 'Vpp' |
| 46 |
|
| 47 |
SHAPES = { |
| 48 |
'sinusoid': 'SIN', 'square': 'SQU', 'triangle': 'TRI', |
| 49 |
'ramp': 'RAMP', 'noise': 'NOIS', 'dc': 'DC', 'user': 'USER' |
| 50 |
} |
| 51 |
shape = Instrument.control( |
| 52 |
"SOUR:FUNC:SHAP?", "SOUR:FUNC:SHAP %s", |
| 53 |
"""Control the shape of the wave, |
| 54 |
which can take the values: sinusoid, square, triangle, ramp, |
| 55 |
noise, dc, and user. (str)""", |
| 56 |
validator=strict_discrete_set, |
| 57 |
values=SHAPES, |
| 58 |
map_values=True |
| 59 |
) |
| 60 |
|
| 61 |
frequency = Instrument.control( |
| 62 |
"SOUR:FREQ?", "SOUR:FREQ %g", |
| 63 |
"""Control the frequency of the |
| 64 |
output in Hz. The allowed range depends on the waveform shape |
| 65 |
and can be queried with :attr:`~.max_frequency` and |
| 66 |
:attr:`~.min_frequency`. (float)""" |
| 67 |
) |
| 68 |
|
| 69 |
max_frequency = Instrument.measurement( |
| 70 |
"SOUR:FREQ? MAX", |
| 71 |
""" Get the maximum :attr:`~.HP33120A.frequency` in Hz for the given shape """ |
| 72 |
) |
| 73 |
|
| 74 |
min_frequency = Instrument.measurement( |
| 75 |
"SOUR:FREQ? MIN", |
| 76 |
""" Get the minimum :attr:`~.HP33120A.frequency` in Hz for the given shape """ |
| 77 |
) |
| 78 |
|
| 79 |
amplitude = Instrument.control( |
| 80 |
"SOUR:VOLT?", "SOUR:VOLT %g", |
| 81 |
""" Control the voltage amplitude of the |
| 82 |
output signal. The default units are in peak-to-peak Volts, but can be |
| 83 |
controlled by :attr:`~.amplitude_units`. The allowed range depends |
| 84 |
on the waveform shape and can be queried with :attr:`~.max_amplitude` |
| 85 |
and :attr:`~.min_amplitude`. (float)""" |
| 86 |
) |
| 87 |
|
| 88 |
max_amplitude = Instrument.measurement( |
| 89 |
"SOUR:VOLT? MAX", |
| 90 |
""" Get the maximum :attr:`~.amplitude` in Volts for the given shape """ |
| 91 |
) |
| 92 |
|
| 93 |
min_amplitude = Instrument.measurement( |
| 94 |
"SOUR:VOLT? MIN", |
| 95 |
""" Get the minimum :attr:`~.amplitude` in Volts for the given shape """ |
| 96 |
) |
| 97 |
|
| 98 |
offset = Instrument.control( |
| 99 |
"SOUR:VOLT:OFFS?", "SOUR:VOLT:OFFS %g", |
| 100 |
""" Control the amplitude voltage offset |
| 101 |
in Volts. The allowed range depends on the waveform shape and can be |
| 102 |
queried with :attr:`~.max_offset` and :attr:`~.min_offset`. """ |
| 103 |
) |
| 104 |
|
| 105 |
max_offset = Instrument.measurement( |
| 106 |
"SOUR:VOLT:OFFS? MAX", |
| 107 |
""" Get the maximum :attr:`~.offset` in Volts for the given shape """ |
| 108 |
) |
| 109 |
|
| 110 |
min_offset = Instrument.measurement( |
| 111 |
"SOUR:VOLT:OFFS? MIN", |
| 112 |
""" Get the minimum :attr:`~.offset` in Volts for the given shape """ |
| 113 |
) |
| 114 |
|
| 115 |
AMPLITUDE_UNITS = {'Vpp': 'VPP', 'Vrms': 'VRMS', 'dBm': 'DBM', 'default': 'DEF'} |
| 116 |
amplitude_units = Instrument.control( |
| 117 |
"SOUR:VOLT:UNIT?", "SOUR:VOLT:UNIT %s", |
| 118 |
""" Control the units of the amplitude, |
| 119 |
which can take the values Vpp, Vrms, dBm, and default. (str) |
| 120 |
""", |
| 121 |
validator=strict_discrete_set, |
| 122 |
values=AMPLITUDE_UNITS, |
| 123 |
map_values=True |
| 124 |
) |
| 125 |
|
| 126 |
burst_enabled = Instrument.control( |
| 127 |
"BM:STATE?", "BM:STATE %d", |
| 128 |
"""Control state of burst modulation""", |
| 129 |
validator=strict_discrete_set, |
| 130 |
values={True: 1, False: 0}, |
| 131 |
map_values=True |
| 132 |
) |
| 133 |
|
| 134 |
burst_source = Instrument.control( |
| 135 |
"BM:SOURCE?", "BM:SOURCE %s", |
| 136 |
"""Control internal or external gate source for burst modulation""", |
| 137 |
validator=strict_discrete_set, |
| 138 |
values=['INT', 'EXT'], |
| 139 |
) |
| 140 |
|
| 141 |
burst_count = Instrument.control( |
| 142 |
"BM:NCYC?", "BM:NCYC %d", |
| 143 |
"""Control the number of cycles per burst (1 to 50,000 cycles)""", |
| 144 |
) |
| 145 |
|
| 146 |
min_burst_count = Instrument.measurement( |
| 147 |
"BM:NCYC? MIN", |
| 148 |
"""Get the minimum :attr:`~.HP33120A.burst_count`""" |
| 149 |
) |
| 150 |
|
| 151 |
max_burst_count = Instrument.measurement( |
| 152 |
"BM:NCYC? MAX", |
| 153 |
"""Get the maximum :attr:`~.HP33120A.burst_count`""" |
| 154 |
) |
| 155 |
|
| 156 |
burst_rate = Instrument.control( |
| 157 |
"BM:INT:RATE?", "BM:INT:RATE %g", |
| 158 |
"""Control the burst rate in Hz fo an internal burst source""" |
| 159 |
) |
| 160 |
|
| 161 |
min_burst_rate = Instrument.measurement( |
| 162 |
"BM:INT:RATE? MIN", |
| 163 |
"""Get the minimum :attr:`~.HP33120A.burst_rate`""" |
| 164 |
) |
| 165 |
|
| 166 |
max_burst_rate = Instrument.measurement( |
| 167 |
"BM:INT:RATE? MAX", |
| 168 |
"""Get the maximum :attr:`~.HP33120A.burst_rate`""" |
| 169 |
) |
| 170 |
|
| 171 |
burst_phase = Instrument.control( |
| 172 |
"BM:PHAS?", "BM:PHAS %g", |
| 173 |
"""Control the starting phase angle of a burst (-360 to +360 degrees)""" |
| 174 |
) |
| 175 |
|
| 176 |
min_burst_phase = Instrument.measurement( |
| 177 |
"BM:PHAS? MIN", |
| 178 |
"""Get the minimum :attr:`~.HP33120A.burst_phase`""" |
| 179 |
) |
| 180 |
|
| 181 |
max_burst_phase = Instrument.measurement( |
| 182 |
"BM:PHAS? MAX", |
| 183 |
"""Get the maximum :attr:`~.HP33120A.burst_phase`""" |
| 184 |
) |
| 185 |
|
| 186 |
def beep(self): |
| 187 |
""" Causes a system beep. """ |
| 188 |
self.write("SYST:BEEP") |