| 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 truncated_range, strict_discrete_set |
| 27 |
|
| 28 |
|
| 29 |
class Agilent8257D(SCPIUnknownMixin, Instrument): |
| 30 |
"""Represents the Agilent 8257D Signal Generator and |
| 31 |
provides a high-level interface for interacting with |
| 32 |
the instrument. |
| 33 |
|
| 34 |
.. code-block:: python |
| 35 |
|
| 36 |
generator = Agilent8257D("GPIB::1") |
| 37 |
|
| 38 |
generator.power = 0 # Sets the output power to 0 dBm |
| 39 |
generator.frequency = 5 # Sets the output frequency to 5 GHz |
| 40 |
generator.enable() # Enables the output |
| 41 |
|
| 42 |
""" |
| 43 |
|
| 44 |
power = Instrument.control( |
| 45 |
":POW?;", ":POW %g dBm;", |
| 46 |
""" A floating point property that represents the output power |
| 47 |
in dBm. This property can be set. |
| 48 |
""" |
| 49 |
) |
| 50 |
frequency = Instrument.control( |
| 51 |
":FREQ?;", ":FREQ %e Hz;", |
| 52 |
""" A floating point property that represents the output frequency |
| 53 |
in Hz. This property can be set. |
| 54 |
""" |
| 55 |
) |
| 56 |
start_frequency = Instrument.control( |
| 57 |
":SOUR:FREQ:STAR?", ":SOUR:FREQ:STAR %e Hz", |
| 58 |
""" A floating point property that represents the start frequency |
| 59 |
in Hz. This property can be set. |
| 60 |
""" |
| 61 |
) |
| 62 |
center_frequency = Instrument.control( |
| 63 |
":SOUR:FREQ:CENT?", ":SOUR:FREQ:CENT %e Hz;", |
| 64 |
""" A floating point property that represents the center frequency |
| 65 |
in Hz. This property can be set. |
| 66 |
""" |
| 67 |
) |
| 68 |
stop_frequency = Instrument.control( |
| 69 |
":SOUR:FREQ:STOP?", ":SOUR:FREQ:STOP %e Hz", |
| 70 |
""" A floating point property that represents the stop frequency |
| 71 |
in Hz. This property can be set. |
| 72 |
""" |
| 73 |
) |
| 74 |
start_power = Instrument.control( |
| 75 |
":SOUR:POW:STAR?", ":SOUR:POW:STAR %e dBm", |
| 76 |
""" A floating point property that represents the start power |
| 77 |
in dBm. This property can be set. |
| 78 |
""" |
| 79 |
) |
| 80 |
stop_power = Instrument.control( |
| 81 |
":SOUR:POW:STOP?", ":SOUR:POW:STOP %e dBm", |
| 82 |
""" A floating point property that represents the stop power |
| 83 |
in dBm. This property can be set. |
| 84 |
""" |
| 85 |
) |
| 86 |
dwell_time = Instrument.control( |
| 87 |
":SOUR:SWE:DWEL1?", ":SOUR:SWE:DWEL1 %.3f", |
| 88 |
""" A floating point property that represents the settling time |
| 89 |
in seconds at the current frequency or power setting. |
| 90 |
This property can be set. |
| 91 |
""" |
| 92 |
) |
| 93 |
step_points = Instrument.control( |
| 94 |
":SOUR:SWE:POIN?", ":SOUR:SWE:POIN %d", |
| 95 |
""" An integer number of points in a step sweep. This property |
| 96 |
can be set. |
| 97 |
""" |
| 98 |
) |
| 99 |
is_enabled = Instrument.measurement( |
| 100 |
":OUTPUT?", |
| 101 |
""" Reads a boolean value that is True if the output is on. """, |
| 102 |
cast=bool |
| 103 |
) |
| 104 |
has_modulation = Instrument.measurement( |
| 105 |
":OUTPUT:MOD?", |
| 106 |
""" Reads a boolean value that is True if the modulation is enabled. """, |
| 107 |
cast=bool |
| 108 |
) |
| 109 |
|
| 110 |
######################## |
| 111 |
# Amplitude modulation # |
| 112 |
######################## |
| 113 |
|
| 114 |
has_amplitude_modulation = Instrument.measurement( |
| 115 |
":SOUR:AM:STAT?", |
| 116 |
""" Reads a boolean value that is True if the amplitude modulation is enabled. """, |
| 117 |
cast=bool |
| 118 |
) |
| 119 |
amplitude_depth = Instrument.control( |
| 120 |
":SOUR:AM:DEPT?", ":SOUR:AM:DEPT %g", |
| 121 |
""" A floating point property that controls the amplitude modulation |
| 122 |
in percent, which can take values from 0 to 100 %. """, |
| 123 |
validator=truncated_range, |
| 124 |
values=[0, 100] |
| 125 |
) |
| 126 |
AMPLITUDE_SOURCES = { |
| 127 |
'internal': 'INT', 'internal 2': 'INT2', |
| 128 |
'external': 'EXT', 'external 2': 'EXT2' |
| 129 |
} |
| 130 |
amplitude_source = Instrument.control( |
| 131 |
":SOUR:AM:SOUR?", ":SOUR:AM:SOUR %s", |
| 132 |
""" A string property that controls the source of the amplitude modulation |
| 133 |
signal, which can take the values: 'internal', 'internal 2', 'external', and |
| 134 |
'external 2'. """, |
| 135 |
validator=strict_discrete_set, |
| 136 |
values=AMPLITUDE_SOURCES, |
| 137 |
map_values=True |
| 138 |
) |
| 139 |
|
| 140 |
#################### |
| 141 |
# Pulse modulation # |
| 142 |
#################### |
| 143 |
|
| 144 |
has_pulse_modulation = Instrument.measurement( |
| 145 |
":SOUR:PULM:STAT?", |
| 146 |
""" Reads a boolean value that is True if the pulse modulation is enabled. """, |
| 147 |
cast=bool |
| 148 |
) |
| 149 |
PULSE_SOURCES = { |
| 150 |
'internal': 'INT', 'external': 'EXT', 'scalar': 'SCAL' |
| 151 |
} |
| 152 |
pulse_source = Instrument.control( |
| 153 |
":SOUR:PULM:SOUR?", ":SOUR:PULM:SOUR %s", |
| 154 |
""" A string property that controls the source of the pulse modulation |
| 155 |
signal, which can take the values: 'internal', 'external', and |
| 156 |
'scalar'. """, |
| 157 |
validator=strict_discrete_set, |
| 158 |
values=PULSE_SOURCES, |
| 159 |
map_values=True |
| 160 |
) |
| 161 |
PULSE_INPUTS = { |
| 162 |
'square': 'SQU', 'free-run': 'FRUN', |
| 163 |
'triggered': 'TRIG', 'doublet': 'DOUB', 'gated': 'GATE' |
| 164 |
} |
| 165 |
pulse_input = Instrument.control( |
| 166 |
":SOUR:PULM:SOUR:INT?", ":SOUR:PULM:SOUR:INT %s", |
| 167 |
""" A string property that controls the internally generated modulation |
| 168 |
input for the pulse modulation, which can take the values: 'square', 'free-run', |
| 169 |
'triggered', 'doublet', and 'gated'. |
| 170 |
""", |
| 171 |
validator=strict_discrete_set, |
| 172 |
values=PULSE_INPUTS, |
| 173 |
map_values=True |
| 174 |
) |
| 175 |
pulse_frequency = Instrument.control( |
| 176 |
":SOUR:PULM:INT:FREQ?", ":SOUR:PULM:INT:FREQ %g", |
| 177 |
""" A floating point property that controls the pulse rate frequency in Hertz, |
| 178 |
which can take values from 0.1 Hz to 10 MHz. """, |
| 179 |
validator=truncated_range, |
| 180 |
values=[0.1, 10e6] |
| 181 |
) |
| 182 |
|
| 183 |
######################## |
| 184 |
# Low-Frequency Output # |
| 185 |
######################## |
| 186 |
|
| 187 |
low_freq_out_amplitude = Instrument.control( |
| 188 |
":SOUR:LFO:AMPL? ", ":SOUR:LFO:AMPL %g VP", |
| 189 |
"""A floating point property that controls the peak voltage (amplitude) of the |
| 190 |
low frequency output in volts, which can take values from 0-3.5V""", |
| 191 |
validator=truncated_range, |
| 192 |
values=[0, 3.5] |
| 193 |
) |
| 194 |
|
| 195 |
LOW_FREQUENCY_SOURCES = { |
| 196 |
'internal': 'INT', 'internal 2': 'INT2', 'function': 'FUNC', 'function 2': 'FUNC2' |
| 197 |
} |
| 198 |
|
| 199 |
low_freq_out_source = Instrument.control( |
| 200 |
":SOUR:LFO:SOUR?", ":SOUR:LFO:SOUR %s", |
| 201 |
"""A string property which controls the source of the low frequency output, which |
| 202 |
can take the values 'internal [2]' for the internal source, or 'function [2]' for an |
| 203 |
internal function generator which can be configured.""", |
| 204 |
validator=strict_discrete_set, |
| 205 |
values=LOW_FREQUENCY_SOURCES, |
| 206 |
map_values=True |
| 207 |
) |
| 208 |
|
| 209 |
def enable_low_freq_out(self): |
| 210 |
"""Enables low frequency output""" |
| 211 |
self.write(":SOUR:LFO:STAT ON") |
| 212 |
|
| 213 |
def disable_low_freq_out(self): |
| 214 |
"""Disables low frequency output""" |
| 215 |
self.write(":SOUR:LFO:STAT OFF") |
| 216 |
|
| 217 |
def config_low_freq_out(self, source='internal', amplitude=3): |
| 218 |
""" Configures the low-frequency output signal. |
| 219 |
|
| 220 |
:param source: The source for the low-frequency output signal. |
| 221 |
:param amplitude: Amplitude of the low-frequency output |
| 222 |
""" |
| 223 |
self.enable_low_freq_out() |
| 224 |
self.low_freq_out_source = source |
| 225 |
self.low_freq_out_amplitude = amplitude |
| 226 |
|
| 227 |
####################### |
| 228 |
# Internal Oscillator # |
| 229 |
####################### |
| 230 |
|
| 231 |
internal_frequency = Instrument.control( |
| 232 |
":SOUR:AM:INT:FREQ?", ":SOUR:AM:INT:FREQ %g", |
| 233 |
""" A floating point property that controls the frequency of the internal |
| 234 |
oscillator in Hertz, which can take values from 0.5 Hz to 1 MHz. """, |
| 235 |
validator=truncated_range, |
| 236 |
values=[0.5, 1e6] |
| 237 |
) |
| 238 |
INTERNAL_SHAPES = { |
| 239 |
'sine': 'SINE', 'triangle': 'TRI', 'square': 'SQU', 'ramp': 'RAMP', |
| 240 |
'noise': 'NOIS', 'dual-sine': 'DUAL', 'swept-sine': 'SWEP' |
| 241 |
} |
| 242 |
internal_shape = Instrument.control( |
| 243 |
":SOUR:AM:INT:FUNC:SHAP?", ":SOUR:AM:INT:FUNC:SHAP %s", |
| 244 |
""" A string property that controls the shape of the internal oscillations, |
| 245 |
which can take the values: 'sine', 'triangle', 'square', 'ramp', 'noise', |
| 246 |
'dual-sine', and 'swept-sine'. """, |
| 247 |
validator=strict_discrete_set, |
| 248 |
values=INTERNAL_SHAPES, |
| 249 |
map_values=True |
| 250 |
) |
| 251 |
|
| 252 |
def __init__(self, adapter, name="Agilent 8257D RF Signal Generator", **kwargs): |
| 253 |
super().__init__( |
| 254 |
adapter, name, **kwargs |
| 255 |
) |
| 256 |
|
| 257 |
def enable(self): |
| 258 |
""" Enables the output of the signal. """ |
| 259 |
self.write(":OUTPUT ON;") |
| 260 |
|
| 261 |
def disable(self): |
| 262 |
""" Disables the output of the signal. """ |
| 263 |
self.write(":OUTPUT OFF;") |
| 264 |
|
| 265 |
def enable_modulation(self): |
| 266 |
self.write(":OUTPUT:MOD ON;") |
| 267 |
self.write(":lfo:sour int; :lfo:ampl 2.0vp; :lfo:stat on;") |
| 268 |
|
| 269 |
def disable_modulation(self): |
| 270 |
""" Disables the signal modulation. """ |
| 271 |
self.write(":OUTPUT:MOD OFF;") |
| 272 |
self.write(":lfo:stat off;") |
| 273 |
|
| 274 |
def config_amplitude_modulation(self, frequency=1e3, depth=100.0, shape='sine'): |
| 275 |
""" Configures the amplitude modulation of the output signal. |
| 276 |
|
| 277 |
:param frequency: A modulation frequency for the internal oscillator |
| 278 |
:param depth: A linear depth percentage |
| 279 |
:param shape: A string that describes the shape for the internal oscillator |
| 280 |
""" |
| 281 |
self.enable_amplitude_modulation() |
| 282 |
self.amplitude_source = 'internal' |
| 283 |
self.internal_frequency = frequency |
| 284 |
self.internal_shape = shape |
| 285 |
self.amplitude_depth = depth |
| 286 |
|
| 287 |
def enable_amplitude_modulation(self): |
| 288 |
""" Enables amplitude modulation of the output signal. """ |
| 289 |
self.write(":SOUR:AM:STAT ON") |
| 290 |
|
| 291 |
def disable_amplitude_modulation(self): |
| 292 |
""" Disables amplitude modulation of the output signal. """ |
| 293 |
self.write(":SOUR:AM:STAT OFF") |
| 294 |
|
| 295 |
def config_pulse_modulation(self, frequency=1e3, input='square'): |
| 296 |
""" Configures the pulse modulation of the output signal. |
| 297 |
|
| 298 |
:param frequency: A pulse rate frequency in Hertz |
| 299 |
:param input: A string that describes the internal pulse input |
| 300 |
""" |
| 301 |
self.enable_pulse_modulation() |
| 302 |
self.pulse_source = 'internal' |
| 303 |
self.pulse_input = input |
| 304 |
self.pulse_frequency = frequency |
| 305 |
|
| 306 |
def enable_pulse_modulation(self): |
| 307 |
""" Enables pulse modulation of the output signal. """ |
| 308 |
self.write(":SOUR:PULM:STAT ON") |
| 309 |
|
| 310 |
def disable_pulse_modulation(self): |
| 311 |
""" Disables pulse modulation of the output signal. """ |
| 312 |
self.write(":SOUR:PULM:STAT OFF") |
| 313 |
|
| 314 |
def config_step_sweep(self): |
| 315 |
""" Configures a step sweep through frequency """ |
| 316 |
self.write(":SOUR:FREQ:MODE SWE;" |
| 317 |
":SOUR:SWE:GEN STEP;" |
| 318 |
":SOUR:SWE:MODE AUTO;") |
| 319 |
|
| 320 |
def enable_retrace(self): |
| 321 |
self.write(":SOUR:LIST:RETR 1") |
| 322 |
|
| 323 |
def disable_retrace(self): |
| 324 |
self.write(":SOUR:LIST:RETR 0") |
| 325 |
|
| 326 |
def single_sweep(self): |
| 327 |
self.write(":SOUR:TSW") |
| 328 |
|
| 329 |
def start_step_sweep(self): |
| 330 |
""" Starts a step sweep. """ |
| 331 |
self.write(":SOUR:SWE:CONT:STAT ON") |
| 332 |
|
| 333 |
def stop_step_sweep(self): |
| 334 |
""" Stops a step sweep. """ |
| 335 |
self.write(":SOUR:SWE:CONT:STAT OFF") |
| 336 |
|
| 337 |
def shutdown(self): |
| 338 |
""" Shuts down the instrument by disabling any modulation |
| 339 |
and the output signal. |
| 340 |
""" |
| 341 |
self.disable_modulation() |
| 342 |
self.disable() |
| 343 |
super().shutdown() |