Debian Codegraph @

tests/instruments/redpitaya/test_redpitaya_scpi.py

raw
1 import datetime
2
3 import pytest
4
5 from pymeasure.test import expected_protocol
6 from pymeasure.instruments.redpitaya import RedPitayaScpi
7
8
9 def test_init():
10 with expected_protocol(
11 RedPitayaScpi,
12 [],
13 ):
14 pass # Verify the expected communication.
15
16
17 def test_CLOCK_getter():
18 with expected_protocol(
19 RedPitayaScpi,
20 [],
21 ) as inst:
22 assert inst.CLOCK == 125000000.0
23
24
25 def test_TRIGGER_SOURCES_getter():
26 with expected_protocol(
27 RedPitayaScpi,
28 [],
29 ) as inst:
30 assert inst.TRIGGER_SOURCES == ('DISABLED', 'NOW', 'CH1_PE', 'CH1_NE', 'CH2_PE', 'CH2_NE',
31 'EXT_PE', 'EXT_NE', 'AWG_PE', 'AWG_NE')
32
33
34 def test_acq_buffer_filled_getter():
35 with expected_protocol(
36 RedPitayaScpi,
37 [(b'ACQ:TRig:FILL?', b'0')],
38 ) as inst:
39 assert inst.acq_buffer_filled is False
40
41
42 @pytest.mark.parametrize("comm_pairs, value", (
43 ([(b'ACQ:DATA:FORMAT ASCII', None)],
44 'ASCII'),
45 ([(b'ACQ:DATA:FORMAT BIN', None)],
46 'BIN'),
47 ([(b'ACQ:DATA:FORMAT BIN', None)],
48 'BIN'),
49 ([(b'ACQ:DATA:FORMAT ASCII', None)],
50 'ASCII'),
51 ))
52 def test_acq_format_setter(comm_pairs, value):
53 with expected_protocol(
54 RedPitayaScpi,
55 comm_pairs,
56 ) as inst:
57 inst.acq_format = value
58
59
60 def test_acq_size_getter():
61 with expected_protocol(
62 RedPitayaScpi,
63 [(b'ACQ:BUF:SIZE?', b'16384')],
64 ) as inst:
65 assert inst.buffer_length == 16384
66
67
68 def test_acq_trigger_delay_ns_setter():
69 with expected_protocol(
70 RedPitayaScpi,
71 [(b'ACQ:TRig:DLY -8182', None)],
72 ) as inst:
73 inst.acq_trigger_delay_ns = -65456
74
75
76 @pytest.mark.parametrize("comm_pairs, value", (
77 ([(b'ACQ:TRig:DLY?', b'0')],
78 0),
79 ([(b'ACQ:TRig:DLY?', b'500')],
80 4000),
81 ([(b'ACQ:TRig:DLY?', b'-8182')],
82 -65456),
83 ))
84 def test_acq_trigger_delay_ns_getter(comm_pairs, value):
85 with expected_protocol(
86 RedPitayaScpi,
87 comm_pairs,
88 ) as inst:
89 assert inst.acq_trigger_delay_ns == value
90
91
92 @pytest.mark.parametrize("comm_pairs, value", (
93 ([(b'ACQ:TRig:DLY 0', None)],
94 0),
95 ([(b'ACQ:TRig:DLY 500', None)],
96 500),
97 ))
98 def test_acq_trigger_delay_samples_setter(comm_pairs, value):
99 with expected_protocol(
100 RedPitayaScpi,
101 comm_pairs,
102 ) as inst:
103 inst.acq_trigger_delay_samples = value
104
105
106 @pytest.mark.parametrize("comm_pairs, value", (
107 ([(b'ACQ:TRig:DLY?', b'0')],
108 0),
109 ([(b'ACQ:TRig:DLY?', b'500')],
110 500),
111 ([(b'ACQ:TRig:DLY?', b'-8182')],
112 -8182),
113 ))
114 def test_acq_trigger_delay_samples_getter(comm_pairs, value):
115 with expected_protocol(
116 RedPitayaScpi,
117 comm_pairs,
118 ) as inst:
119 assert inst.acq_trigger_delay_samples == value
120
121
122 def test_acq_trigger_level_setter():
123 with expected_protocol(
124 RedPitayaScpi,
125 [(b'ACQ:TRig:LEV 0.500000', None)],
126 ) as inst:
127 inst.acq_trigger_level = 0.5
128
129
130 def test_acq_trigger_level_getter():
131 with expected_protocol(
132 RedPitayaScpi,
133 [(b'ACQ:TRig:LEV?', b'0.5')],
134 ) as inst:
135 assert inst.acq_trigger_level == 0.5
136
137
138 @pytest.mark.parametrize("comm_pairs, value", (
139 ([(b'ACQ:TRig DISABLED', None)],
140 'DISABLED'),
141 ([(b'ACQ:TRig NOW', None)],
142 'NOW'),
143 ([(b'ACQ:TRig CH1_PE', None)],
144 'CH1_PE'),
145 ([(b'ACQ:TRig CH1_NE', None)],
146 'CH1_NE'),
147 ([(b'ACQ:TRig CH2_PE', None)],
148 'CH2_PE'),
149 ([(b'ACQ:TRig CH2_NE', None)],
150 'CH2_NE'),
151 ([(b'ACQ:TRig EXT_PE', None)],
152 'EXT_PE'),
153 ([(b'ACQ:TRig EXT_NE', None)],
154 'EXT_NE'),
155 ([(b'ACQ:TRig AWG_PE', None)],
156 'AWG_PE'),
157 ([(b'ACQ:TRig AWG_NE', None)],
158 'AWG_NE'),
159 ))
160 def test_acq_trigger_source_setter(comm_pairs, value):
161 with expected_protocol(
162 RedPitayaScpi,
163 comm_pairs,
164 ) as inst:
165 inst.acq_trigger_source = value
166
167
168 def test_acq_trigger_status_getter():
169 with expected_protocol(
170 RedPitayaScpi,
171 [(b'ACQ:TRig:STAT?', b'TD')],
172 ) as inst:
173 assert inst.acq_trigger_status is True
174
175
176 def test_acq_units_setter():
177 with expected_protocol(
178 RedPitayaScpi,
179 [(b'ACQ:DATA:Units RAW', None)],
180 ) as inst:
181 inst.acq_units = 'RAW'
182
183
184 @pytest.mark.parametrize("comm_pairs, value", (
185 ([(b'ACQ:DATA:Units?', b'VOLTS')],
186 'VOLTS'),
187 ([(b'ACQ:DATA:Units?', b'RAW')],
188 'RAW'),
189 ))
190 def test_acq_units_getter(comm_pairs, value):
191 with expected_protocol(
192 RedPitayaScpi,
193 comm_pairs,
194 ) as inst:
195 assert inst.acq_units == value
196
197
198 def test_ain1_gain_setter():
199 with expected_protocol(
200 RedPitayaScpi,
201 [(b'ACQ:SOUR1:GAIN LV', None)],
202 ) as inst:
203 inst.ain1.gain = 'LV'
204
205
206 def test_ain1_gain_getter():
207 with expected_protocol(
208 RedPitayaScpi,
209 [(b'ACQ:SOUR1:GAIN?', b'LV')],
210 ) as inst:
211 assert inst.ain1.gain == 'LV'
212
213
214 @pytest.mark.parametrize("comm_pairs, value", (
215 ([(b'ACQ:AVG OFF', None)],
216 False),
217 ([(b'ACQ:AVG ON', None)],
218 True),
219 ))
220 def test_average_skipped_samples_setter(comm_pairs, value):
221 with expected_protocol(
222 RedPitayaScpi,
223 comm_pairs,
224 ) as inst:
225 inst.average_skipped_samples = value
226
227
228 @pytest.mark.parametrize("comm_pairs, value", (
229 ([(b'ACQ:AVG?', b'OFF')],
230 False),
231 ([(b'ACQ:AVG?', b'ON')],
232 True),
233 ))
234 def test_average_skipped_samples_getter(comm_pairs, value):
235 with expected_protocol(
236 RedPitayaScpi,
237 comm_pairs,
238 ) as inst:
239 assert inst.average_skipped_samples == value
240
241
242 def test_board_name_getter():
243 with expected_protocol(
244 RedPitayaScpi,
245 [(b'SYST:BRD:Name?', b'STEMlab 125-10')],
246 ) as inst:
247 assert inst.board_name == 'STEMlab 125-10'
248
249
250 def test_date_setter():
251 with expected_protocol(
252 RedPitayaScpi,
253 [(b'SYST:DATE 2023,12,22', None)],
254 ) as inst:
255 inst.date = datetime.date(2023, 12, 22)
256
257
258 def test_date_getter():
259 with expected_protocol(
260 RedPitayaScpi,
261 [(b'SYST:DATE?', b'2023,12,22')],
262 ) as inst:
263 assert inst.date == datetime.date(2023, 12, 22)
264
265
266 @pytest.mark.parametrize("comm_pairs, value", (
267 ([(b'ACQ:DEC 1', None)],
268 1),
269 ([(b'ACQ:DEC 2', None)],
270 2),
271 ([(b'ACQ:DEC 4', None)],
272 4),
273 ([(b'ACQ:DEC 8', None)],
274 8),
275 ([(b'ACQ:DEC 16', None)],
276 16),
277 ([(b'ACQ:DEC 32', None)],
278 32),
279 ([(b'ACQ:DEC 64', None)],
280 64),
281 ([(b'ACQ:DEC 128', None)],
282 128),
283 ([(b'ACQ:DEC 256', None)],
284 256),
285 ([(b'ACQ:DEC 512', None)],
286 512),
287 ([(b'ACQ:DEC 1024', None)],
288 1024),
289 ([(b'ACQ:DEC 2048', None)],
290 2048),
291 ([(b'ACQ:DEC 4096', None)],
292 4096),
293 ([(b'ACQ:DEC 8192', None)],
294 8192),
295 ([(b'ACQ:DEC 16384', None)],
296 16384),
297 ([(b'ACQ:DEC 32768', None)],
298 32768),
299 ([(b'ACQ:DEC 65536', None)],
300 65536),
301 ))
302 def test_decimation_setter(comm_pairs, value):
303 with expected_protocol(
304 RedPitayaScpi,
305 comm_pairs,
306 ) as inst:
307 inst.decimation = value
308
309
310 @pytest.mark.parametrize("comm_pairs, value", (
311 ([(b'ACQ:DEC?', b'1')],
312 1.0),
313 ([(b'ACQ:DEC?', b'2')],
314 2.0),
315 ([(b'ACQ:DEC?', b'4')],
316 4.0),
317 ([(b'ACQ:DEC?', b'8')],
318 8.0),
319 ([(b'ACQ:DEC?', b'16')],
320 16.0),
321 ([(b'ACQ:DEC?', b'32')],
322 32.0),
323 ([(b'ACQ:DEC?', b'64')],
324 64.0),
325 ([(b'ACQ:DEC?', b'128')],
326 128.0),
327 ([(b'ACQ:DEC?', b'256')],
328 256.0),
329 ([(b'ACQ:DEC?', b'512')],
330 512.0),
331 ([(b'ACQ:DEC?', b'1024')],
332 1024.0),
333 ([(b'ACQ:DEC?', b'2048')],
334 2048.0),
335 ([(b'ACQ:DEC?', b'4096')],
336 4096.0),
337 ([(b'ACQ:DEC?', b'8192')],
338 8192.0),
339 ([(b'ACQ:DEC?', b'16384')],
340 16384.0),
341 ([(b'ACQ:DEC?', b'32768')],
342 32768.0),
343 ([(b'ACQ:DEC?', b'65536')],
344 65536.0),
345 ))
346 def test_decimation_getter(comm_pairs, value):
347 with expected_protocol(
348 RedPitayaScpi,
349 comm_pairs,
350 ) as inst:
351 assert inst.decimation == value
352
353
354 def test_led_getter():
355 with expected_protocol(
356 RedPitayaScpi,
357 [(b'DIG:PIN? LED7', 1)],
358 ) as inst:
359 assert inst.led7.enabled
360
361
362 def test_time_setter():
363 with expected_protocol(
364 RedPitayaScpi,
365 [(b'SYST:TIME 13,07,20', None)],
366 ) as inst:
367 inst.time = datetime.time(13, 7, 20)
368
369
370 def test_time_getter():
371 with expected_protocol(
372 RedPitayaScpi,
373 [(b'SYST:TIME?', '13,07,20')],
374 ) as inst:
375 assert inst.time == datetime.time(13, 7, 20)
376
377
378 def test_analog_reset():
379 with expected_protocol(
380 RedPitayaScpi,
381 [(b'ANALOG:RST', None)],
382 ) as inst:
383 assert inst.analog_reset() is None
384
385
386 def test_digital_reset():
387 with expected_protocol(
388 RedPitayaScpi,
389 [(b'DIG:RST', None)],
390 ) as inst:
391 assert inst.digital_reset() is None