| 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 pytest |
| 26 |
from pymeasure.test import expected_protocol |
| 27 |
from pymeasure.instruments.agilent.agilent33500 import Agilent33500 |
| 28 |
|
| 29 |
|
| 30 |
@pytest.mark.parametrize( |
| 31 |
"shape", ["SIN", "SQU", "TRI", "RAMP", "PULS", "PRBS", "NOIS", "ARB", "DC"] |
| 32 |
) |
| 33 |
def test_shape(shape): |
| 34 |
""" |
| 35 |
Test Agilent 33500 shape function |
| 36 |
""" |
| 37 |
with expected_protocol( |
| 38 |
Agilent33500, |
| 39 |
[ |
| 40 |
("SOUR1:FUNC?", shape), |
| 41 |
("SOUR2:FUNC?", shape), |
| 42 |
("FUNC?", shape), |
| 43 |
(f"SOUR1:FUNC {shape}", None), |
| 44 |
(f"SOUR2:FUNC {shape}", None), |
| 45 |
(f"FUNC {shape}", None), |
| 46 |
], |
| 47 |
) as inst: |
| 48 |
assert shape == inst.ch_1.shape |
| 49 |
assert shape == inst.ch_2.shape |
| 50 |
assert shape == inst.shape |
| 51 |
inst.ch_1.shape = shape |
| 52 |
inst.ch_2.shape = shape |
| 53 |
inst.shape = shape |
| 54 |
|
| 55 |
|
| 56 |
@pytest.mark.parametrize("frequency", [1e-6, 1.2e8]) |
| 57 |
def test_frequency(frequency): |
| 58 |
""" |
| 59 |
Test Agilent 33500 frequency function |
| 60 |
""" |
| 61 |
with expected_protocol( |
| 62 |
Agilent33500, |
| 63 |
[ |
| 64 |
("SOUR1:FREQ?", frequency), |
| 65 |
("SOUR2:FREQ?", frequency), |
| 66 |
("FREQ?", frequency), |
| 67 |
(f"SOUR1:FREQ {frequency:.6f}", None), |
| 68 |
(f"SOUR2:FREQ {frequency:.6f}", None), |
| 69 |
(f"FREQ {frequency:.6f}", None), |
| 70 |
], |
| 71 |
) as inst: |
| 72 |
assert frequency == inst.ch_1.frequency |
| 73 |
assert frequency == inst.ch_2.frequency |
| 74 |
assert frequency == inst.frequency |
| 75 |
inst.ch_1.frequency = frequency |
| 76 |
inst.ch_2.frequency = frequency |
| 77 |
inst.frequency = frequency |
| 78 |
|
| 79 |
|
| 80 |
@pytest.mark.parametrize("amplitude", [10e-3, 10]) |
| 81 |
def test_amplitude(amplitude): |
| 82 |
""" |
| 83 |
Test Agilent 33500 amplitude function |
| 84 |
""" |
| 85 |
with expected_protocol( |
| 86 |
Agilent33500, |
| 87 |
[ |
| 88 |
("SOUR1:VOLT?", amplitude), |
| 89 |
("SOUR2:VOLT?", amplitude), |
| 90 |
("VOLT?", amplitude), |
| 91 |
(f"SOUR1:VOLT {amplitude:.6f}", None), |
| 92 |
(f"SOUR2:VOLT {amplitude:.6f}", None), |
| 93 |
(f"VOLT {amplitude:.6f}", None), |
| 94 |
], |
| 95 |
) as inst: |
| 96 |
assert amplitude == inst.ch_1.amplitude |
| 97 |
assert amplitude == inst.ch_2.amplitude |
| 98 |
assert amplitude == inst.amplitude |
| 99 |
inst.ch_1.amplitude = amplitude |
| 100 |
inst.ch_2.amplitude = amplitude |
| 101 |
inst.amplitude = amplitude |
| 102 |
|
| 103 |
|
| 104 |
@pytest.mark.parametrize("amplitude_unit", ["VPP", "VRMS", "DBM"]) |
| 105 |
def test_amplitude_unit(amplitude_unit): |
| 106 |
""" |
| 107 |
Test Agilent 33500 amplitude unit function |
| 108 |
""" |
| 109 |
with expected_protocol( |
| 110 |
Agilent33500, |
| 111 |
[ |
| 112 |
("SOUR1:VOLT:UNIT?", amplitude_unit), |
| 113 |
("SOUR2:VOLT:UNIT?", amplitude_unit), |
| 114 |
("VOLT:UNIT?", amplitude_unit), |
| 115 |
(f"SOUR1:VOLT:UNIT {amplitude_unit}", None), |
| 116 |
(f"SOUR2:VOLT:UNIT {amplitude_unit}", None), |
| 117 |
(f"VOLT:UNIT {amplitude_unit}", None), |
| 118 |
], |
| 119 |
) as inst: |
| 120 |
assert amplitude_unit == inst.ch_1.amplitude_unit |
| 121 |
assert amplitude_unit == inst.ch_2.amplitude_unit |
| 122 |
assert amplitude_unit == inst.amplitude_unit |
| 123 |
inst.ch_1.amplitude_unit = amplitude_unit |
| 124 |
inst.ch_2.amplitude_unit = amplitude_unit |
| 125 |
inst.amplitude_unit = amplitude_unit |
| 126 |
|
| 127 |
|
| 128 |
@pytest.mark.parametrize("state", [0, 1]) |
| 129 |
def test_output(state): |
| 130 |
""" |
| 131 |
Test Agilent 33500 output function |
| 132 |
""" |
| 133 |
with expected_protocol( |
| 134 |
Agilent33500, |
| 135 |
[ |
| 136 |
("OUTP1?", state), |
| 137 |
("OUTP2?", state), |
| 138 |
("OUTP?", state), |
| 139 |
(f"OUTP1 {state}", None), |
| 140 |
(f"OUTP2 {state}", None), |
| 141 |
(f"OUTP {state}", None), |
| 142 |
], |
| 143 |
) as inst: |
| 144 |
assert state == inst.ch_1.output |
| 145 |
assert state == inst.ch_2.output |
| 146 |
assert state == inst.output |
| 147 |
inst.ch_1.output = state |
| 148 |
inst.ch_2.output = state |
| 149 |
inst.output = state |
| 150 |
|
| 151 |
|
| 152 |
@pytest.mark.parametrize("offset", [-4.995, 4.995]) |
| 153 |
def test_offset(offset): |
| 154 |
""" |
| 155 |
Test Agilent 33500 offset function |
| 156 |
""" |
| 157 |
with expected_protocol( |
| 158 |
Agilent33500, |
| 159 |
[ |
| 160 |
("SOUR1:VOLT:OFFS?", offset), |
| 161 |
("SOUR2:VOLT:OFFS?", offset), |
| 162 |
("VOLT:OFFS?", offset), |
| 163 |
(f"SOUR1:VOLT:OFFS {offset:.6f}", None), |
| 164 |
(f"SOUR2:VOLT:OFFS {offset:.6f}", None), |
| 165 |
(f"VOLT:OFFS {offset:.6f}", None), |
| 166 |
], |
| 167 |
) as inst: |
| 168 |
assert offset == inst.ch_1.offset |
| 169 |
assert offset == inst.ch_2.offset |
| 170 |
assert offset == inst.offset |
| 171 |
inst.ch_1.offset = offset |
| 172 |
inst.ch_2.offset = offset |
| 173 |
inst.offset = offset |
| 174 |
|
| 175 |
|
| 176 |
@pytest.mark.parametrize("voltage_high", [-4.995, 4.995]) |
| 177 |
def test_voltage_high(voltage_high): |
| 178 |
""" |
| 179 |
Test Agilent 33500 voltage_high function |
| 180 |
""" |
| 181 |
with expected_protocol( |
| 182 |
Agilent33500, |
| 183 |
[ |
| 184 |
("SOUR1:VOLT:HIGH?", voltage_high), |
| 185 |
("SOUR2:VOLT:HIGH?", voltage_high), |
| 186 |
("VOLT:HIGH?", voltage_high), |
| 187 |
(f"SOUR1:VOLT:HIGH {voltage_high:.6f}", None), |
| 188 |
(f"SOUR2:VOLT:HIGH {voltage_high:.6f}", None), |
| 189 |
(f"VOLT:HIGH {voltage_high:.6f}", None), |
| 190 |
], |
| 191 |
) as inst: |
| 192 |
assert voltage_high == inst.ch_1.voltage_high |
| 193 |
assert voltage_high == inst.ch_2.voltage_high |
| 194 |
assert voltage_high == inst.voltage_high |
| 195 |
inst.ch_1.voltage_high = voltage_high |
| 196 |
inst.ch_2.voltage_high = voltage_high |
| 197 |
inst.voltage_high = voltage_high |
| 198 |
|
| 199 |
|
| 200 |
@pytest.mark.parametrize("voltage_low", [-4.995, 4.995]) |
| 201 |
def test_voltage_low(voltage_low): |
| 202 |
""" |
| 203 |
Test Agilent 33500 voltage_low function |
| 204 |
""" |
| 205 |
with expected_protocol( |
| 206 |
Agilent33500, |
| 207 |
[ |
| 208 |
("SOUR1:VOLT:LOW?", voltage_low), |
| 209 |
("SOUR2:VOLT:LOW?", voltage_low), |
| 210 |
("VOLT:LOW?", voltage_low), |
| 211 |
(f"SOUR1:VOLT:LOW {voltage_low:.6f}", None), |
| 212 |
(f"SOUR2:VOLT:LOW {voltage_low:.6f}", None), |
| 213 |
(f"VOLT:LOW {voltage_low:.6f}", None), |
| 214 |
], |
| 215 |
) as inst: |
| 216 |
assert voltage_low == inst.ch_1.voltage_low |
| 217 |
assert voltage_low == inst.ch_2.voltage_low |
| 218 |
assert voltage_low == inst.voltage_low |
| 219 |
inst.ch_1.voltage_low = voltage_low |
| 220 |
inst.ch_2.voltage_low = voltage_low |
| 221 |
inst.voltage_low = voltage_low |
| 222 |
|
| 223 |
|
| 224 |
@pytest.mark.parametrize("phase", [-360, 360]) |
| 225 |
def test_phase(phase): |
| 226 |
""" |
| 227 |
Test Agilent 33500 phase function |
| 228 |
""" |
| 229 |
with expected_protocol( |
| 230 |
Agilent33500, |
| 231 |
[ |
| 232 |
("SOUR1:PHAS?", phase), |
| 233 |
("SOUR2:PHAS?", phase), |
| 234 |
("PHAS?", phase), |
| 235 |
(f"SOUR1:PHAS {phase:.6f}", None), |
| 236 |
(f"SOUR2:PHAS {phase:.6f}", None), |
| 237 |
(f"PHAS {phase:.6f}", None), |
| 238 |
], |
| 239 |
) as inst: |
| 240 |
assert phase == inst.ch_1.phase |
| 241 |
assert phase == inst.ch_2.phase |
| 242 |
assert phase == inst.phase |
| 243 |
inst.ch_1.phase = phase |
| 244 |
inst.ch_2.phase = phase |
| 245 |
inst.phase = phase |
| 246 |
|
| 247 |
|
| 248 |
@pytest.mark.parametrize("square_dutycycle", [0.01, 99.98]) |
| 249 |
def test_square_dutycycle(square_dutycycle): |
| 250 |
""" |
| 251 |
Test Agilent 33500 square_dutycycle function |
| 252 |
""" |
| 253 |
with expected_protocol( |
| 254 |
Agilent33500, |
| 255 |
[ |
| 256 |
("SOUR1:FUNC:SQU:DCYC?", square_dutycycle), |
| 257 |
("SOUR2:FUNC:SQU:DCYC?", square_dutycycle), |
| 258 |
("FUNC:SQU:DCYC?", square_dutycycle), |
| 259 |
(f"SOUR1:FUNC:SQU:DCYC {square_dutycycle:.6f}", None), |
| 260 |
(f"SOUR2:FUNC:SQU:DCYC {square_dutycycle:.6f}", None), |
| 261 |
(f"FUNC:SQU:DCYC {square_dutycycle:.6f}", None), |
| 262 |
], |
| 263 |
) as inst: |
| 264 |
assert square_dutycycle == inst.ch_1.square_dutycycle |
| 265 |
assert square_dutycycle == inst.ch_2.square_dutycycle |
| 266 |
assert square_dutycycle == inst.square_dutycycle |
| 267 |
inst.ch_1.square_dutycycle = square_dutycycle |
| 268 |
inst.ch_2.square_dutycycle = square_dutycycle |
| 269 |
inst.square_dutycycle = square_dutycycle |
| 270 |
|
| 271 |
|
| 272 |
@pytest.mark.parametrize("ramp_symmetry", [0.01, 99.98]) |
| 273 |
def test_ramp_symmetry(ramp_symmetry): |
| 274 |
""" |
| 275 |
Test Agilent 33500 ramp_symmetry function |
| 276 |
""" |
| 277 |
with expected_protocol( |
| 278 |
Agilent33500, |
| 279 |
[ |
| 280 |
("SOUR1:FUNC:RAMP:SYMM?", ramp_symmetry), |
| 281 |
("SOUR2:FUNC:RAMP:SYMM?", ramp_symmetry), |
| 282 |
("FUNC:RAMP:SYMM?", ramp_symmetry), |
| 283 |
(f"SOUR1:FUNC:RAMP:SYMM {ramp_symmetry:.6f}", None), |
| 284 |
(f"SOUR2:FUNC:RAMP:SYMM {ramp_symmetry:.6f}", None), |
| 285 |
(f"FUNC:RAMP:SYMM {ramp_symmetry:.6f}", None), |
| 286 |
], |
| 287 |
) as inst: |
| 288 |
assert ramp_symmetry == inst.ch_1.ramp_symmetry |
| 289 |
assert ramp_symmetry == inst.ch_2.ramp_symmetry |
| 290 |
assert ramp_symmetry == inst.ramp_symmetry |
| 291 |
inst.ch_1.ramp_symmetry = ramp_symmetry |
| 292 |
inst.ch_2.ramp_symmetry = ramp_symmetry |
| 293 |
inst.ramp_symmetry = ramp_symmetry |
| 294 |
|
| 295 |
|
| 296 |
def test_channel_phase_synchronization(): |
| 297 |
""" |
| 298 |
Test Agilent 33500 channel phase synchronization |
| 299 |
""" |
| 300 |
with expected_protocol( |
| 301 |
Agilent33500, |
| 302 |
[ |
| 303 |
("PHAS:SYNC", None) |
| 304 |
] |
| 305 |
) as inst: |
| 306 |
assert inst.phase_sync() is None |