| 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 |
# Parts of this code were copied and adapted from the Agilent33220A class. |
| 26 |
|
| 27 |
import logging |
| 28 |
from pymeasure.instruments import Instrument, Channel, SCPIUnknownMixin |
| 29 |
from pymeasure.instruments.validators import strict_discrete_set, strict_range |
| 30 |
from time import time |
| 31 |
from pyvisa.errors import VisaIOError |
| 32 |
|
| 33 |
log = logging.getLogger(__name__) |
| 34 |
log.addHandler(logging.NullHandler()) |
| 35 |
|
| 36 |
|
| 37 |
# Capitalize string arguments to allow for better conformity with other WFG's |
| 38 |
# FIXME: Currently not used since it does not combine well with the strict_discrete_set validator |
| 39 |
# def capitalize_string(string: str, *args, **kwargs): |
| 40 |
# return string.upper() |
| 41 |
|
| 42 |
|
| 43 |
# Combine the capitalize function and validator |
| 44 |
# FIXME: This validator is not doing anything other then self.capitalize_string |
| 45 |
# FIXME: I removed it from this class for now |
| 46 |
# string_validator = joined_validators(capitalize_string, strict_discrete_set) |
| 47 |
|
| 48 |
|
| 49 |
class Agilent33500Channel(Channel): |
| 50 |
"""Implementation of a base Agilent 33500 channel""" |
| 51 |
|
| 52 |
shape = Instrument.control( |
| 53 |
"SOUR{ch}:FUNC?", |
| 54 |
"SOUR{ch}:FUNC %s", |
| 55 |
""" A string property that controls the output waveform. Can be set to: |
| 56 |
SIN<USOID>, SQU<ARE>, TRI<ANGLE>, RAMP, PULS<E>, PRBS, NOIS<E>, ARB, DC. """, |
| 57 |
validator=strict_discrete_set, |
| 58 |
values=["SIN", "SQU", "TRI", "RAMP", "PULS", "PRBS", "NOIS", "ARB", "DC"], |
| 59 |
) |
| 60 |
|
| 61 |
frequency = Instrument.control( |
| 62 |
"SOUR{ch}:FREQ?", |
| 63 |
"SOUR{ch}:FREQ %f", |
| 64 |
""" A floating point property that controls the frequency of the output |
| 65 |
waveform in Hz, from 1 uHz to 120 MHz (maximum range, can be lower depending |
| 66 |
on your device), depending on the specified function. """, |
| 67 |
validator=strict_range, |
| 68 |
values=[1e-6, 120e6], |
| 69 |
) |
| 70 |
|
| 71 |
amplitude = Instrument.control( |
| 72 |
"SOUR{ch}:VOLT?", |
| 73 |
"SOUR{ch}:VOLT %f", |
| 74 |
""" A floating point property that controls the voltage amplitude of the |
| 75 |
output waveform in V, from 10e-3 V to 10 V. Depends on the output |
| 76 |
impedance.""", |
| 77 |
validator=strict_range, |
| 78 |
values=[10e-3, 10], |
| 79 |
) |
| 80 |
|
| 81 |
amplitude_unit = Instrument.control( |
| 82 |
"SOUR{ch}:VOLT:UNIT?", |
| 83 |
"SOUR{ch}:VOLT:UNIT %s", |
| 84 |
""" A string property that controls the units of the amplitude. Valid |
| 85 |
values are VPP (default), VRMS, and DBM.""", |
| 86 |
validator=strict_discrete_set, |
| 87 |
values=["VPP", "VRMS", "DBM"], |
| 88 |
) |
| 89 |
|
| 90 |
offset = Instrument.control( |
| 91 |
"SOUR{ch}:VOLT:OFFS?", |
| 92 |
"SOUR{ch}:VOLT:OFFS %f", |
| 93 |
""" A floating point property that controls the voltage offset of the |
| 94 |
output waveform in V, from 0 V to 4.995 V, depending on the set |
| 95 |
voltage amplitude (maximum offset = (Vmax - voltage) / 2). |
| 96 |
""", |
| 97 |
validator=strict_range, |
| 98 |
values=[-4.995, +4.995], |
| 99 |
) |
| 100 |
|
| 101 |
voltage_high = Instrument.control( |
| 102 |
"SOUR{ch}:VOLT:HIGH?", |
| 103 |
"SOUR{ch}:VOLT:HIGH %f", |
| 104 |
""" A floating point property that controls the upper voltage of the |
| 105 |
output waveform in V, from -4.999 V to 5 V (must be higher than low |
| 106 |
voltage by at least 1 mV).""", |
| 107 |
validator=strict_range, |
| 108 |
values=[-4.999, 5], |
| 109 |
) |
| 110 |
|
| 111 |
voltage_low = Instrument.control( |
| 112 |
"SOUR{ch}:VOLT:LOW?", |
| 113 |
"SOUR{ch}:VOLT:LOW %f", |
| 114 |
""" A floating point property that controls the lower voltage of the |
| 115 |
output waveform in V, from -5 V to 4.999 V (must be lower than high |
| 116 |
voltage by at least 1 mV).""", |
| 117 |
validator=strict_range, |
| 118 |
values=[-5, 4.999], |
| 119 |
) |
| 120 |
|
| 121 |
phase = Instrument.control( |
| 122 |
"SOUR{ch}:PHAS?", |
| 123 |
"SOUR{ch}:PHAS %f", |
| 124 |
""" A floating point property that controls the phase of the output |
| 125 |
waveform in degrees, from -360 degrees to 360 degrees. Not available |
| 126 |
for arbitrary waveforms or noise.""", |
| 127 |
validator=strict_range, |
| 128 |
values=[-360, 360], |
| 129 |
) |
| 130 |
|
| 131 |
square_dutycycle = Instrument.control( |
| 132 |
"SOUR{ch}:FUNC:SQU:DCYC?", |
| 133 |
"SOUR{ch}:FUNC:SQU:DCYC %f", |
| 134 |
""" A floating point property that controls the duty cycle of a square |
| 135 |
waveform function in percent, from 0.01% to 99.98%. |
| 136 |
The duty cycle is limited by the frequency and the minimal pulse width of |
| 137 |
16 ns. See manual for more details.""", |
| 138 |
validator=strict_range, |
| 139 |
values=[0.01, 99.98], |
| 140 |
) |
| 141 |
|
| 142 |
ramp_symmetry = Instrument.control( |
| 143 |
"SOUR{ch}:FUNC:RAMP:SYMM?", |
| 144 |
"SOUR{ch}:FUNC:RAMP:SYMM %f", |
| 145 |
""" A floating point property that controls the symmetry percentage |
| 146 |
for the ramp waveform, from 0.0% to 100.0%.""", |
| 147 |
validator=strict_range, |
| 148 |
values=[0, 100], |
| 149 |
) |
| 150 |
|
| 151 |
pulse_period = Instrument.control( |
| 152 |
"SOUR{ch}:FUNC:PULS:PER?", |
| 153 |
"SOUR{ch}:FUNC:PULS:PER %e", |
| 154 |
""" A floating point property that controls the period of a pulse |
| 155 |
waveform function in seconds, ranging from 33 ns to 1 Ms. Can be set |
| 156 |
and overwrites the frequency for *all* waveforms. If the period is |
| 157 |
shorter than the pulse width + the edge time, the edge time and pulse |
| 158 |
width will be adjusted accordingly. """, |
| 159 |
validator=strict_range, |
| 160 |
values=[33e-9, 1e6], |
| 161 |
) |
| 162 |
|
| 163 |
pulse_hold = Instrument.control( |
| 164 |
"SOUR{ch}:FUNC:PULS:HOLD?", |
| 165 |
"SOUR{ch}:FUNC:PULS:HOLD %s", |
| 166 |
""" A string property that controls if either the pulse width or the |
| 167 |
duty cycle is retained when changing the period or frequency of the |
| 168 |
waveform. Can be set to: WIDT<H> or DCYC<LE>. """, |
| 169 |
validator=strict_discrete_set, |
| 170 |
values=["WIDT", "WIDTH", "DCYC", "DCYCLE"], |
| 171 |
) |
| 172 |
|
| 173 |
pulse_width = Instrument.control( |
| 174 |
"SOUR{ch}:FUNC:PULS:WIDT?", |
| 175 |
"SOUR{ch}:FUNC:PULS:WIDT %e", |
| 176 |
""" A floating point property that controls the width of a pulse |
| 177 |
waveform function in seconds, ranging from 16 ns to 1e6 s, within a |
| 178 |
set of restrictions depending on the period.""", |
| 179 |
validator=strict_range, |
| 180 |
values=[16e-9, 1e6], |
| 181 |
) |
| 182 |
|
| 183 |
pulse_dutycycle = Instrument.control( |
| 184 |
"SOUR{ch}:FUNC:PULS:DCYC?", |
| 185 |
"SOUR{ch}:FUNC:PULS:DCYC %f", |
| 186 |
""" A floating point property that controls the duty cycle of a pulse |
| 187 |
waveform function in percent, from 0% to 100%.""", |
| 188 |
validator=strict_range, |
| 189 |
values=[0, 100], |
| 190 |
) |
| 191 |
|
| 192 |
pulse_transition = Instrument.control( |
| 193 |
"SOUR{ch}:FUNC:PULS:TRAN?", |
| 194 |
"SOUR{ch}:FUNC:PULS:TRAN:BOTH %e", |
| 195 |
""" A floating point property that controls the edge time in |
| 196 |
seconds for both the rising and falling edges. It is defined as the |
| 197 |
time between the 10% and 90% thresholds of the edge. |
| 198 |
Valid values are between 8.4 ns to 1 µs.""", |
| 199 |
validator=strict_range, |
| 200 |
values=[8.4e-9, 1e-6], |
| 201 |
) |
| 202 |
|
| 203 |
output = Instrument.control( |
| 204 |
"OUTP{ch}?", |
| 205 |
"OUTP{ch} %d", |
| 206 |
""" A boolean property that turns on (True, 'on') or off (False, 'off') |
| 207 |
the output of the function generator.""", |
| 208 |
validator=strict_discrete_set, |
| 209 |
map_values=True, |
| 210 |
values={True: 1, "on": 1, "ON": 1, False: 0, "off": 0, "OFF": 0}, |
| 211 |
) |
| 212 |
|
| 213 |
output_load = Instrument.control( |
| 214 |
"OUTP{ch}:LOAD?", |
| 215 |
"OUTP{ch}:LOAD %s", |
| 216 |
""" Sets the expected load resistance (should be the load impedance connected |
| 217 |
to the output. The output impedance is always 50 Ohm, this setting can be used |
| 218 |
to correct the displayed voltage for loads unmatched to 50 Ohm. |
| 219 |
Valid values are between 1 and 10 kOhm or INF for high impedance. |
| 220 |
No validator is used since both numeric and string inputs are accepted, |
| 221 |
thus a value outside the range will not return an error. |
| 222 |
""", |
| 223 |
) |
| 224 |
|
| 225 |
burst_state = Instrument.control( |
| 226 |
"SOUR{ch}:BURS:STAT?", |
| 227 |
"SOUR{ch}:BURS:STAT %d", |
| 228 |
""" A boolean property that controls whether the burst mode is on |
| 229 |
(True) or off (False).""", |
| 230 |
validator=strict_discrete_set, |
| 231 |
map_values=True, |
| 232 |
values={True: 1, False: 0}, |
| 233 |
) |
| 234 |
|
| 235 |
burst_mode = Instrument.control( |
| 236 |
"SOUR{ch}:BURS:MODE?", |
| 237 |
"SOUR{ch}:BURS:MODE %s", |
| 238 |
""" A string property that controls the burst mode. Valid values |
| 239 |
are: TRIG<GERED>, GAT<ED>.""", |
| 240 |
validator=strict_discrete_set, |
| 241 |
values=["TRIG", "TRIGGERED", "GAT", "GATED"], |
| 242 |
) |
| 243 |
|
| 244 |
burst_period = Instrument.control( |
| 245 |
"SOUR{ch}:BURS:INT:PER?", |
| 246 |
"SOUR{ch}:BURS:INT:PER %e", |
| 247 |
""" A floating point property that controls the period of subsequent bursts. |
| 248 |
Has to follow the equation burst_period > (burst_ncycles / frequency) + 1 µs. |
| 249 |
Valid values are 1 µs to 8000 s.""", |
| 250 |
validator=strict_range, |
| 251 |
values=[1e-6, 8000], |
| 252 |
) |
| 253 |
|
| 254 |
burst_ncycles = Instrument.control( |
| 255 |
"SOUR{ch}:BURS:NCYC?", |
| 256 |
"SOUR{ch}:BURS:NCYC %d", |
| 257 |
""" An integer property that sets the number of cycles to be output |
| 258 |
when a burst is triggered. Valid values are 1 to 100000. This can be |
| 259 |
set. """, |
| 260 |
validator=strict_range, |
| 261 |
values=range(1, 100000), |
| 262 |
) |
| 263 |
|
| 264 |
arb_file = Instrument.control( |
| 265 |
"SOUR{ch}:FUNC:ARB?", |
| 266 |
"SOUR{ch}:FUNC:ARB %s", |
| 267 |
""" A string property that selects the arbitrary signal from the volatile |
| 268 |
memory of the device. String has to match an existing arb signal in volatile |
| 269 |
memory (set by :meth:`data_arb`).""", |
| 270 |
) |
| 271 |
|
| 272 |
arb_advance = Instrument.control( |
| 273 |
"SOUR{ch}:FUNC:ARB:ADV?", |
| 274 |
"SOUR{ch}:FUNC:ARB:ADV %s", |
| 275 |
""" A string property that selects how the device advances from data point |
| 276 |
to data point. Can be set to 'TRIG<GER>' or 'SRAT<E>' (default). """, |
| 277 |
validator=strict_discrete_set, |
| 278 |
values=["TRIG", "TRIGGER", "SRAT", "SRATE"], |
| 279 |
) |
| 280 |
|
| 281 |
arb_filter = Instrument.control( |
| 282 |
"SOUR{ch}:FUNC:ARB:FILT?", |
| 283 |
"SOUR{ch}:FUNC:ARB:FILT %s", |
| 284 |
""" A string property that selects the filter setting for arbitrary signals. |
| 285 |
Can be set to 'NORM<AL>', 'STEP' and 'OFF'. """, |
| 286 |
validator=strict_discrete_set, |
| 287 |
values=["NORM", "NORMAL", "STEP", "OFF"], |
| 288 |
) |
| 289 |
|
| 290 |
arb_srate = Instrument.control( |
| 291 |
"SOUR{ch}:FUNC:ARB:SRAT?", |
| 292 |
"SOUR{ch}:FUNC:ARB:SRAT %f", |
| 293 |
""" An floating point property that sets the sample rate of the currently selected |
| 294 |
arbitrary signal. Valid values are 1 µSa/s to 250 MSa/s (maximum range, can be lower |
| 295 |
depending on your device).""", |
| 296 |
validator=strict_range, |
| 297 |
values=[1e-6, 250e6], |
| 298 |
) |
| 299 |
|
| 300 |
def data_volatile_clear(self): |
| 301 |
""" |
| 302 |
Clear all arbitrary signals from volatile memory for a given channel. |
| 303 |
|
| 304 |
This should be done if the same name is used continuously to load |
| 305 |
different arbitrary signals into the memory, since an error will occur |
| 306 |
if a trace is loaded which already exists in memory. |
| 307 |
""" |
| 308 |
self.write("SOUR{ch}:DATA:VOL:CLE") |
| 309 |
|
| 310 |
def data_arb(self, arb_name, data_points, data_format="DAC"): |
| 311 |
""" |
| 312 |
Uploads an arbitrary trace into the volatile memory of the device for a given channel. |
| 313 |
|
| 314 |
The data_points can be given as: |
| 315 |
comma separated 16 bit DAC values (ranging from -32767 to +32767), |
| 316 |
as comma separated floating point values (ranging from -1.0 to +1.0), |
| 317 |
or as a binary data stream. |
| 318 |
Check the manual for more information. The storage depends on the device type and ranges |
| 319 |
from 8 Sa to 16 MSa (maximum). |
| 320 |
|
| 321 |
:param arb_name: The name of the trace in the volatile memory. This is used to access the |
| 322 |
trace. |
| 323 |
|
| 324 |
:param data_points: Individual points of the trace. The format depends on the format |
| 325 |
parameter. |
| 326 |
|
| 327 |
format = 'DAC' (default): Accepts list of integer values ranging from |
| 328 |
-32767 to +32767. Minimum of 8 a maximum of 65536 points. |
| 329 |
|
| 330 |
format = 'float': Accepts list of floating point values ranging from |
| 331 |
-1.0 to +1.0. Minimum of 8 a maximum of 65536 points. |
| 332 |
|
| 333 |
format = 'binary': Accepts a binary stream of 8 bit data. |
| 334 |
:param data_format: Defines the format of data_points. Can be 'DAC' (default), 'float' or |
| 335 |
'binary'. See documentation on parameter data_points above. |
| 336 |
""" |
| 337 |
if data_format == "DAC": |
| 338 |
separator = ", " |
| 339 |
data_points_str = [str(item) for item in data_points] # Turn list entries into strings |
| 340 |
data_string = separator.join(data_points_str) # Join strings with separator |
| 341 |
self.write(f"SOUR{{ch}}:DATA:ARB:DAC {arb_name}, {data_string}") |
| 342 |
return |
| 343 |
elif data_format == "float": |
| 344 |
separator = ", " |
| 345 |
data_points_str = [str(item) for item in data_points] # Turn list entries into strings |
| 346 |
data_string = separator.join(data_points_str) # Join strings with separator |
| 347 |
self.write(f"SOUR{{ch}}:DATA:ARB {arb_name}, {data_string}") |
| 348 |
return |
| 349 |
elif data_format == "binary": # TODO: *Binary is not yet implemented* |
| 350 |
raise NotImplementedError( |
| 351 |
'The binary format has not yet been implemented. Use "DAC" or "float" instead.' |
| 352 |
) |
| 353 |
else: |
| 354 |
raise ValueError( |
| 355 |
'Undefined format keyword was used. Valid entries are "DAC", "float" and "binary"' |
| 356 |
) |
| 357 |
|
| 358 |
|
| 359 |
class Agilent33500(SCPIUnknownMixin, Instrument): |
| 360 |
""" |
| 361 |
Represents the Agilent 33500 Function/Arbitrary Waveform Generator family. |
| 362 |
|
| 363 |
Individual devices are represented by subclasses. |
| 364 |
User can specify a channel to control, if no channel specified, a default channel |
| 365 |
is picked based on the device e.g. For Agilent33500B the default channel |
| 366 |
is channel 1. See reference manual for your device |
| 367 |
|
| 368 |
.. code-block:: python |
| 369 |
|
| 370 |
generator = Agilent33500("GPIB::1") |
| 371 |
|
| 372 |
generator.shape = 'SIN' # Sets default channel output signal shape to sine |
| 373 |
generator.channels[1].shape = 'SIN' # Sets channel 1 output signal shape to sine |
| 374 |
generator.frequency = 1e3 # Sets default channel output frequency to 1 kHz |
| 375 |
generator.channels[1].frequency = 1e3 # Sets channel 1 output frequency to 1 kHz |
| 376 |
generator.channels[2].amplitude = 5 # Sets channel 2 output amplitude to 5 Vpp |
| 377 |
generator.channels[2].output = 'on' # Enables channel 2 output |
| 378 |
|
| 379 |
generator.channels[1].shape = 'ARB' # Set channel 1 shape to arbitrary |
| 380 |
generator.channels[1].arb_srate = 1e6 # Set channel 1 sample rate to 1MSa/s |
| 381 |
|
| 382 |
generator.channels[1].data_volatile_clear() # Clear channel 1 volatile internal memory |
| 383 |
generator.channels[1].data_arb( # Send data of arbitrary waveform to channel 1 |
| 384 |
'test', |
| 385 |
range(-10000, 10000, +20), # In this case a simple ramp |
| 386 |
data_format='DAC' # Data format is set to 'DAC' |
| 387 |
) |
| 388 |
generator.channels[1].arb_file = 'test' # Select the transmitted waveform 'test' |
| 389 |
|
| 390 |
""" |
| 391 |
|
| 392 |
ch_1 = Instrument.ChannelCreator(Agilent33500Channel, 1) |
| 393 |
|
| 394 |
ch_2 = Instrument.ChannelCreator(Agilent33500Channel, 2) |
| 395 |
|
| 396 |
def __init__(self, adapter, name="Agilent 33500 Function/Arbitrary Waveform generator family", |
| 397 |
**kwargs): |
| 398 |
super().__init__( |
| 399 |
adapter, name, **kwargs |
| 400 |
) |
| 401 |
|
| 402 |
def beep(self): |
| 403 |
"""Causes a system beep.""" |
| 404 |
self.write("SYST:BEEP") |
| 405 |
|
| 406 |
shape = Instrument.control( |
| 407 |
"FUNC?", |
| 408 |
"FUNC %s", |
| 409 |
""" A string property that controls the output waveform. Can be set to: |
| 410 |
SIN<USOID>, SQU<ARE>, TRI<ANGLE>, RAMP, PULS<E>, PRBS, NOIS<E>, ARB, DC. """, |
| 411 |
validator=strict_discrete_set, |
| 412 |
values=["SIN", "SQU", "TRI", "RAMP", "PULS", "PRBS", "NOIS", "ARB", "DC"], |
| 413 |
) |
| 414 |
|
| 415 |
frequency = Instrument.control( |
| 416 |
"FREQ?", |
| 417 |
"FREQ %f", |
| 418 |
""" A floating point property that controls the frequency of the output |
| 419 |
waveform in Hz, from 1 uHz to 120 MHz (maximum range, can be lower depending |
| 420 |
on your device), depending on the specified function.""", |
| 421 |
validator=strict_range, |
| 422 |
values=[1e-6, 120e6], |
| 423 |
) |
| 424 |
|
| 425 |
amplitude = Instrument.control( |
| 426 |
"VOLT?", |
| 427 |
"VOLT %f", |
| 428 |
""" A floating point property that controls the voltage amplitude of the |
| 429 |
output waveform in V, from 10e-3 V to 10 V. Depends on the output |
| 430 |
impedance.""", |
| 431 |
validator=strict_range, |
| 432 |
values=[10e-3, 10], |
| 433 |
) |
| 434 |
|
| 435 |
amplitude_unit = Instrument.control( |
| 436 |
"VOLT:UNIT?", |
| 437 |
"VOLT:UNIT %s", |
| 438 |
""" A string property that controls the units of the amplitude. Valid |
| 439 |
values are VPP (default), VRMS, and DBM.""", |
| 440 |
validator=strict_discrete_set, |
| 441 |
values=["VPP", "VRMS", "DBM"], |
| 442 |
) |
| 443 |
|
| 444 |
offset = Instrument.control( |
| 445 |
"VOLT:OFFS?", |
| 446 |
"VOLT:OFFS %f", |
| 447 |
""" A floating point property that controls the voltage offset of the |
| 448 |
output waveform in V, from 0 V to 4.995 V, depending on the set |
| 449 |
voltage amplitude (maximum offset = (Vmax - voltage) / 2). |
| 450 |
""", |
| 451 |
validator=strict_range, |
| 452 |
values=[-4.995, +4.995], |
| 453 |
) |
| 454 |
|
| 455 |
voltage_high = Instrument.control( |
| 456 |
"VOLT:HIGH?", |
| 457 |
"VOLT:HIGH %f", |
| 458 |
""" A floating point property that controls the upper voltage of the |
| 459 |
output waveform in V, from -4.999 V to 5 V (must be higher than low |
| 460 |
voltage by at least 1 mV).""", |
| 461 |
validator=strict_range, |
| 462 |
values=[-4.999, 5], |
| 463 |
) |
| 464 |
|
| 465 |
voltage_low = Instrument.control( |
| 466 |
"VOLT:LOW?", |
| 467 |
"VOLT:LOW %f", |
| 468 |
""" A floating point property that controls the lower voltage of the |
| 469 |
output waveform in V, from -5 V to 4.999 V (must be lower than high |
| 470 |
voltage by at least 1 mV).""", |
| 471 |
validator=strict_range, |
| 472 |
values=[-5, 4.999], |
| 473 |
) |
| 474 |
|
| 475 |
phase = Instrument.control( |
| 476 |
"PHAS?", |
| 477 |
"PHAS %f", |
| 478 |
""" A floating point property that controls the phase of the output |
| 479 |
waveform in degrees, from -360 degrees to 360 degrees. Not available |
| 480 |
for arbitrary waveforms or noise.""", |
| 481 |
validator=strict_range, |
| 482 |
values=[-360, 360], |
| 483 |
) |
| 484 |
|
| 485 |
square_dutycycle = Instrument.control( |
| 486 |
"FUNC:SQU:DCYC?", |
| 487 |
"FUNC:SQU:DCYC %f", |
| 488 |
""" A floating point property that controls the duty cycle of a square |
| 489 |
waveform function in percent, from 0.01% to 99.98%. |
| 490 |
The duty cycle is limited by the frequency and the minimal pulse width of |
| 491 |
16 ns. See manual for more details.""", |
| 492 |
validator=strict_range, |
| 493 |
values=[0.01, 99.98], |
| 494 |
) |
| 495 |
|
| 496 |
ramp_symmetry = Instrument.control( |
| 497 |
"FUNC:RAMP:SYMM?", |
| 498 |
"FUNC:RAMP:SYMM %f", |
| 499 |
""" A floating point property that controls the symmetry percentage |
| 500 |
for the ramp waveform, from 0.0% to 100.0%.""", |
| 501 |
validator=strict_range, |
| 502 |
values=[0, 100], |
| 503 |
) |
| 504 |
|
| 505 |
pulse_period = Instrument.control( |
| 506 |
"FUNC:PULS:PER?", |
| 507 |
"FUNC:PULS:PER %e", |
| 508 |
""" A floating point property that controls the period of a pulse |
| 509 |
waveform function in seconds, ranging from 33 ns to 1e6 s. Can be set |
| 510 |
and overwrites the frequency for *all* waveforms. If the period is |
| 511 |
shorter than the pulse width + the edge time, the edge time and pulse |
| 512 |
width will be adjusted accordingly. """, |
| 513 |
validator=strict_range, |
| 514 |
values=[33e-9, 1e6], |
| 515 |
) |
| 516 |
|
| 517 |
pulse_hold = Instrument.control( |
| 518 |
"FUNC:PULS:HOLD?", |
| 519 |
"FUNC:PULS:HOLD %s", |
| 520 |
""" A string property that controls if either the pulse width or the |
| 521 |
duty cycle is retained when changing the period or frequency of the |
| 522 |
waveform. Can be set to: WIDT<H> or DCYC<LE>. """, |
| 523 |
validator=strict_discrete_set, |
| 524 |
values=["WIDT", "WIDTH", "DCYC", "DCYCLE"], |
| 525 |
) |
| 526 |
|
| 527 |
pulse_width = Instrument.control( |
| 528 |
"FUNC:PULS:WIDT?", |
| 529 |
"FUNC:PULS:WIDT %e", |
| 530 |
""" A floating point property that controls the width of a pulse |
| 531 |
waveform function in seconds, ranging from 16 ns to 1 Ms, within a |
| 532 |
set of restrictions depending on the period.""", |
| 533 |
validator=strict_range, |
| 534 |
values=[16e-9, 1e6], |
| 535 |
) |
| 536 |
|
| 537 |
pulse_dutycycle = Instrument.control( |
| 538 |
"FUNC:PULS:DCYC?", |
| 539 |
"FUNC:PULS:DCYC %f", |
| 540 |
""" A floating point property that controls the duty cycle of a pulse |
| 541 |
waveform function in percent, from 0% to 100%.""", |
| 542 |
validator=strict_range, |
| 543 |
values=[0, 100], |
| 544 |
) |
| 545 |
|
| 546 |
pulse_transition = Instrument.control( |
| 547 |
"FUNC:PULS:TRAN?", |
| 548 |
"FUNC:PULS:TRAN:BOTH %e", |
| 549 |
""" A floating point property that controls the edge time in |
| 550 |
seconds for both the rising and falling edges. It is defined as the |
| 551 |
time between the 10% and 90% thresholds of the edge. |
| 552 |
Valid values are between 8.4 ns to 1 µs.""", |
| 553 |
validator=strict_range, |
| 554 |
values=[8.4e-9, 1e-6], |
| 555 |
) |
| 556 |
|
| 557 |
output = Instrument.control( |
| 558 |
"OUTP?", |
| 559 |
"OUTP %d", |
| 560 |
""" A boolean property that turns on (True, 'on') or off (False, 'off') |
| 561 |
the output of the function generator.""", |
| 562 |
validator=strict_discrete_set, |
| 563 |
map_values=True, |
| 564 |
values={True: 1, "on": 1, "ON": 1, False: 0, "off": 0, "OFF": 0}, |
| 565 |
) |
| 566 |
|
| 567 |
output_load = Instrument.control( |
| 568 |
"OUTP:LOAD?", |
| 569 |
"OUTP:LOAD %s", |
| 570 |
""" Sets the expected load resistance (should be the load impedance connected |
| 571 |
to the output. The output impedance is always 50 Ohm, this setting can be used |
| 572 |
to correct the displayed voltage for loads unmatched to 50 Ohm. |
| 573 |
Valid values are between 1 and 10 kOhm or INF for high impedance. |
| 574 |
No validator is used since both numeric and string inputs are accepted, |
| 575 |
thus a value outside the range will not return an error. |
| 576 |
""", |
| 577 |
) |
| 578 |
|
| 579 |
burst_state = Instrument.control( |
| 580 |
"BURS:STAT?", |
| 581 |
"BURS:STAT %d", |
| 582 |
""" A boolean property that controls whether the burst mode is on |
| 583 |
(True) or off (False).""", |
| 584 |
validator=strict_discrete_set, |
| 585 |
map_values=True, |
| 586 |
values={True: 1, False: 0}, |
| 587 |
) |
| 588 |
|
| 589 |
burst_mode = Instrument.control( |
| 590 |
"BURS:MODE?", |
| 591 |
"BURS:MODE %s", |
| 592 |
""" A string property that controls the burst mode. Valid values |
| 593 |
are: TRIG<GERED>, GAT<ED>.""", |
| 594 |
validator=strict_discrete_set, |
| 595 |
values=["TRIG", "TRIGGERED", "GAT", "GATED"], |
| 596 |
) |
| 597 |
|
| 598 |
burst_period = Instrument.control( |
| 599 |
"BURS:INT:PER?", |
| 600 |
"BURS:INT:PER %e", |
| 601 |
""" A floating point property that controls the period of subsequent bursts. |
| 602 |
Has to follow the equation burst_period > (burst_ncycles / frequency) + 1 µs. |
| 603 |
Valid values are 1 µs to 8000 s.""", |
| 604 |
validator=strict_range, |
| 605 |
values=[1e-6, 8000], |
| 606 |
) |
| 607 |
|
| 608 |
burst_ncycles = Instrument.control( |
| 609 |
"BURS:NCYC?", |
| 610 |
"BURS:NCYC %d", |
| 611 |
""" An integer property that sets the number of cycles to be output |
| 612 |
when a burst is triggered. Valid values are 1 to 100000. This can be |
| 613 |
set. """, |
| 614 |
validator=strict_range, |
| 615 |
values=range(1, 100000), |
| 616 |
) |
| 617 |
|
| 618 |
arb_file = Instrument.control( |
| 619 |
"FUNC:ARB?", |
| 620 |
"FUNC:ARB %s", |
| 621 |
""" A string property that selects the arbitrary signal from the volatile |
| 622 |
memory of the device. String has to match an existing arb signal in volatile |
| 623 |
memory (set by :meth:`data_arb`).""", |
| 624 |
) |
| 625 |
|
| 626 |
arb_advance = Instrument.control( |
| 627 |
"FUNC:ARB:ADV?", |
| 628 |
"FUNC:ARB:ADV %s", |
| 629 |
""" A string property that selects how the device advances from data point |
| 630 |
to data point. Can be set to 'TRIG<GER>' or 'SRAT<E>' (default). """, |
| 631 |
validator=strict_discrete_set, |
| 632 |
values=["TRIG", "TRIGGER", "SRAT", "SRATE"], |
| 633 |
) |
| 634 |
|
| 635 |
arb_filter = Instrument.control( |
| 636 |
"FUNC:ARB:FILT?", |
| 637 |
"FUNC:ARB:FILT %s", |
| 638 |
""" A string property that selects the filter setting for arbitrary signals. |
| 639 |
Can be set to 'NORM<AL>', 'STEP' and 'OFF'. """, |
| 640 |
validator=strict_discrete_set, |
| 641 |
values=["NORM", "NORMAL", "STEP", "OFF"], |
| 642 |
) |
| 643 |
# TODO: This implementation is currently not working. Do not know why. |
| 644 |
# arb_period = Instrument.control( |
| 645 |
# "FUNC:ARB:PER?", "FUNC:ARB:PER %e", |
| 646 |
# """ A floating point property that controls the period of the arbitrary signal. |
| 647 |
# Limited by number of signal points. Check for instrument errors when setting |
| 648 |
# this property.""", |
| 649 |
# validator=strict_range, |
| 650 |
# values=[33e-9, 1e6], |
| 651 |
# ) |
| 652 |
# |
| 653 |
# arb_frequency = Instrument.control( |
| 654 |
# "FUNC:ARB:FREQ?", "FUNC:ARB:FREQ %f", |
| 655 |
# """ A floating point property that controls the frequency of the arbitrary signal. |
| 656 |
# Limited by number of signal points. Check for instrument |
| 657 |
# errors when setting this property.""", |
| 658 |
# validator=strict_range, |
| 659 |
# values=[1e-6, 30e+6], |
| 660 |
# ) |
| 661 |
# |
| 662 |
# arb_npoints = Instrument.measurement( |
| 663 |
# "FUNC:ARB:POIN?", |
| 664 |
# """ Returns the number of points in the currently selected arbitrary trace. """ |
| 665 |
# ) |
| 666 |
# |
| 667 |
# arb_voltage = Instrument.control( |
| 668 |
# "FUNC:ARB:PTP?", "FUNC:ARB:PTP %f", |
| 669 |
# """ An floating point property that sets the peak-to-peak voltage for the |
| 670 |
# currently selected arbitrary signal. Valid values are 1 mV to 10 V. This can be |
| 671 |
# set. """, |
| 672 |
# validator=strict_range, |
| 673 |
# values=[0.001, 10], |
| 674 |
# ) |
| 675 |
|
| 676 |
arb_srate = Instrument.control( |
| 677 |
"FUNC:ARB:SRAT?", |
| 678 |
"FUNC:ARB:SRAT %f", |
| 679 |
""" An floating point property that sets the sample rate of the currently selected |
| 680 |
arbitrary signal. Valid values are 1 µSa/s to 250 MSa/s (maximum range, can be lower |
| 681 |
depending on your device).""", |
| 682 |
validator=strict_range, |
| 683 |
values=[1e-6, 250e6], |
| 684 |
) |
| 685 |
|
| 686 |
def data_volatile_clear(self): |
| 687 |
""" |
| 688 |
Clear all arbitrary signals from volatile memory. |
| 689 |
|
| 690 |
This should be done if the same name is used continuously to load |
| 691 |
different arbitrary signals into the memory, since an error |
| 692 |
will occur if a trace is loaded which already exists in the memory. |
| 693 |
""" |
| 694 |
self.write("DATA:VOL:CLE") |
| 695 |
|
| 696 |
def phase_sync(self): |
| 697 |
""" Synchronize the phase of all channels.""" |
| 698 |
self.write("PHAS:SYNC") |
| 699 |
|
| 700 |
def data_arb(self, arb_name, data_points, data_format="DAC"): |
| 701 |
""" |
| 702 |
Uploads an arbitrary trace into the volatile memory of the device. |
| 703 |
|
| 704 |
The data_points can be given as: |
| 705 |
comma separated 16 bit DAC values (ranging from -32767 to +32767), |
| 706 |
as comma separated floating point values (ranging from -1.0 to +1.0) |
| 707 |
or as a binary data stream. |
| 708 |
Check the manual for more information. |
| 709 |
The storage depends on the device type and ranges |
| 710 |
from 8 Sa to 16 MSa (maximum). |
| 711 |
|
| 712 |
:param arb_name: The name of the trace in the volatile memory. This is used to access the |
| 713 |
trace. |
| 714 |
:param data_points: Individual points of the trace. The format depends on the format |
| 715 |
parameter. |
| 716 |
format = 'DAC' (default): Accepts list of integer values ranging from |
| 717 |
-32767 to +32767. Minimum of 8 a maximum of 65536 points. |
| 718 |
format = 'float': Accepts list of floating point values ranging from |
| 719 |
-1.0 to +1.0. Minimum of 8 a maximum of 65536 points. |
| 720 |
format = 'binary': Accepts a binary stream of 8 bit data. |
| 721 |
:param data_format: Defines the format of data_points. Can be 'DAC' (default), 'float' or |
| 722 |
'binary'. See documentation on parameter data_points above. |
| 723 |
""" |
| 724 |
if data_format == "DAC": |
| 725 |
separator = ", " |
| 726 |
data_points_str = [str(item) for item in data_points] # Turn list entries into strings |
| 727 |
data_string = separator.join(data_points_str) # Join strings with separator |
| 728 |
self.write(f"DATA:ARB:DAC {arb_name}, {data_string}") |
| 729 |
return |
| 730 |
elif data_format == "float": |
| 731 |
separator = ", " |
| 732 |
data_points_str = [str(item) for item in data_points] # Turn list entries into strings |
| 733 |
data_string = separator.join(data_points_str) # Join strings with separator |
| 734 |
self.write(f"DATA:ARB {arb_name}, {data_string}") |
| 735 |
return |
| 736 |
elif data_format == "binary": # TODO: *Binary is not yet implemented* |
| 737 |
raise NotImplementedError( |
| 738 |
'The binary format has not yet been implemented. Use "DAC" or "float" instead.' |
| 739 |
) |
| 740 |
else: |
| 741 |
raise ValueError( |
| 742 |
'Undefined format keyword was used. Valid entries are "DAC", "float" and "binary"' |
| 743 |
) |
| 744 |
|
| 745 |
display = Instrument.setting( |
| 746 |
"DISP:TEXT '%s'", |
| 747 |
""" A string property which is displayed on the front panel of |
| 748 |
the device.""", |
| 749 |
) |
| 750 |
|
| 751 |
def clear_display(self): |
| 752 |
"""Removes a text message from the display.""" |
| 753 |
self.write("DISP:TEXT:CLE") |
| 754 |
|
| 755 |
def trigger(self): |
| 756 |
"""Send a trigger signal to the function generator.""" |
| 757 |
self.write("*TRG;*WAI") |
| 758 |
|
| 759 |
def wait_for_trigger(self, timeout=3600, should_stop=lambda: False): |
| 760 |
""" |
| 761 |
Wait until the triggering has finished or timeout is reached. |
| 762 |
|
| 763 |
:param timeout: The maximum time the waiting is allowed to take. If |
| 764 |
timeout is exceeded, a TimeoutError is raised. If |
| 765 |
timeout is set to zero, no timeout will be used. |
| 766 |
:param should_stop: Optional function (returning a bool) to allow the |
| 767 |
waiting to be stopped before its end. |
| 768 |
|
| 769 |
""" |
| 770 |
self.write("*OPC?") |
| 771 |
|
| 772 |
t0 = time() |
| 773 |
while True: |
| 774 |
try: |
| 775 |
ready = bool(self.read()) |
| 776 |
except VisaIOError: |
| 777 |
ready = False |
| 778 |
|
| 779 |
if ready: |
| 780 |
return |
| 781 |
|
| 782 |
if timeout != 0 and time() - t0 > timeout: |
| 783 |
raise TimeoutError( |
| 784 |
"Timeout expired while waiting for the Agilent 33220A" |
| 785 |
+ " to finish the triggering." |
| 786 |
) |
| 787 |
|
| 788 |
if should_stop: |
| 789 |
return |
| 790 |
|
| 791 |
trigger_source = Instrument.control( |
| 792 |
"TRIG:SOUR?", |
| 793 |
"TRIG:SOUR %s", |
| 794 |
""" A string property that controls the trigger source. Valid values |
| 795 |
are: IMM<EDIATE> (internal), EXT<ERNAL> (rear input), BUS (via trigger |
| 796 |
command).""", |
| 797 |
validator=strict_discrete_set, |
| 798 |
values=["IMM", "IMMEDIATE", "EXT", "EXTERNAL", "BUS"], |
| 799 |
) |
| 800 |
|
| 801 |
ext_trig_out = Instrument.control( |
| 802 |
"OUTP:TRIG?", |
| 803 |
"OUTP:TRIG %d", |
| 804 |
""" A boolean property that controls whether the trigger out signal is |
| 805 |
active (True) or not (False). This signal is output from the Ext Trig |
| 806 |
connector on the rear panel in Burst and Wobbel mode.""", |
| 807 |
validator=strict_discrete_set, |
| 808 |
map_values=True, |
| 809 |
values={True: 1, False: 0}, |
| 810 |
) |