Skip to content

Commit

Permalink
#26 - removed synchronous digital output from example (see issue #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbaker committed Jan 11, 2024
1 parent 14b4243 commit 5685e47
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
64 changes: 1 addition & 63 deletions src/example_scripts/awg_example.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
6 changes: 4 additions & 2 deletions src/spectrumdevice/devices/awg/awg_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion src/tests/device_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
7 changes: 4 additions & 3 deletions src/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
23 changes: 17 additions & 6 deletions src/tests/test_single_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/tests/test_star_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5685e47

Please sign in to comment.