Debian Codegraph @

pymeasure/instruments/agilent/agilent33220A.py

raw
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 strict_discrete_set,\
27 strict_range, joined_validators
28 from time import time
29 from pyvisa.errors import VisaIOError
30
31 import logging
32 log = logging.getLogger(__name__)
33 log.addHandler(logging.NullHandler())
34
35
36 # Capitalize string arguments to allow for better conformity with other WFG's
37 def capitalize_string(string: str, *args, **kwargs):
38 return string.upper()
39
40
41 # Combine the capitalize function and validator
42 string_validator = joined_validators(capitalize_string, strict_discrete_set)
43
44
45 class Agilent33220A(SCPIUnknownMixin, Instrument):
46 """Represents the Agilent 33220A Arbitrary Waveform Generator.
47
48 .. code-block:: python
49
50 # Default channel for the Agilent 33220A
51 wfg = Agilent33220A("GPIB::10")
52
53 wfg.shape = "SINUSOID" # Sets a sine waveform
54 wfg.frequency = 4.7e3 # Sets the frequency to 4.7 kHz
55 wfg.amplitude = 1 # Set amplitude of 1 V
56 wfg.offset = 0 # Set the amplitude to 0 V
57
58 wfg.burst_state = True # Enable burst mode
59 wfg.burst_ncycles = 10 # A burst will consist of 10 cycles
60 wfg.burst_mode = "TRIGGERED" # A burst will be applied on a trigger
61 wfg.trigger_source = "BUS" # A burst will be triggered on TRG*
62
63 wfg.output = True # Enable output of waveform generator
64 wfg.trigger() # Trigger a burst
65 wfg.wait_for_trigger() # Wait until the triggering is finished
66 wfg.beep() # "beep"
67
68 print(wfg.check_errors()) # Get the error queue
69
70 """
71
72 def __init__(self, adapter, name="Agilent 33220A Arbitrary Waveform generator", **kwargs):
73 super().__init__(
74 adapter,
75 name,
76 **kwargs
77 )
78
79 shape = Instrument.control(
80 "FUNC?", "FUNC %s",
81 """ A string property that controls the output waveform. Can be set to:
82 SIN<USOID>, SQU<ARE>, RAMP, PULS<E>, NOIS<E>, DC, USER. """,
83 validator=joined_validators(
84 strict_discrete_set, string_validator
85 ),
86 values=[["SINUSOID", "SIN", "SQUARE", "SQU", "RAMP",
87 "PULSE", "PULS", "NOISE", "NOIS", "DC", "USER"], ],
88 )
89
90 frequency = Instrument.control(
91 "FREQ?", "FREQ %s",
92 """ A floating point property that controls the frequency of the output
93 waveform in Hz, from 1e-6 (1 uHz) to 20e+6 (20 MHz), depending on the
94 specified function. Can be set. """,
95 validator=strict_range,
96 values=[1e-6, 5e+6],
97 )
98
99 amplitude = Instrument.control(
100 "VOLT?", "VOLT %f",
101 """ A floating point property that controls the voltage amplitude of the
102 output waveform in V, from 10e-3 V to 10 V. Can be set. """,
103 validator=strict_range,
104 values=[10e-3, 10],
105 )
106
107 amplitude_unit = Instrument.control(
108 "VOLT:UNIT?", "VOLT:UNIT %s",
109 """ A string property that controls the units of the amplitude. Valid
110 values are Vpp (default), Vrms, and dBm. Can be set. """,
111 validator=joined_validators(
112 strict_discrete_set, string_validator
113 ),
114 values=[["VPP", "VRMS", "DBM"], ],
115 )
116
117 offset = Instrument.control(
118 "VOLT:OFFS?", "VOLT:OFFS %f",
119 """ A floating point property that controls the voltage offset of the
120 output waveform in V, from 0 V to 4.995 V, depending on the set
121 voltage amplitude (maximum offset = (10 - voltage) / 2). Can be set.
122 """,
123 validator=strict_range,
124 values=[-4.995, +4.995],
125 )
126
127 voltage_high = Instrument.control(
128 "VOLT:HIGH?", "VOLT:HIGH %f",
129 """ A floating point property that controls the upper voltage of the
130 output waveform in V, from -4.990 V to 5 V (must be higher than low
131 voltage). Can be set. """,
132 validator=strict_range,
133 values=[-4.99, 5],
134 )
135
136 voltage_low = Instrument.control(
137 "VOLT:LOW?", "VOLT:LOW %f",
138 """ A floating point property that controls the lower voltage of the
139 output waveform in V, from -5 V to 4.990 V (must be lower than high
140 voltage). Can be set. """,
141 validator=strict_range,
142 values=[-5, 4.99],
143 )
144
145 square_dutycycle = Instrument.control(
146 "FUNC:SQU:DCYC?", "FUNC:SQU:DCYC %f",
147 """ A floating point property that controls the duty cycle of a square
148 waveform function in percent. Can be set. """,
149 validator=strict_range,
150 values=[20, 80],
151 )
152
153 ramp_symmetry = Instrument.control(
154 "FUNC:RAMP:SYMM?", "FUNC:RAMP:SYMM %f",
155 """ A floating point property that controls the symmetry percentage
156 for the ramp waveform. Can be set. """,
157 validator=strict_range,
158 values=[0, 100],
159 )
160
161 pulse_period = Instrument.control(
162 "PULS:PER?", "PULS:PER %f",
163 """ A floating point property that controls the period of a pulse
164 waveform function in seconds, ranging from 200 ns to 2000 s. Can be set
165 and overwrites the frequency for *all* waveforms. If the period is
166 shorter than the pulse width + the edge time, the edge time and pulse
167 width will be adjusted accordingly. """,
168 validator=strict_range,
169 values=[200e-9, 2e3],
170 )
171
172 pulse_hold = Instrument.control(
173 "FUNC:PULS:HOLD?", "FUNC:PULS:HOLD %s",
174 """ A string property that controls if either the pulse width or the
175 duty cycle is retained when changing the period or frequency of the
176 waveform. Can be set to: WIDT<H> or DCYC<LE>. """,
177 validator=joined_validators(
178 strict_discrete_set, string_validator
179 ),
180 values=[["WIDT", "WIDTH", "DCYC", "DCYCLE"], ],
181 )
182
183 pulse_width = Instrument.control(
184 "FUNC:PULS:WIDT?", "FUNC:PULS:WIDT %f",
185 """ A floating point property that controls the width of a pulse
186 waveform function in seconds, ranging from 20 ns to 2000 s, within a
187 set of restrictions depending on the period. Can be set. """,
188 validator=strict_range,
189 values=[20e-9, 2e3],
190 )
191
192 pulse_dutycycle = Instrument.control(
193 "FUNC:PULS:DCYC?", "FUNC:PULS:DCYC %f",
194 """ A floating point property that controls the duty cycle of a pulse
195 waveform function in percent. Can be set. """,
196 validator=strict_range,
197 values=[0, 100],
198 )
199
200 pulse_transition = Instrument.control(
201 "FUNC:PULS:TRAN?", "FUNC:PULS:TRAN %g",
202 """ A floating point property that controls the edge time in
203 seconds for both the rising and falling edges. It is defined as the
204 time between 0.1 and 0.9 of the threshold. Valid values are between
205 5 ns to 100 ns. The transition time has to be smaller than
206 0.625 * the pulse width. Can be set. """,
207 validator=strict_range,
208 values=[5e-9, 100e-9],
209 )
210
211 output = Instrument.control(
212 "OUTP?", "OUTP %d",
213 """ A boolean property that turns on (True) or off (False) the output
214 of the function generator. Can be set. """,
215 validator=strict_discrete_set,
216 map_values=True,
217 values={True: 1, False: 0},
218 )
219
220 burst_state = Instrument.control(
221 "BURS:STAT?", "BURS:STAT %d",
222 """ A boolean property that controls whether the burst mode is on
223 (True) or off (False). Can be set. """,
224 validator=strict_discrete_set,
225 map_values=True,
226 values={True: 1, False: 0},
227 )
228
229 burst_mode = Instrument.control(
230 "BURS:MODE?", "BURS:MODE %s",
231 """ A string property that controls the burst mode. Valid values
232 are: TRIG<GERED>, GAT<ED>. This setting can be set. """,
233 validator=joined_validators(
234 strict_discrete_set, string_validator
235 ),
236 values=[["TRIG", "TRIGGERED", "GAT", "GATED"], ],
237 )
238
239 burst_ncycles = Instrument.control(
240 "BURS:NCYC?", "BURS:NCYC %d",
241 """ An integer property that sets the number of cycles to be output
242 when a burst is triggered. Valid values are 1 to 50000. This can be
243 set. """,
244 validator=strict_discrete_set,
245 values=range(1, 50001),
246 cast=lambda v: int(float(v))
247 )
248
249 def trigger(self):
250 """ Send a trigger signal to the function generator. """
251 self.write("*TRG;*WAI")
252
253 def wait_for_trigger(self, timeout=3600, should_stop=lambda: False):
254 """ Wait until the triggering has finished or timeout is reached.
255
256 :param timeout: The maximum time the waiting is allowed to take. If
257 timeout is exceeded, a TimeoutError is raised. If
258 timeout is set to zero, no timeout will be used.
259 :param should_stop: Optional function (returning a bool) to allow the
260 waiting to be stopped before its end.
261
262 """
263 self.write("*OPC?")
264
265 t0 = time()
266 while True:
267 try:
268 ready = bool(self.read())
269 except VisaIOError:
270 ready = False
271
272 if ready:
273 return
274
275 if timeout != 0 and time() - t0 > timeout:
276 raise TimeoutError(
277 "Timeout expired while waiting for the Agilent 33220A" +
278 " to finish the triggering."
279 )
280
281 if should_stop():
282 return
283
284 trigger_source = Instrument.control(
285 "TRIG:SOUR?", "TRIG:SOUR %s",
286 """ A string property that controls the trigger source. Valid values
287 are: IMM<EDIATE> (internal), EXT<ERNAL> (rear input), BUS (via trigger
288 command). This setting can be set. """,
289 validator=joined_validators(
290 strict_discrete_set, string_validator
291 ),
292 values=[["IMM", "IMMEDIATE", "EXT", "EXTERNAL", "BUS"], ],
293 )
294
295 trigger_state = Instrument.control(
296 "OUTP:TRIG?", "OUTP:TRIG %d",
297 """ A boolean property that controls whether the output is triggered
298 (True) or not (False). Can be set. """,
299 validator=strict_discrete_set,
300 map_values=True,
301 values={True: 1, False: 0},
302 )
303
304 remote_local_state = Instrument.setting(
305 "SYST:COMM:RLST %s",
306 """ A string property that controls the remote/local state of the
307 function generator. Valid values are: LOC<AL>, REM<OTE>, RWL<OCK>.
308 This setting can only be set. """,
309 validator=joined_validators(
310 strict_discrete_set, string_validator
311 ),
312 values=[["LOC", "LOCAL", "REM", "REMOTE", "RWL", "RWLOCK"], ],
313 )
314
315 beeper_state = Instrument.control(
316 "SYST:BEEP:STAT?", "SYST:BEEP:STAT %d",
317 """ A boolean property that controls the state of the beeper. Can
318 be set. """,
319 validator=strict_discrete_set,
320 map_values=True,
321 values={True: 1, False: 0},
322 )
323
324 def beep(self):
325 """ Causes a system beep. """
326 self.write("SYST:BEEP")