| 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 |
|
| 27 |
from pymeasure.instruments.teledyne.teledyne_oscilloscope import sanitize_source |
| 28 |
from pymeasure.instruments.lecroy.lecroyT3DSO1204 import LeCroyT3DSO1204 |
| 29 |
from pymeasure.test import expected_protocol |
| 30 |
|
| 31 |
INVALID_CHANNELS = ["INVALID_SOURCE", "C1 C2", "C1 MATH", "C1234567", "CHANNEL"] |
| 32 |
VALID_CHANNELS = [('C1', 'C1'), ('CHANNEL2', 'C2'), ('ch 3', 'C3'), ('chan 4', 'C4'), |
| 33 |
('\tC3\t', 'C3'), (' math ', 'MATH')] |
| 34 |
|
| 35 |
|
| 36 |
def test_init(): |
| 37 |
with expected_protocol( |
| 38 |
LeCroyT3DSO1204, |
| 39 |
[(b"CHDR OFF", None)] |
| 40 |
): |
| 41 |
pass # Verify the expected communication. |
| 42 |
|
| 43 |
|
| 44 |
@pytest.mark.parametrize("channel", INVALID_CHANNELS) |
| 45 |
def test_invalid_source(channel): |
| 46 |
with pytest.raises(ValueError): |
| 47 |
sanitize_source(channel) |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.parametrize("channel", VALID_CHANNELS) |
| 51 |
def test_sanitize_valid_source(channel): |
| 52 |
assert sanitize_source(channel[0]) == channel[1] |
| 53 |
|
| 54 |
|
| 55 |
def test_bwlimit(): |
| 56 |
with expected_protocol( |
| 57 |
LeCroyT3DSO1204, |
| 58 |
[(b"CHDR OFF", None), |
| 59 |
(b"BWL C1,OFF", None), |
| 60 |
(b"C1:BWL?", b"OFF"), |
| 61 |
(b"BWL C1,ON", None), |
| 62 |
(b"C1:BWL?", b"ON") |
| 63 |
] |
| 64 |
) as instr: |
| 65 |
instr.ch_1.bwlimit = False |
| 66 |
assert instr.ch_1.bwlimit is False |
| 67 |
instr.ch_1.bwlimit = True |
| 68 |
assert instr.ch_1.bwlimit is True |
| 69 |
|
| 70 |
|
| 71 |
def test_coupling(): |
| 72 |
with expected_protocol( |
| 73 |
LeCroyT3DSO1204, |
| 74 |
[(b"CHDR OFF", None), |
| 75 |
(b"C1:CPL D1M", None), |
| 76 |
(b"C1:CPL?", b"D1M"), |
| 77 |
(b"C1:CPL A1M", None), |
| 78 |
(b"C1:CPL?", b"A1M"), |
| 79 |
(b"C1:CPL GND", None), |
| 80 |
(b"C1:CPL?", b"GND") |
| 81 |
], |
| 82 |
) as instr: |
| 83 |
instr.ch_1.coupling = "dc 1M" |
| 84 |
assert instr.ch_1.coupling == "dc 1M" |
| 85 |
instr.ch_1.coupling = "ac 1M" |
| 86 |
assert instr.ch_1.coupling == "ac 1M" |
| 87 |
instr.ch_1.coupling = "ground" |
| 88 |
assert instr.ch_1.coupling == "ground" |
| 89 |
|
| 90 |
|
| 91 |
def test_offset(): |
| 92 |
with expected_protocol( |
| 93 |
LeCroyT3DSO1204, |
| 94 |
[(b"CHDR OFF", None), |
| 95 |
(b"C1:OFST 1.00E+00V", None), |
| 96 |
(b"C1:OFST?", b"1.00E+00") |
| 97 |
] |
| 98 |
) as instr: |
| 99 |
instr.ch_1.offset = 1. |
| 100 |
assert instr.ch_1.offset == 1. |
| 101 |
|
| 102 |
|
| 103 |
def test_attenuation(): |
| 104 |
with expected_protocol( |
| 105 |
LeCroyT3DSO1204, |
| 106 |
[(b"CHDR OFF", None), |
| 107 |
(b"C1:ATTN 100", None), |
| 108 |
(b"C1:ATTN?", b"100"), |
| 109 |
(b"C1:ATTN 0.1", None), |
| 110 |
(b"C1:ATTN?", b"0.1") |
| 111 |
] |
| 112 |
) as instr: |
| 113 |
instr.ch_1.probe_attenuation = 100 |
| 114 |
assert instr.ch_1.probe_attenuation == 100 |
| 115 |
instr.ch_1.probe_attenuation = 0.1 |
| 116 |
assert instr.ch_1.probe_attenuation == 0.1 |
| 117 |
|
| 118 |
|
| 119 |
def test_skew_factor(): |
| 120 |
with expected_protocol( |
| 121 |
LeCroyT3DSO1204, |
| 122 |
[(b"CHDR OFF", None), |
| 123 |
(b"C1:SKEW 1.00E-07S", None), |
| 124 |
(b"C1:SKEW?", b"1.00E-07S"), |
| 125 |
] |
| 126 |
) as instr: |
| 127 |
instr.ch_1.skew_factor = 1e-7 |
| 128 |
assert instr.ch_1.skew_factor == 1e-7 |
| 129 |
|
| 130 |
|
| 131 |
def test_channel_setup(): |
| 132 |
with expected_protocol( |
| 133 |
LeCroyT3DSO1204, |
| 134 |
[(b"CHDR OFF", None), |
| 135 |
(b"C1:ATTN?", b"1"), |
| 136 |
(b"C1:BWL?", b"OFF"), |
| 137 |
(b"C1:CPL?", b"D1M"), |
| 138 |
(b"C1:OFST?", b"-1.50E-01"), |
| 139 |
(b"C1:SKEW?", b"0.00E+00S"), |
| 140 |
(b"C1:TRA?", b"ON"), |
| 141 |
(b"C1:UNIT?", b"V"), |
| 142 |
(b"C1:VDIV?", b"5.00E-02"), |
| 143 |
(b"C1:INVS?", b"OFF"), |
| 144 |
(b"C1:TRCP?", b"DC"), |
| 145 |
(b"C1:TRLV?", b"1.50E-01"), |
| 146 |
(b"C1:TRLV2?", b"1.50E-01"), |
| 147 |
(b"C1:TRSL?", b"POS"), |
| 148 |
] |
| 149 |
) as instr: |
| 150 |
assert instr.ch_1.current_configuration == {"channel": 1, |
| 151 |
"attenuation": 1., |
| 152 |
"bandwidth_limit": False, |
| 153 |
"coupling": "dc 1M", |
| 154 |
"offset": -0.150, |
| 155 |
"skew_factor": 0., |
| 156 |
"display": True, |
| 157 |
"unit": "V", |
| 158 |
"volts_div": 0.05, |
| 159 |
"inverted": False, |
| 160 |
"trigger_coupling": "dc", |
| 161 |
"trigger_level": 0.150, |
| 162 |
"trigger_level2": 0.150, |
| 163 |
"trigger_slope": "positive" |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
def test_memory_size(): |
| 168 |
with expected_protocol( |
| 169 |
LeCroyT3DSO1204, |
| 170 |
[(b"CHDR OFF", None), |
| 171 |
(b"MSIZ 14M", None), |
| 172 |
(b"MSIZ?", b"14M"), |
| 173 |
(b"MSIZ 1.4M", None), |
| 174 |
(b"MSIZ?", b"1.4M"), |
| 175 |
(b"MSIZ 7K", None), |
| 176 |
(b"MSIZ?", b"7K") |
| 177 |
] |
| 178 |
) as instr: |
| 179 |
instr.memory_size = 14e6 |
| 180 |
assert instr.memory_size == 14e6 |
| 181 |
instr.memory_size = 14e5 |
| 182 |
assert instr.memory_size == 14e5 |
| 183 |
instr.memory_size = 7e3 |
| 184 |
assert instr.memory_size == 7e3 |
| 185 |
|
| 186 |
|
| 187 |
def test_sample_size(): |
| 188 |
with expected_protocol( |
| 189 |
LeCroyT3DSO1204, |
| 190 |
[(b"CHDR OFF", None), |
| 191 |
(b"SANU? C1", b"3.50E+06"), |
| 192 |
(b"SANU? C1", b"3.50E+06"), |
| 193 |
(b"SANU? C3", b"3.50E+06"), |
| 194 |
(b"SANU? C3", b"3.50E+06"), |
| 195 |
] |
| 196 |
) as instr: |
| 197 |
assert instr.acquisition_sample_size_c1 == 3.5e6 |
| 198 |
assert instr.acquisition_sample_size_c2 == 3.5e6 |
| 199 |
assert instr.acquisition_sample_size_c3 == 3.5e6 |
| 200 |
assert instr.acquisition_sample_size_c4 == 3.5e6 |
| 201 |
|
| 202 |
|
| 203 |
def test_waveform_preamble(): |
| 204 |
with expected_protocol( |
| 205 |
LeCroyT3DSO1204, |
| 206 |
[(b"CHDR OFF", None), |
| 207 |
(b"WFSU?", b"SP,1,NP,0,FP,0"), |
| 208 |
(b"ACQW?", b"SAMPLING"), |
| 209 |
(b"SARA?", b"1.00E+09"), |
| 210 |
(b"SAST?", b"Trig'd"), |
| 211 |
(b"MSIZ?", b"7M"), |
| 212 |
(b"TDIV?", b"5.00E-04"), |
| 213 |
(b"TRDL?", b"-0.00E+00"), |
| 214 |
(b"SANU? C1", b"1.75E+06"), |
| 215 |
(b"C1:VDIV?", b"5.00E-02"), |
| 216 |
(b"C1:OFST?", b"-1.50E-01"), |
| 217 |
(b"C1:UNIT?", b"V"), |
| 218 |
] |
| 219 |
) as instr: |
| 220 |
assert instr.waveform_preamble == { |
| 221 |
"sparsing": 1, |
| 222 |
"requested_points": 0, |
| 223 |
"transmitted_points": None, |
| 224 |
"sampled_points": 1.75e6, |
| 225 |
"first_point": 0, |
| 226 |
"memory_size": 7e6, |
| 227 |
"source": "C1", |
| 228 |
"type": "normal", |
| 229 |
"average": None, |
| 230 |
"sampling_rate": 1e9, |
| 231 |
"grid_number": 14, |
| 232 |
"status": "triggered", |
| 233 |
"xdiv": 5e-4, |
| 234 |
"xoffset": 0, |
| 235 |
"ydiv": 0.05, |
| 236 |
"yoffset": -0.150, |
| 237 |
"unit": "V" |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
def test_download_one_point(): |
| 242 |
with expected_protocol( |
| 243 |
LeCroyT3DSO1204, |
| 244 |
[(b"CHDR OFF", None), |
| 245 |
(b"WFSU SP,1", None), |
| 246 |
(b"WFSU NP,1", None), |
| 247 |
(b"WFSU FP,0", None), |
| 248 |
(b"SANU? C1", b"7.00E+06"), |
| 249 |
(b"WFSU NP,1", None), |
| 250 |
(b"WFSU FP,0", None), |
| 251 |
(b"C1:WF? DAT2", b"DAT2,#9000000001" + b"\x01" + b"\n\n"), |
| 252 |
(b"WFSU?", b"SP,1,NP,2,FP,0"), |
| 253 |
(b"ACQW?", b"SAMPLING"), |
| 254 |
(b"SARA?", b"1.00E+09"), |
| 255 |
(b"SAST?", b"Stop"), |
| 256 |
(b"MSIZ?", b"7M"), |
| 257 |
(b"TDIV?", b"5.00E-04"), |
| 258 |
(b"TRDL?", b"-0.00E+00"), |
| 259 |
(b"SANU? C1", b"7.00E+06"), |
| 260 |
(b"C1:VDIV?", b"5.00E-02"), |
| 261 |
(b"C1:OFST?", b"-1.50E-01"), |
| 262 |
(b"C1:UNIT?", b"V") |
| 263 |
], |
| 264 |
connection_attributes={'chunk_size': 0}, |
| 265 |
) as instr: |
| 266 |
y, x, preamble = instr.download_waveform(source="c1", requested_points=1, sparsing=1) |
| 267 |
assert preamble == { |
| 268 |
"sparsing": 1, |
| 269 |
"requested_points": 1, |
| 270 |
"memory_size": 7e6, |
| 271 |
"sampled_points": 7e6, |
| 272 |
"transmitted_points": 1, |
| 273 |
"first_point": 0, |
| 274 |
"source": "C1", |
| 275 |
"type": "normal", |
| 276 |
"average": None, |
| 277 |
"sampling_rate": 1e9, |
| 278 |
"grid_number": 14, |
| 279 |
"status": "stopped", |
| 280 |
"xdiv": 5e-4, |
| 281 |
"xoffset": 0, |
| 282 |
"ydiv": 0.05, |
| 283 |
"yoffset": -0.150, |
| 284 |
"unit": "V" |
| 285 |
} |
| 286 |
assert len(x) == 1 |
| 287 |
assert len(y) == 1 |
| 288 |
assert y[0] == 1 * 0.05 / 25. + 0.150 |
| 289 |
|
| 290 |
|
| 291 |
def test_download_two_points(): |
| 292 |
with expected_protocol( |
| 293 |
LeCroyT3DSO1204, |
| 294 |
[(b"CHDR OFF", None), |
| 295 |
(b"WFSU SP,1", None), |
| 296 |
(b"WFSU NP,2", None), |
| 297 |
(b"WFSU FP,0", None), |
| 298 |
(b"SANU? C1", b"7.00E+06"), |
| 299 |
(b"WFSU NP,2", None), |
| 300 |
(b"WFSU FP,0", None), |
| 301 |
(b"C1:WF? DAT2", b"DAT2,#9000000002" + b"\x01\x01" + b"\n\n"), |
| 302 |
(b"WFSU?", b"SP,1,NP,2,FP,0"), |
| 303 |
(b"ACQW?", b"SAMPLING"), |
| 304 |
(b"SARA?", b"1.00E+09"), |
| 305 |
(b"SAST?", b"Stop"), |
| 306 |
(b"MSIZ?", b"7M"), |
| 307 |
(b"TDIV?", b"5.00E-04"), |
| 308 |
(b"TRDL?", b"-0.00E+00"), |
| 309 |
(b"SANU? C1", b"7.00E+06"), |
| 310 |
(b"C1:VDIV?", b"5.00E-02"), |
| 311 |
(b"C1:OFST?", b"-1.50E-01"), |
| 312 |
(b"C1:UNIT?", b"V") |
| 313 |
], |
| 314 |
connection_attributes={'chunk_size': 0}, |
| 315 |
) as instr: |
| 316 |
y, x, preamble = instr.download_waveform(source="c1", requested_points=2, sparsing=1) |
| 317 |
assert preamble == { |
| 318 |
"sparsing": 1, |
| 319 |
"requested_points": 2, |
| 320 |
"memory_size": 7e6, |
| 321 |
"sampled_points": 7e6, |
| 322 |
"transmitted_points": 2, |
| 323 |
"first_point": 0, |
| 324 |
"source": "C1", |
| 325 |
"type": "normal", |
| 326 |
"average": None, |
| 327 |
"sampling_rate": 1e9, |
| 328 |
"grid_number": 14, |
| 329 |
"status": "stopped", |
| 330 |
"xdiv": 5e-4, |
| 331 |
"xoffset": 0, |
| 332 |
"ydiv": 0.05, |
| 333 |
"yoffset": -0.150, |
| 334 |
"unit": "V" |
| 335 |
} |
| 336 |
assert len(x) == 2 |
| 337 |
assert len(y) == 2 |
| 338 |
assert x[0] == -5e-4 * 14 / 2. |
| 339 |
assert y[0] == 1 * 0.05 / 25. + 0.150 |
| 340 |
assert x[1] == x[0] + 1 / 1e9 |
| 341 |
assert y[1] == y[0] |
| 342 |
|
| 343 |
|
| 344 |
def test_trigger(): |
| 345 |
with expected_protocol( |
| 346 |
LeCroyT3DSO1204, |
| 347 |
[(b"CHDR OFF", None), |
| 348 |
(b"TRSE?", b"EDGE,SR,C1,HT,OFF"), |
| 349 |
(b"TRMD?", b"AUTO"), |
| 350 |
(b"C1:TRCP?", b"DC"), |
| 351 |
(b"C1:TRLV?", b"1.50E-01"), |
| 352 |
(b"C1:TRLV2?", b"1.50E-01"), |
| 353 |
(b"C1:TRSL?", b"POS"), |
| 354 |
] |
| 355 |
) as instr: |
| 356 |
assert instr.trigger == { |
| 357 |
"mode": "auto", |
| 358 |
"trigger_type": "edge", |
| 359 |
"source": "c1", |
| 360 |
"hold_type": "off", |
| 361 |
"hold_value1": None, |
| 362 |
"hold_value2": None, |
| 363 |
"coupling": "dc", |
| 364 |
"level": 0.150, |
| 365 |
"level2": 0.150, |
| 366 |
"slope": "positive", |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
def test_math_define(): |
| 371 |
with expected_protocol( |
| 372 |
LeCroyT3DSO1204, |
| 373 |
[(b"CHDR OFF", None), |
| 374 |
(b"DEF EQN,'C2*C4'", None), |
| 375 |
(b"DEF?", b"EQN,'C2*C4'"), |
| 376 |
] |
| 377 |
) as instr: |
| 378 |
instr.math_define = ("channel2", "*", "channel4") |
| 379 |
assert instr.math_define == ["EQN", "'C2*C4'"] |
| 380 |
|
| 381 |
|
| 382 |
def test_math_vdiv(): |
| 383 |
with expected_protocol( |
| 384 |
LeCroyT3DSO1204, |
| 385 |
[(b"CHDR OFF", None), |
| 386 |
(b"MTVD 1.00E+00V", None), |
| 387 |
(b"MTVD?", b"1.00E+00"), |
| 388 |
] |
| 389 |
) as instr: |
| 390 |
instr.math_vdiv = 1.0 |
| 391 |
assert instr.math_vdiv == 1.0 |
| 392 |
|
| 393 |
|
| 394 |
def test_math_vpos(): |
| 395 |
with expected_protocol( |
| 396 |
LeCroyT3DSO1204, |
| 397 |
[(b"CHDR OFF", None), |
| 398 |
(b"MTVP 120", None), |
| 399 |
(b"MTVP?", b"120"), |
| 400 |
] |
| 401 |
) as instr: |
| 402 |
instr.math_vpos = 120 |
| 403 |
assert instr.math_vpos == 120 |
| 404 |
|
| 405 |
|
| 406 |
def test_display_parameter(): |
| 407 |
with expected_protocol( |
| 408 |
LeCroyT3DSO1204, |
| 409 |
[(b"CHDR OFF", None), |
| 410 |
(b"PACU PKPK,C1", None), |
| 411 |
(b"PACU MEAN,C2", None) |
| 412 |
] |
| 413 |
) as instr: |
| 414 |
instr.display_parameter(parameter="PKPK", channel=1) |
| 415 |
instr.ch(2).display_parameter = "MEAN" |
| 416 |
|
| 417 |
|
| 418 |
def test_measure_parameter(): |
| 419 |
with expected_protocol( |
| 420 |
LeCroyT3DSO1204, |
| 421 |
[(b"CHDR OFF", None), |
| 422 |
(b"C2:PAVA? RISE", b"RISE,3.600000E-9"), |
| 423 |
(b"C3:PAVA? MEAN", b"MEAN,3.600000E-9"), |
| 424 |
] |
| 425 |
) as instr: |
| 426 |
assert instr.measure_parameter("RISE", "channel2") == 3.6e-9 |
| 427 |
assert instr.ch_3.measure_parameter("MEAN") == 3.6e-9 |
| 428 |
|
| 429 |
|
| 430 |
def test_menu(): |
| 431 |
with expected_protocol( |
| 432 |
LeCroyT3DSO1204, |
| 433 |
[(b"CHDR OFF", None), |
| 434 |
(b"MENU ON", None), |
| 435 |
(b"MENU?", b"ON"), |
| 436 |
(b"MENU OFF", None), |
| 437 |
(b"MENU?", b"OFF"), |
| 438 |
] |
| 439 |
) as instr: |
| 440 |
instr.menu = True |
| 441 |
assert instr.menu is True |
| 442 |
instr.menu = False |
| 443 |
assert instr.menu is False |
| 444 |
|
| 445 |
|
| 446 |
def test_grid_display(): |
| 447 |
with expected_protocol( |
| 448 |
LeCroyT3DSO1204, |
| 449 |
[(b"CHDR OFF", None), |
| 450 |
(b"GRDS FULL", None), |
| 451 |
(b"GRDS?", b"FULL"), |
| 452 |
] |
| 453 |
) as instr: |
| 454 |
instr.grid_display = "full" |
| 455 |
assert instr.grid_display == "full" |
| 456 |
|
| 457 |
|
| 458 |
def test_intensity(): |
| 459 |
with expected_protocol( |
| 460 |
LeCroyT3DSO1204, |
| 461 |
[(b"CHDR OFF", None), |
| 462 |
(b"INTS GRID,50,TRACE,100", None), |
| 463 |
(b"INTS?", b"GRID,50,TRACE,100"), |
| 464 |
] |
| 465 |
) as instr: |
| 466 |
instr.intensity = 50, 100 |
| 467 |
assert instr.intensity == {"GRID": 50, "TRACE": 100} |
| 468 |
|
| 469 |
|
| 470 |
if __name__ == '__main__': |
| 471 |
pytest.main() |