| 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.test import expected_protocol |
| 26 |
from pymeasure.instruments import Instrument |
| 27 |
|
| 28 |
from pymeasure.instruments.activetechnologies import AWG401x_AFG |
| 29 |
from pymeasure.instruments.activetechnologies.AWG401x import ChannelAFG, SequenceEntry |
| 30 |
|
| 31 |
|
| 32 |
class SequencerInstrument(Instrument): |
| 33 |
"""A class in order to test SequenceEntry.""" |
| 34 |
|
| 35 |
def __init__(self, adapter, **kwargs): |
| 36 |
super().__init__(adapter, "SequencerInstrument", **kwargs) |
| 37 |
self.waveforms = {} |
| 38 |
self.se = SequenceEntry(self, 1, 7) |
| 39 |
|
| 40 |
|
| 41 |
# AFG Tests |
| 42 |
AFG_init_comm = [ |
| 43 |
# ("*IDN?", "x,AWG4012"), |
| 44 |
("SOURce1:INITDELay? MINimum", "1"), |
| 45 |
("SOURce1:INITDELay? MAXimum", "2"), |
| 46 |
("SOURce1:VOLTage:LEVel:IMMediate:LOW? MINimum", "1"), |
| 47 |
("SOURce1:VOLTage:LEVel:IMMediate:LOW? MAXimum", "2"), |
| 48 |
("SOURce1:VOLTage:LEVel:IMMediate:HIGH? MINimum", "1"), |
| 49 |
("SOURce1:VOLTage:LEVel:IMMediate:HIGH? MAXimum", "2"), |
| 50 |
("SOURce1:VOLTage:LEVel:IMMediate:AMPLitude? MINimum", "VPP1"), |
| 51 |
("SOURce1:VOLTage:LEVel:IMMediate:AMPLitude? MAXimum", "VPP2"), |
| 52 |
("SOURce1:VOLTage:LEVel:IMMediate:OFFSet? MINimum", "1"), |
| 53 |
("SOURce1:VOLTage:LEVel:IMMediate:OFFSet? MAXimum", "2"), |
| 54 |
("SOURce1:VOLTage:BASELINE:OFFSET? MINimum", "1"), |
| 55 |
("SOURce1:VOLTage:BASELINE:OFFSET? MAXimum", "2"), |
| 56 |
("SOURce1:FREQuency? MINimum", "1"), |
| 57 |
("SOURce1:FREQuency? MAXimum", "2"), |
| 58 |
("SOURce1:PHASe:ADJust? MINimum", "1"), |
| 59 |
("SOURce1:PHASe:ADJust? MAXimum", "2"), |
| 60 |
("SOURce2:INITDELay? MINimum", "1"), |
| 61 |
("SOURce2:INITDELay? MAXimum", "2"), |
| 62 |
("SOURce2:VOLTage:LEVel:IMMediate:LOW? MINimum", "1"), |
| 63 |
("SOURce2:VOLTage:LEVel:IMMediate:LOW? MAXimum", "2"), |
| 64 |
("SOURce2:VOLTage:LEVel:IMMediate:HIGH? MINimum", "1"), |
| 65 |
("SOURce2:VOLTage:LEVel:IMMediate:HIGH? MAXimum", "2"), |
| 66 |
("SOURce2:VOLTage:LEVel:IMMediate:AMPLitude? MINimum", "VPP1"), |
| 67 |
("SOURce2:VOLTage:LEVel:IMMediate:AMPLitude? MAXimum", "VPP2"), |
| 68 |
("SOURce2:VOLTage:LEVel:IMMediate:OFFSet? MINimum", "1"), |
| 69 |
("SOURce2:VOLTage:LEVel:IMMediate:OFFSet? MAXimum", "2"), |
| 70 |
("SOURce2:VOLTage:BASELINE:OFFSET? MINimum", "1"), |
| 71 |
("SOURce2:VOLTage:BASELINE:OFFSET? MAXimum", "2"), |
| 72 |
("SOURce2:FREQuency? MINimum", "1"), |
| 73 |
("SOURce2:FREQuency? MAXimum", "2"), |
| 74 |
("SOURce2:PHASe:ADJust? MINimum", "1"), |
| 75 |
("SOURce2:PHASe:ADJust? MAXimum", "2"), |
| 76 |
("*IDN?", "x,AWG4012"), |
| 77 |
] |
| 78 |
|
| 79 |
|
| 80 |
def test_AFG_init(): |
| 81 |
with expected_protocol( |
| 82 |
AWG401x_AFG, |
| 83 |
AFG_init_comm, |
| 84 |
) as inst: |
| 85 |
assert len(inst.channels) == 2 |
| 86 |
assert isinstance(inst.ch_1, ChannelAFG) |
| 87 |
|
| 88 |
|
| 89 |
def test_AFG_frequency_setter(): |
| 90 |
with expected_protocol( |
| 91 |
AWG401x_AFG, |
| 92 |
[*AFG_init_comm, |
| 93 |
("SOURce2:FREQuency 1.5", None), |
| 94 |
], |
| 95 |
) as inst: |
| 96 |
inst.ch_2.frequency = 1.5 |
| 97 |
|
| 98 |
|
| 99 |
def test_AFG_frequency_getter(): |
| 100 |
with expected_protocol( |
| 101 |
AWG401x_AFG, |
| 102 |
[*AFG_init_comm, |
| 103 |
("SOURce2:FREQuency?", "1.5"), |
| 104 |
], |
| 105 |
) as inst: |
| 106 |
assert inst.ch_2.frequency == 1.5 |
| 107 |
|
| 108 |
|
| 109 |
# SequenceEntry Tests |
| 110 |
Sequence_init_comm = [ |
| 111 |
("SEQuence:ELEM7:LENGth? MINimum", "1"), |
| 112 |
("SEQuence:ELEM7:LENGth? MAXimum", "2"), |
| 113 |
("SEQuence:ELEM7:LOOP:COUNt? MINimum", "1"), |
| 114 |
("SEQuence:ELEM7:LOOP:COUNt? MAXimum", "2"), |
| 115 |
("SEQuence:ELEM7:AMPlitude1? MINimum", "1"), |
| 116 |
("SEQuence:ELEM7:AMPlitude1? MAXimum", "2"), |
| 117 |
("SEQuence:ELEM7:OFFset1? MINimum", "1"), |
| 118 |
("SEQuence:ELEM7:OFFset1? MAXimum", "2"), |
| 119 |
("SEQuence:ELEM7:VOLTage:HIGH1? MINimum", "1"), |
| 120 |
("SEQuence:ELEM7:VOLTage:HIGH1? MAXimum", "2"), |
| 121 |
("SEQuence:ELEM7:VOLTage:LOW1? MINimum", "1"), |
| 122 |
("SEQuence:ELEM7:VOLTage:LOW1? MAXimum", "2"), |
| 123 |
] |
| 124 |
|
| 125 |
|
| 126 |
def test_SequenceEntry_init(): |
| 127 |
with expected_protocol( |
| 128 |
SequencerInstrument, |
| 129 |
Sequence_init_comm, |
| 130 |
): |
| 131 |
pass # verify init |
| 132 |
|
| 133 |
|
| 134 |
def test_SequenceEntry_voltage_amplitude_setter(): |
| 135 |
with expected_protocol( |
| 136 |
SequencerInstrument, |
| 137 |
[*Sequence_init_comm, |
| 138 |
("SEQuence:ELEM7:AMPlitude1 1.5", None)], |
| 139 |
) as inst: |
| 140 |
inst.se.ch_1.voltage_amplitude = 1.5 |
| 141 |
|
| 142 |
|
| 143 |
def test_SequenceEntry_voltage_amplitude_getter(): |
| 144 |
with expected_protocol( |
| 145 |
SequencerInstrument, |
| 146 |
[*Sequence_init_comm, |
| 147 |
("SEQuence:ELEM7:AMPlitude1?", "1.5")], |
| 148 |
) as inst: |
| 149 |
assert inst.se.ch_1.voltage_amplitude == 1.5 |