Controlling Spectrum Instrumentation Digitisers with Python

For anyone using Spectrum Instrumentation digitisers: I’ve just released spectrumdevice: a new Python library for controlling them.

The Python API provided by Spectrum Instrumentation is a very thin wrapper around their .dll / .so driver and is quite un-pythonic and difficult to use without a spending a lot of time reading their documentation.

spectrumdevice provides an easy to use, high-level, object-oriented and fully typed interface for configuring and acquiring signals from digitisers.

You can install from PyPI:
pip install spectrumdevice

or conda-forge:
conda install -c conda-forge spectrumdevice

Links:
Source on GitHub
PyPI page
conda-forge page
Documentation

The README on GitHub is the best place for getting started. There are also some examples in the example_scripts folder in the repository. The documentation site provides detailed information about the API.

spectrumdevice features mock classes that allow you to run and test software that uses the library without hardware devices connected and on machines without the Spectrum Instrumentation drivers installed.

A quick example of configuring a card and continuously streaming waveforms from it:

from spectrumdevice import SpectrumCard
from spectrumdevice.settings import (
    TriggerSettings,
    AcquisitionSettings,
    TriggerSource,
    ExternalTriggerMode,
    AcquisitionMode
)

trigger_settings = TriggerSettings(
  trigger_sources=[TriggerSource.SPC_TMASK_EXT0],
  external_trigger_mode=ExternalTriggerMode.SPC_TM_POS,
  external_trigger_level_in_mv=1000,
)

acquisition_settings = AcquisitionSettings(
  acquisition_mode=AcquisitionMode.SPC_REC_FIFO_MULTI,
  sample_rate_in_hz=40000000,
  acquisition_length_in_samples=400,
  pre_trigger_length_in_samples=0,
  timeout_in_ms=1000,
  enabled_channels=[0, 1, 2, 3],
  vertical_ranges_in_mv=[200, 200, 200, 200],
  vertical_offsets_in_percent=[0, 0, 0, 0],
)

card = SpectrumCard(device_number=0)
card.configure_trigger(trigger_settings)
card.configure_acquisition(acquisition_settings)

card.execute_continuous_multi_fifo_acquisition()

measurements = []
while True:
    measurements.append(card.get_waveforms())

It’s a very new project and we’ve only been able to test it on devices we have in the lab, so it would be great to hear from people who have tried it out on other devices. Please get it touch via the GitHub issue tracker!

Thanks,

Christian

This is fantastic work! I do not have any of those devices, but this work is extremely important. If you believe you have made a robust enough contribution, perhaps you can also consider sharing your code via the Journal of Open Source Software, which will alow other to cite you, etc.