From 5685e47819dbe88d3d9f28ca2f911008f93002bf Mon Sep 17 00:00:00 2001 From: crnbaker Date: Thu, 11 Jan 2024 17:04:08 +0000 Subject: [PATCH] #26 - removed synchronous digital output from example (see issue #40) --- README.md | 2 +- src/example_scripts/awg_example.py | 64 +--------------------- src/spectrumdevice/devices/awg/awg_card.py | 6 +- src/tests/device_factories.py | 6 +- src/tests/test_integration.py | 7 ++- src/tests/test_single_card.py | 23 ++++++-- src/tests/test_star_hub.py | 7 ++- 7 files changed, 38 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 2b20013..796412a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ for controlling devices: |----------------------------|-----------------------------------------------------------------------| | `SpectrumDigitiserCard` | Controlling individual digitiser cards | | `SpectrumDigitiserStarHub` | Controlling digitiser cards aggregated with a StarHub | -| `SpectrumAWGCard` | Controlling individual AWG cards (Not yet implemented) | +| `SpectrumAWGCard` | Controlling individual AWG cards | | `SpectrumAWGStarHub` | Controlling AWG cards aggregated with a StarHub (Not yet implemented) | `spectrumdevice` also includes mock classes for testing software without drivers installed or hardware connected: diff --git a/src/example_scripts/awg_example.py b/src/example_scripts/awg_example.py index a30f80f..bd246d4 100644 --- a/src/example_scripts/awg_example.py +++ b/src/example_scripts/awg_example.py @@ -1,8 +1,7 @@ from time import sleep from matplotlib.pyplot import plot, show -from numpy import int16, iinfo, bool_, linspace, sin, pi -from numpy.typing import NDArray +from numpy import int16, iinfo, linspace, sin, pi from spectrumdevice.devices.awg.awg_card import SpectrumAWGCard from spectrumdevice.settings import TriggerSettings, TriggerSource, ExternalTriggerMode @@ -16,16 +15,6 @@ SAMPLE_RATE = 125000000 -def write_digital_waveform_to_bit_15_of_analog( - digital_waveform: NDArray[bool_], analog_waveform: NDArray[int16] -) -> NDArray[int16]: - if analog_waveform.shape != digital_waveform.shape: - raise ValueError("Analog and digital waveforms must have the same shape.") - analog_waveform &= ~1 # Clear the least significant bit - analog_waveform |= digital_waveform.astype(int16) # Set the least significant bit using bitwise OR - return analog_waveform - - if __name__ == "__main__": card = SpectrumAWGCard(device_number=0) @@ -64,54 +53,3 @@ def write_digital_waveform_to_bit_15_of_analog( plot(t * 1e6, analog_wfm) show() - - # card = MockSpectrumAWGCard( - # device_number=0, - # model=ModelNumber.TYP_M2P6560_X4, - # num_channels_per_module=1, - # num_modules=1, - # mode=AcquisitionMode.SPC_REC_STD_SINGLE, - # ) - - # digitiser = SpectrumDigitiserCard(device_number=1, ip_address="169.254.13.35") - # digitiser_trigger = TriggerSettings( - # trigger_sources=[TriggerSource.SPC_TMASK_EXT0], - # external_trigger_mode=ExternalTriggerMode.SPC_TM_POS, - # external_trigger_level_in_mv=1000, - # ) - # digitiser_settings = AcquisitionSettings( - # acquisition_mode=AcquisitionMode.SPC_REC_FIFO_MULTI, - # sample_rate_in_hz=1000000, - # acquisition_length_in_samples=400, - # pre_trigger_length_in_samples=0, - # timeout_in_ms=1000, - # enabled_channels=[0], - # vertical_ranges_in_mv=[200], - # vertical_offsets_in_percent=[0], - # input_impedances=[InputImpedance.ONE_MEGA_OHM], - # timestamping_enabled=False, - # ) - # digitiser.configure_trigger(digitiser_trigger) - # digitiser.configure_acquisition(digitiser_settings) - - # print(digitiser) - - # analog_wfm = array([0, full_scale_max_value, 0, full_scale_min_value], dtype=int16) - # digital_wfm = array([True, False, True, False]) - # analog_waveform = write_digital_waveform_to_bit_15_of_analog(digital_wfm, analog_wfm) - # print(card.io_lines[0]) - # card.io_lines[0].set_mode(IOLineMode.SPCM_XMODE_DIGOUT) - # card.io_lines[0].set_dig_out_settings( - # DigOutIOLineModeSettings( - # source_channel=DigOutSourceChannel.SPCM_XMODE_DIGOUTSRC_CH0, - # source_bit=DigOutSourceBit.SPCM_XMODE_DIGOUTSRC_BIT15, - # ) - # ) - # digitiser.stop() - - # digitiser.execute_continuous_fifo_acquisition() - - # waveforms = waveforms + digitiser.get_waveforms() - - # digitiser.reset() - # digitiser.disconnect() diff --git a/src/spectrumdevice/devices/awg/awg_card.py b/src/spectrumdevice/devices/awg/awg_card.py index c23cc57..14b4ff1 100644 --- a/src/spectrumdevice/devices/awg/awg_card.py +++ b/src/spectrumdevice/devices/awg/awg_card.py @@ -50,8 +50,10 @@ def transfer_waveform(self, waveform: NDArray[int16]) -> None: step_size = get_memsize_step_size(self._model_number) remainder = len(waveform) % step_size if remainder > 0: - logger.warning("Waveform length is not a multiple of 8 samples. Waveform in card memory will be zero-padded" - " to the next multiple of 8.") + logger.warning( + "Waveform length is not a multiple of 8 samples. Waveform in card memory will be zero-padded" + " to the next multiple of 8." + ) coerced_mem_size = len(waveform) if remainder == 0 else len(waveform) + (step_size - remainder) self.write_to_spectrum_device_register(SPC_MEMSIZE, coerced_mem_size) self.start_transfer() diff --git a/src/tests/device_factories.py b/src/tests/device_factories.py index 4b0d4e2..297d16a 100644 --- a/src/tests/device_factories.py +++ b/src/tests/device_factories.py @@ -14,7 +14,11 @@ DIGITISER_STAR_HUB_TEST_MODE, SpectrumTestMode, TEST_DIGITISER_IP, - TEST_DIGITISER_NUMBER, SINGLE_AWG_CARD_TEST_MODE, NUM_MODULES_PER_AWG, NUM_CHANNELS_PER_AWG_MODULE, TEST_AWG_IP, + TEST_DIGITISER_NUMBER, + SINGLE_AWG_CARD_TEST_MODE, + NUM_MODULES_PER_AWG, + NUM_CHANNELS_PER_AWG_MODULE, + TEST_AWG_IP, TEST_AWG_NUMBER, ) diff --git a/src/tests/test_integration.py b/src/tests/test_integration.py index 91038f4..1e803c1 100644 --- a/src/tests/test_integration.py +++ b/src/tests/test_integration.py @@ -18,7 +18,7 @@ NUM_CARDS_IN_STAR_HUB, NUM_CHANNELS_PER_DIGITISER_MODULE, NUM_MODULES_PER_DIGITISER, - SINGLE_CARD_TEST_MODE, + SINGLE_DIGITISER_CARD_TEST_MODE, STAR_HUB_MASTER_CARD_INDEX, DIGITISER_STAR_HUB_TEST_MODE, SpectrumTestMode, @@ -30,7 +30,7 @@ @pytest.mark.integration class SingleCardIntegrationTests(TestCase): def setUp(self) -> None: - self._single_card_mock_mode = SINGLE_CARD_TEST_MODE == SpectrumTestMode.MOCK_HARDWARE + self._single_card_mock_mode = SINGLE_DIGITISER_CARD_TEST_MODE == SpectrumTestMode.MOCK_HARDWARE def test_standard_single_mode(self) -> None: measurement = standard_single_mode_example( @@ -121,7 +121,8 @@ def test_star_hub(self) -> None: ip_address=TEST_DIGITISER_IP, ) self.assertEqual( - len(hub.analog_channels), NUM_CHANNELS_PER_DIGITISER_MODULE * NUM_MODULES_PER_DIGITISER * NUM_CARDS_IN_STAR_HUB + len(hub.analog_channels), + NUM_CHANNELS_PER_DIGITISER_MODULE * NUM_MODULES_PER_DIGITISER * NUM_CARDS_IN_STAR_HUB, ) self.assertEqual(len(hub._child_cards), NUM_CARDS_IN_STAR_HUB) diff --git a/src/tests/test_single_card.py b/src/tests/test_single_card.py index 43919d2..064b2b2 100644 --- a/src/tests/test_single_card.py +++ b/src/tests/test_single_card.py @@ -18,11 +18,20 @@ ) from spectrumdevice.settings.channel import SpectrumAnalogChannelName from spectrumdevice.settings.device_modes import AcquisitionMode, ClockMode, GenerationMode -from spectrumdevice.settings.transfer_buffer import create_samples_acquisition_transfer_buffer, transfer_buffer_factory, \ - BufferType, BufferDirection +from spectrumdevice.settings.transfer_buffer import ( + create_samples_acquisition_transfer_buffer, + transfer_buffer_factory, + BufferType, + BufferDirection, +) from spectrumdevice.settings.triggering import ExternalTriggerMode, TriggerSource -from tests.configuration import ACQUISITION_LENGTH, NUM_CHANNELS_PER_DIGITISER_MODULE, NUM_MODULES_PER_DIGITISER, \ - NUM_MODULES_PER_AWG, NUM_CHANNELS_PER_AWG_MODULE +from tests.configuration import ( + ACQUISITION_LENGTH, + NUM_CHANNELS_PER_DIGITISER_MODULE, + NUM_MODULES_PER_DIGITISER, + NUM_MODULES_PER_AWG, + NUM_CHANNELS_PER_AWG_MODULE, +) from tests.device_factories import create_awg_card_for_testing, create_digitiser_card_for_testing @@ -209,8 +218,10 @@ def test_num_loops(self) -> None: self.assertEqual(5, self._device.num_loops) def test_transfer_waveform(self) -> None: - wfm = (array([0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8]) - * iinfo(int16).max).astype(int16) + wfm = ( + array([0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8]) + * iinfo(int16).max + ).astype(int16) self._device.transfer_waveform(wfm) transferred_wfm = self._device.transfer_buffers[0].data_array assert_array_equal(wfm, transferred_wfm) diff --git a/src/tests/test_star_hub.py b/src/tests/test_star_hub.py index 636b5a7..0db9fd2 100644 --- a/src/tests/test_star_hub.py +++ b/src/tests/test_star_hub.py @@ -6,7 +6,12 @@ from spectrumdevice.exceptions import SpectrumInvalidNumberOfEnabledChannels from spectrumdevice.settings.channel import SpectrumAnalogChannelName from spectrumdevice.settings.transfer_buffer import create_samples_acquisition_transfer_buffer -from tests.configuration import ACQUISITION_LENGTH, NUM_CARDS_IN_STAR_HUB, NUM_CHANNELS_PER_DIGITISER_MODULE, NUM_MODULES_PER_DIGITISER +from tests.configuration import ( + ACQUISITION_LENGTH, + NUM_CARDS_IN_STAR_HUB, + NUM_CHANNELS_PER_DIGITISER_MODULE, + NUM_MODULES_PER_DIGITISER, +) from tests.device_factories import create_spectrum_star_hub_for_testing from tests.test_single_card import SingleCardTest