| 1 |
import datetime |
| 2 |
|
| 3 |
import pytest |
| 4 |
from pymeasure.instruments.redpitaya import RedPitayaScpi |
| 5 |
|
| 6 |
|
| 7 |
@pytest.fixture(scope="module") |
| 8 |
def redpitaya_scpi(connected_device_address: str): |
| 9 |
""" to use the tests in this file invoke pytest as: |
| 10 |
pytest -k redpitaya_scpi --device-address TCPIP::x.y.z.k::port::SOCKET |
| 11 |
where you replace x.y.z.k byt the device IP address and port by its port address |
| 12 |
""" |
| 13 |
instr = RedPitayaScpi(adapter=connected_device_address) |
| 14 |
# ensure the device is in a defined state, e.g. by resetting it. |
| 15 |
instr.digital_reset() |
| 16 |
instr.analog_reset() |
| 17 |
return instr |
| 18 |
|
| 19 |
|
| 20 |
class TestRedpitaya: |
| 21 |
|
| 22 |
def test_time_date(self, redpitaya_scpi): |
| 23 |
inst = redpitaya_scpi |
| 24 |
inst.time = datetime.time(13, 7, 20) |
| 25 |
assert inst.time.hour == 13 |
| 26 |
assert inst.time.minute == 7 |
| 27 |
|
| 28 |
inst.date = datetime.date(2023, 12, 22) |
| 29 |
assert inst.date == datetime.date(2023, 12, 22) |
| 30 |
|
| 31 |
def test_led_dio(self, redpitaya_scpi): |
| 32 |
inst = redpitaya_scpi |
| 33 |
|
| 34 |
for ind in range(8): |
| 35 |
inst.led[ind].enabled = True |
| 36 |
assert inst.led[ind].enabled |
| 37 |
|
| 38 |
inst.led[ind].enabled = False |
| 39 |
assert not inst.led[ind].enabled |
| 40 |
|
| 41 |
for ind in range(7): |
| 42 |
inst.dioN[ind].direction_in = True |
| 43 |
assert inst.dioN[ind].direction_in |
| 44 |
inst.dioN[ind].direction_in = False |
| 45 |
assert not inst.dioN[ind].direction_in |
| 46 |
|
| 47 |
inst.dioN[ind].enabled = True |
| 48 |
assert inst.dioN[ind].enabled |
| 49 |
|
| 50 |
inst.dioN[ind].enabled = False |
| 51 |
assert not inst.dioN[ind].enabled |
| 52 |
|
| 53 |
for ind in range(7): |
| 54 |
inst.dioP[ind].direction_in = True |
| 55 |
assert inst.dioP[ind].direction_in |
| 56 |
inst.dioP[ind].direction_in = False |
| 57 |
assert not inst.dioP[ind].direction_in |
| 58 |
|
| 59 |
inst.dioP[ind].enabled = True |
| 60 |
assert inst.dioP[ind].enabled |
| 61 |
|
| 62 |
inst.dioP[ind].enabled = False |
| 63 |
assert not inst.dioP[ind].enabled |
| 64 |
|
| 65 |
def test_analog_slow(self, redpitaya_scpi): |
| 66 |
inst = redpitaya_scpi |
| 67 |
|
| 68 |
for ind in range(4): |
| 69 |
inst.analog_in_slow[ind].voltage |
| 70 |
inst.analog_out_slow[ind].voltage = 0.5 |
| 71 |
|
| 72 |
def test_acquisition(self, redpitaya_scpi): |
| 73 |
inst = redpitaya_scpi |
| 74 |
|
| 75 |
for ind in range(17): |
| 76 |
inst.decimation = 2**ind |
| 77 |
assert inst.decimation == 2**ind |
| 78 |
|
| 79 |
inst.average_skipped_samples = False |
| 80 |
assert inst.average_skipped_samples is False |
| 81 |
inst.average_skipped_samples = True |
| 82 |
assert inst.average_skipped_samples |
| 83 |
|
| 84 |
assert inst.acq_units == 'VOLTS' |
| 85 |
inst.acq_units = 'RAW' |
| 86 |
assert inst.acq_units == 'RAW' |
| 87 |
|
| 88 |
assert inst.buffer_length == 16384 |
| 89 |
|
| 90 |
inst.acq_format = 'ASCII' |
| 91 |
inst.acq_format = 'BIN' |
| 92 |
|
| 93 |
for trigger_source in inst.TRIGGER_SOURCES: |
| 94 |
inst.acq_trigger_source = trigger_source |
| 95 |
if trigger_source == "DISABLED": |
| 96 |
assert inst.acq_trigger_status |
| 97 |
|
| 98 |
assert inst.acq_buffer_filled is False |
| 99 |
|
| 100 |
inst.acq_trigger_delay_samples = 0 |
| 101 |
assert inst.acq_trigger_delay_samples == 0 |
| 102 |
assert inst.acq_trigger_delay_ns == 0 |
| 103 |
|
| 104 |
inst.acq_trigger_delay_samples = 500 |
| 105 |
assert inst.acq_trigger_delay_samples == 500 |
| 106 |
assert inst.acq_trigger_delay_ns == int(500 / inst.CLOCK * 1e9) |
| 107 |
|
| 108 |
inst.acq_trigger_delay_ns = RedPitayaScpi.DELAY_NS[10] |
| 109 |
assert inst.acq_trigger_delay_ns == RedPitayaScpi.DELAY_NS[10] |
| 110 |
assert inst.acq_trigger_delay_samples == -8192 + 10 |
| 111 |
|
| 112 |
inst.acq_trigger_level = 0.5 |
| 113 |
assert inst.acq_trigger_level == pytest.approx(0.5) |
| 114 |
|
| 115 |
inst.ain1.gain = 'LV' |
| 116 |
assert inst.ain1.gain == 'LV' |
| 117 |
|
| 118 |
inst.acq_format = 'BIN' |
| 119 |
inst.ain1.get_data_from_binary() |
| 120 |
|
| 121 |
inst.acq_format = 'ASCII' |
| 122 |
inst.ain1.get_data_from_ascii() |