Skip to content

DAQ (Data Acquisition)¤

Interface¤

data acquisition (DAQ) instrument interface and helpers.

Defines InstroDAQ and related helpers. Transport/protocols: SCPI, VISA.

Public API

InstroDAQ, HWTimingException, InstroDAQFacade

logger module-attribute ¤

logger = getLogger(__name__)

InstroDAQ ¤

InstroDAQ(
    name: str,
    driver: DAQDriverBase,
    device_id: str | None = None,
    connection_config: ConnectConfig | None = None,
    publishers: list[Publisher] | None = None,
    **kwargs,
)

Bases: Instrument

Parameters:

  • name ¤

    (str) –

    A name to give your DAQ that helps differentiate it from other DAQ instances.

  • driver ¤

    (DAQDriverBase) –

    The driver instance for the specific DAQ vendor.

  • device_id ¤

    (str | None, default: None ) –

    Provide this when using a non-SCPI/VISA DAQ device. Defaults to None.

  • connection_config ¤

    (ConnectConfig | None, default: None ) –

    Provide this when using a SCPI/VISA DAQ Device. Defaults to None.

  • publishers ¤

    (list[Publisher] | None, default: None ) –

    Publishers to send data to when executing methods. Defaults to None.

  • **kwargs ¤

    Optional keyword arguments used as tags throughout the life of the instrument. These tags are applied to the Measurement and Command objects and can be utilized by publishers like NominalCorePublisher as added metadata.

    Special keyword arguments: dataset_rid (str): If provided, automatically creates and adds a NominalCorePublisher with the specified dataset RID. Assumes a Nominal 'default' credential is stored on disk.

background_interval property writable ¤

background_interval: float

Get the background interval setting.

Returns:

  • float ( float ) –

    The current background worker interval in seconds. For DAQ devices, this is always 0

  • float

    since DAQ reads block and implicitly time the loop.

background_enable property writable ¤

background_enable: bool

Get the background worker enable state.

Returns:

  • bool ( bool ) –

    True if background worker is enabled, False otherwise.

name instance-attribute ¤

name = name

data_handler instance-attribute ¤

data_handler = (
    None
    if connection_config is None
    else DataHandler(select(connection_config))
)

publishers instance-attribute ¤

publishers = publishers or []

default_tags instance-attribute ¤

default_tags: dict[str, str] = {}

create classmethod ¤

Factory method to create a InstroDAQ instance for the specified vendor and resource.

Parameters:

  • name ¤
    (str) –

    The name assigned to the DAQ instrument.

  • vendor ¤
    (DAQVendor) –

    The vendor enum specifying which DAQ driver to use.

  • resource ¤
    (str | ConnectConfig) –

    The identifier/resource string or connection configuration for the DAQ.

  • publishers ¤
    (list[Publisher] | None, default: None ) –

    Optional list of publishers for data output.

  • **kwargs ¤

    Optional keyword arguments used as tags throughout the life of the instrument. These tags are applied to the Measurement and Command objects and can be utilized by publishers like NominalCorePublisher as added metadata.

    Special keyword arguments: dataset_rid (str): If provided, automatically creates and adds a NominalCorePublisher with the specified dataset RID. Assumes a Nominal 'default' credential is stored on disk.

Returns:

  • InstroDAQ ( InstroDAQ ) –

    An initialized InstroDAQ object with the specified configuration.

open ¤

open()

Establish connection to the device.

close ¤

close()

Disconnect from the device.

configure_analog_channel ¤

configure_analog_channel(
    direction: Direction,
    physical_channel: str,
    alias: str | None = None,
    range_min: float = -10.0,
    range_max: float = 10.0,
    scaler: Scaler | None = None,
    terminal_config: TerminalConfig | None = None,
)

Configure an analog input or output channel.

Parameters:

  • direction ¤
    (Direction) –

    The direction of the channel (INPUT or OUTPUT). Note: OUTPUT is not yet implemented.

  • physical_channel ¤
    (str) –

    The physical channel identifier (e.g., "ai0", "Dev1/ai0").

  • alias ¤
    (str | None, default: None ) –

    A user-friendly name for the channel. If not provided, the physical_channel name is used as the alias. Defaults to None.

  • range_min ¤
    (float, default: -10.0 ) –

    The minimum voltage range for the channel. Defaults to -10.0.

  • range_max ¤
    (float, default: 10.0 ) –

    The maximum voltage range for the channel. Defaults to 10.0.

  • scaler ¤
    (Scaler, default: None ) –

    A Scaler object responsible for scaling the data read by the DAQ channel. Defaults to None.

  • terminal_config ¤
    (TerminalConfig, default: None ) –

    The terminal configuration for the channel. Defaults to None.

Raises:

  • ValueError

    If direction is not INPUT or OUTPUT.

configure_ai_sample_rate ¤

configure_ai_sample_rate(
    sample_rate: float, samples_per_channel: int | None = None, **kwargs
)

Configures the device to use a hardware sample clock at the specified sample rate.

Parameters:

  • sample_rate ¤
    (float) –

    Sample Rate (Hz). Applies to all AI channels.

  • samples_per_channel ¤
    (int | None, default: None ) –

    The number of samples to fetch per channel

start ¤

start(**kwargs)

Start the DAQ device.

This method initiates a hardware timed data acquisition process.

Parameters:

  • **kwargs ¤

    Optional keyword arguments. Supported: - channel_type (ChannelType, optional): Specifies which DAQmx task to start (NI devices only).

stop ¤

stop(**kwargs)

Stop the DAQ device.

read_analog ¤

read_analog(**kwargs) -> Measurement | list[Measurement]

Read from analog input channels.

This method handles both hardware-timed and software-timed acquisitions: - Hardware-timed with background disabled: Fetches data from the DAQ buffer directly. - Hardware-timed with background enabled: Retrieves data from the channel buffer for all configured analog input channels. Returns a single Measurement if channels are time-correlated, or a list of Measurements if channels have different timestamps. - Software-timed: Initiates a conversion and returns the current values for all configured channels.

Parameters:

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Measurement objects and can be utilized by publishers like NominalCorePublisher as added metadata.

Returns:

write_analog_value ¤

write_analog_value(channel: str, value: float, **kwargs)

Write a value to an analog output channel.

Parameters:

  • channel ¤
    (str) –

    The alias of the analog output channel to write to.

  • value ¤
    (float) –

    The analog value to write.

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Command object and can be utilized by publishers like NominalCorePublisher as added metadata.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured analog output channels.

configure_digital_channel ¤

configure_digital_channel(
    direction: Direction,
    physical_channel: str,
    logic: Logic,
    logic_level: float | None = None,
    alias: str | None = None,
    port_width: DigitalPortWidth | None = None,
)

Configure a digital input or output channel.

Parameters:

  • direction ¤
    (Direction) –

    The direction of the channel (INPUT or OUTPUT).

  • physical_channel ¤
    (str) –

    The physical channel identifier (e.g., "di0", "port0/line0").

  • logic ¤
    (Logic) –

    The logic level type (HIGH or LOW).

  • logic_level ¤
    (float | None, default: None ) –

    The voltage threshold for the logic level (if hardware supports customization). If None, the driver's default logic level is used. Defaults to None.

  • alias ¤
    (str | None, default: None ) –

    A user-friendly name for the channel. If not provided, alias will be set to physical_channel. Defaults to None.

  • port_width ¤
    (DigitalPortWidth | None, default: None ) –

    The width of the digital port in bits (8, 16, 32, or 64). Only used when port configuring the channel as a port rather than a line. Defaults to None.

write_digital_line ¤

write_digital_line(channel: str, data: int, **kwargs)

Write a value to a digital output line.

Parameters:

  • channel ¤
    (str) –

    The alias of the digital output channel to write to.

  • data ¤
    (int) –

    The digital value to write (typically 0 or 1 for a line).

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Command object and can be utilized by publishers like NominalCorePublisher as added metadata.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured digital output channels.

Note

The written command is automatically published to all configured publishers.

read_digital_line ¤

read_digital_line(channel: str, **kwargs)

Read a value from a digital input line.

Parameters:

  • channel ¤
    (str) –

    The alias of the digital input channel to read from.

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Measurement object and can be utilized by publishers like NominalCorePublisher as added metadata.

Returns:

  • Measurement

    A Measurement object containing the digital value, channel name, and timestamp. The measurement is also automatically published to all configured publishers.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured digital input channels.

write_digital_port ¤

write_digital_port(channel: str, data: int, **kwargs)

Write a value to a digital output port.

Parameters:

  • channel ¤
    (str) –

    The alias of the digital output channel to write to.

  • data ¤
    (int) –

    The digital value to write to the port.

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Command object and can be utilized by publishers like NominalCorePublisher as added metadata.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured digital output channels.

Note

The written command is automatically published to all configured publishers.

read_digital_port ¤

read_digital_port(channel: str, **kwargs)

Read a value from a digital input port.

Parameters:

  • channel ¤
    (str) –

    The alias of the digital input channel to read from.

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Measurement object and can be utilized by publishers like NominalCorePublisher as added metadata.

Returns:

  • Measurement

    A Measurement object containing the digital port value, channel name, and timestamp. The measurement is also automatically published to all configured publishers.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured digital input channels.

configure_relay_channel ¤

configure_relay_channel(
    physical_channel: str, alias: str | None = None
)

Configure a relay channel.

Parameters:

  • physical_channel ¤
    (str) –

    The physical channel identifier (e.g., "3101" for slot 3, channel 101).

  • alias ¤
    (str | None, default: None ) –

    A user-friendly name for the relay. If not provided, the physical_channel name is used as the alias. Defaults to None.

close_relay ¤

close_relay(channel: str, **kwargs)

Close a relay (connect the circuit).

Parameters:

  • channel ¤
    (str) –

    The alias of the relay channel to close.

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Command object and can be utilized by publishers like NominalCorePublisher as added metadata.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured relay channels.

open_relay ¤

open_relay(channel: str, **kwargs)

Open a relay (disconnect the circuit).

Parameters:

  • channel ¤
    (str) –

    The alias of the relay channel to open.

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Command object and can be utilized by publishers like NominalCorePublisher as added metadata.

Raises:

  • KeyError

    If the specified channel alias is not found in the configured relay channels.

get_actual_sample_rate ¤

get_actual_sample_rate() -> float | None

Return the actual sample rate achieved by the hardware after start().

Returns None if the driver does not support this query or if start() has not been called.

get_points_in_buffer ¤

get_points_in_buffer(**kwargs) -> Measurement

Get the current number of points in the DAQ buffer.

This is useful for monitoring hardware-timed acquisitions to see how many samples are waiting to be read from the buffer.

Parameters:

  • **kwargs ¤

    Optional keyword arguments used as tags. These tags are applied to the Measurement object and can be utilized by publishers like NominalCorePublisher as added metadata.

Returns:

  • Measurement ( Measurement ) –

    A Measurement object containing the buffer point count with channel name

  • Measurement

    "{daq_name}.buffer" and a timestamp. The measurement is also automatically published

  • Measurement

    to all configured publishers.

add_publisher ¤

add_publisher(publisher: Publisher)

Add a publisher to the list of publishers for this instrument.

Publishers receive all Measurement and Command objects that are published by this instrument. Multiple publishers can be added to send data to different destinations.

Parameters:

  • publisher ¤
    (Publisher) –

    The publisher instance to add.

publish ¤

publish(data: Measurement | Command, **kwargs)

Publish a Measurement or Command to all configured publishers.

This method sends the data to all publishers that have been added to this instrument. Additional keyword arguments are passed through to each publisher's publish method.

Parameters:

  • data ¤
    (Measurement | Command) –

    The measurement or command data to publish.

  • **kwargs ¤

    Optional keyword arguments passed to each publisher's publish method.

get_identity ¤

get_identity() -> str

Query the instrument's identity string.

This method sends the SCPI "*IDN?" command to retrieve the instrument's identification information, which typically includes manufacturer, model number, serial number, and firmware version.

Returns:

  • str ( str ) –

    The instrument's identity string.

Raises:

  • RuntimeError

    If no connection is configured for this instrument (data_handler is None).

open_and_get_identity staticmethod ¤

open_and_get_identity(connection_config: ConnectConfig) -> str

Convenience method to open a connection, query identity, and close.

This static method creates a temporary instrument instance, opens a connection, queries the identity, closes the connection, and returns the identity string. Useful for instrument discovery without maintaining a long-lived connection.

Parameters:

  • connection_config ¤
    (ConnectConfig) –

    The connection configuration for the instrument.

Returns:

  • str ( str ) –

    The instrument's identity string.

Raises:

  • RuntimeError

    If the connection cannot be established or the identity cannot be queried.

send_arbitrary_command ¤

send_arbitrary_command(command: str)

Send an arbitrary command string to the instrument.

This method allows sending custom commands directly to the instrument without going through the instrument's high-level API. Useful for accessing instrument-specific features not exposed by the standard interface.

Parameters:

  • command ¤
    (str) –

    The command string to send to the instrument.

Raises:

  • RuntimeError

    If no connection is configured for this instrument (data_handler is None).

query_arbitrary_command ¤

query_arbitrary_command(command: str) -> str

Send an arbitrary command string and return the instrument's response.

This method sends a command and waits for a response, useful for querying instrument state or configuration. The response is returned as a string.

Parameters:

  • command ¤
    (str) –

    The query command string to send to the instrument.

Returns:

  • str ( str ) –

    The instrument's response to the query command.

Raises:

  • RuntimeError

    If no connection is configured for this instrument (data_handler is None).

add_background_daemon_function ¤

add_background_daemon_function(method: Callable, *args, **kwargs)

Adds a function (and its arguments) to be periodically called by the background worker daemon.

There may already be functions defined and this will add to the end of that list. Call define_background_daemon to clear and define a new function if you do not want the default functions to run.

Parameters:

  • method ¤
    (Callable) –

    The method/function to be invoked in the background thread.

  • *args ¤

    Positional arguments to pass to the method.

  • **kwargs ¤

    Keyword arguments to pass to the method.

get_channel ¤

get_channel(
    channel_name: str,
    length: int = 1,
    wait_for_latest: bool = False,
    timeout: float = 10.0,
) -> Measurement

Get most recent Measurement data for a specific channel from the buffer.

Parameters:

  • channel_name ¤
    (str) –

    The name of the channel from which to retrieve data.

  • length ¤
    (int, default: 1 ) –

    The number of most recent samples to return.

  • wait_for_latest ¤
    (bool, default: False ) –

    Block and wait for the next channel value(s).

  • timeout ¤
    (float, default: 10.0 ) –

    Timeout in seconds when waiting for channel or values. Defaults to 10.0 seconds. Only applies when wait_for_latest=True.

Returns:

  • Measurement ( Measurement ) –

    A Measurement object containing the requested channel data and timestamps.

Raises:

  • RuntimeError

    No background buffer exists because start() was not called.

  • ChannelNotFoundTimeoutError

    If wait_for_latest=True and the channel does not appear within timeout.

  • ChannelValueTimeoutError

    If wait_for_latest=True and sufficient values are not available within timeout.

define_background_daemon ¤

define_background_daemon(method: Callable, *args, **kwargs)

Clear all background daemon functions and register a single custom method.

This method clears any previously registered background daemon functions and registers a new method to be called in the background daemon loop. This is useful when you want to replace the default background functions with a custom implementation.

Parameters:

  • method ¤
    (Callable) –

    The method to call as part of the background daemon.

  • *args ¤

    Positional arguments to pass to the method when it is called.

  • **kwargs ¤

    Keyword arguments to pass to the method when it is called.

HWTimingException ¤

Bases: Exception

InstroDAQFacade ¤

InstroDAQFacade(nominal_daq: InstroDAQ)

Facade class that provides drivers with access to InstroDAQ configuration.

This class implements the APIInstroDAQ interface and allows drivers to access channel configurations and timing settings without direct access to the InstroDAQ instance's internal state.

Parameters:

  • nominal_daq ¤

    (InstroDAQ) –

    The InstroDAQ instance to provide access to.

ai_hw_timing_configs property ¤

ai_hw_timing_configs: HWTimingConfig

Get the hardware timing configuration for analog input channels.

Returns:

  • HWTimingConfig ( HWTimingConfig ) –

    The hardware timing configuration containing sample rate,

  • HWTimingConfig

    sample period, and samples per channel.

Raises:

  • ValueError

    If hardware timing has not been configured for analog input channels.

ai_sample_rate property ¤

ai_sample_rate: float

Get the analog input sample rate in Hz.

Returns:

  • float ( float ) –

    The sample rate in Hz for analog input channels.

Raises:

  • ValueError

    If hardware timing has not been configured for analog input channels.

channels property ¤

channels: list[DAQChannel]

Get all configured DAQ channels.

Returns:

  • list[DAQChannel]

    list[DAQChannel]: A list of all configured channels (analog and digital, input and output).

ai_channels property ¤

ai_channels: dict[str, AnalogChannel]

Get all configured analog input channels.

Returns:

  • dict[str, AnalogChannel]

    dict[str, AnalogChannel]: A dictionary mapping channel aliases to AnalogChannel objects.

ao_channels property ¤

ao_channels: dict[str, AnalogChannel]

Get all configured analog output channels.

Returns:

  • dict[str, AnalogChannel]

    dict[str, AnalogChannel]: A dictionary mapping channel aliases to AnalogChannel objects.

di_channels property ¤

di_channels: dict[str, DigitalChannel]

Get all configured digital input channels.

Returns:

  • dict[str, DigitalChannel]

    dict[str, DigitalChannel]: A dictionary mapping channel aliases to DigitalChannel objects.

do_channels property ¤

do_channels: dict[str, DigitalChannel]

Get all configured digital output channels.

Returns:

  • dict[str, DigitalChannel]

    dict[str, DigitalChannel]: A dictionary mapping channel aliases to DigitalChannel objects.

Types & Configuration¤

data acquisition (DAQ) instrument interface and helpers.

Defines DAQVendor and related helpers. Public API: DAQVendor, ChannelType, Logic, Direction, HWTimingConfig, DAQChannel, AnalogChannel, DigitalPortWidth, DigitalChannel, DigitalPortChannel, DigitalLineChannel, RelayChannel

DAQVendor ¤

Bases: Enum

NI class-attribute instance-attribute ¤

NI = 'NI DAQmx'

LABJACK_T_SERIES class-attribute instance-attribute ¤

LABJACK_T_SERIES = 'LabJack T-Series'

KEYSIGHT_34980 class-attribute instance-attribute ¤

KEYSIGHT_34980 = 'KEYSIGHT_34980'

MCC class-attribute instance-attribute ¤

MCC = 'MCC DAQ'

ChannelType ¤

Bases: Enum

ANALOG_INPUT class-attribute instance-attribute ¤

ANALOG_INPUT = 'ai'

ANALOG_OUTPUT class-attribute instance-attribute ¤

ANALOG_OUTPUT = 'ao'

DIGITAL_INPUT class-attribute instance-attribute ¤

DIGITAL_INPUT = 'di'

DIGITAL_OUTPUT class-attribute instance-attribute ¤

DIGITAL_OUTPUT = 'do'

Logic ¤

Bases: Enum

HIGH class-attribute instance-attribute ¤

HIGH = 'HIGH'

LOW class-attribute instance-attribute ¤

LOW = 'LOW'

Direction ¤

Bases: Enum

INPUT class-attribute instance-attribute ¤

INPUT = 'INPUT'

OUTPUT class-attribute instance-attribute ¤

OUTPUT = 'OUTPUT'

TerminalConfig ¤

Bases: Enum

DIFF class-attribute instance-attribute ¤

DIFF = 'DIFFERENTIAL'

NRSE class-attribute instance-attribute ¤

NRSE = 'NRSE'

RSE class-attribute instance-attribute ¤

RSE = 'RSE'

HWTimingConfig dataclass ¤

HWTimingConfig(
    sample_rate: float, sample_period: int, samples_per_channel: int
)

sample_rate instance-attribute ¤

sample_rate: float

sample_period instance-attribute ¤

sample_period: int

samples_per_channel instance-attribute ¤

samples_per_channel: int

DAQChannel dataclass ¤

DAQChannel(*, physical_channel: str, alias: str, direction: Direction)

physical_channel instance-attribute ¤

physical_channel: str

alias instance-attribute ¤

alias: str

direction instance-attribute ¤

direction: Direction

AnalogChannel dataclass ¤

AnalogChannel(
    range_max: float,
    range_min: float,
    scaler: Scaler | None,
    terminal_config: TerminalConfig | None = None,
    *,
    physical_channel: str,
    alias: str,
    direction: Direction,
)

Bases: DAQChannel

range_max instance-attribute ¤

range_max: float

range_min instance-attribute ¤

range_min: float

scaler instance-attribute ¤

scaler: Scaler | None

terminal_config class-attribute instance-attribute ¤

terminal_config: TerminalConfig | None = None

physical_channel instance-attribute ¤

physical_channel: str

alias instance-attribute ¤

alias: str

direction instance-attribute ¤

direction: Direction

DigitalPortWidth ¤

Bases: IntEnum

WIDTH_8 class-attribute instance-attribute ¤

WIDTH_8 = 8

WIDTH_16 class-attribute instance-attribute ¤

WIDTH_16 = 16

WIDTH_32 class-attribute instance-attribute ¤

WIDTH_32 = 32

WIDTH_64 class-attribute instance-attribute ¤

WIDTH_64 = 64

DigitalChannel dataclass ¤

DigitalChannel(
    logic_level: float | None,
    logic: Logic,
    *,
    physical_channel: str,
    alias: str,
    direction: Direction,
)

Bases: DAQChannel

logic_level instance-attribute ¤

logic_level: float | None

logic instance-attribute ¤

logic: Logic

physical_channel instance-attribute ¤

physical_channel: str

alias instance-attribute ¤

alias: str

direction instance-attribute ¤

direction: Direction

DigitalPortChannel dataclass ¤

DigitalPortChannel(
    logic_level: float | None,
    logic: Logic,
    width: DigitalPortWidth,
    *,
    physical_channel: str,
    alias: str,
    direction: Direction,
)

Bases: DigitalChannel

width instance-attribute ¤

physical_channel instance-attribute ¤

physical_channel: str

alias instance-attribute ¤

alias: str

direction instance-attribute ¤

direction: Direction

logic_level instance-attribute ¤

logic_level: float | None

logic instance-attribute ¤

logic: Logic

DigitalLineChannel dataclass ¤

DigitalLineChannel(
    logic_level: float | None,
    logic: Logic,
    bit_position: int | None = None,
    *,
    physical_channel: str,
    alias: str,
    direction: Direction,
)

Bases: DigitalChannel

bit_position class-attribute instance-attribute ¤

bit_position: int | None = None

physical_channel instance-attribute ¤

physical_channel: str

alias instance-attribute ¤

alias: str

direction instance-attribute ¤

direction: Direction

logic_level instance-attribute ¤

logic_level: float | None

logic instance-attribute ¤

logic: Logic

RelayChannel dataclass ¤

RelayChannel(
    *, physical_channel: str, alias: str, direction: Direction
)

Bases: DAQChannel

A relay channel that can be opened or closed to route signals.

Note: direction is set to OUTPUT by convention (relay control is an output command).

physical_channel instance-attribute ¤

physical_channel: str

alias instance-attribute ¤

alias: str

direction instance-attribute ¤

direction: Direction

Scaling¤

Scaling for data acquisition (DAQ).

Defines Scaler and related helpers. Public API: Scaler, LinearScaler, ReverseLinearScaler, DevicePassthrough, ScalerPipeline

Scaler ¤

Bases: ABC

Abstract base class for scaler operations.

Scalers convert raw DAQ readings to scaled values with appropriate units. All scaler implementations must provide a scaling function and units.

units abstractmethod property ¤

units: str

Get the units of the scaled values.

Returns:

  • str

    A string representing the units (e.g., "V", "degC", "mV").

scale abstractmethod ¤

scale(raw: float) -> float

Scale a raw DAQ reading to a physical value.

Parameters:

  • raw ¤
    (float) –

    The raw value from the DAQ device.

Returns:

  • float

    The scaled physical value.

LinearScaler ¤

LinearScaler(gain: float, offset: float, units: str)

Bases: Scaler

Scaler that requires a linear transformation: output = raw * gain + offset.

This is useful for sensors that have a linear relationship between the raw reading and the physical quantity being measured.

Parameters:

  • gain ¤

    (float) –

    The gain factor to multiply the raw value by.

  • offset ¤

    (float) –

    The offset to add to the scaled value.

  • units ¤

    (str) –

    The units string for the scaled output.

units property ¤

units: str

Get the units of the scaled values.

Returns:

  • str

    The units string specified during initialization.

scale ¤

scale(raw: float) -> float

Scale the raw value using linear transformation.

Parameters:

  • raw ¤
    (float) –

    The value to be scaled.

Returns:

  • float

    The scaled value: raw * gain + offset.

ReverseLinearScaler ¤

ReverseLinearScaler(gain: float, offset: float, units: str)

Bases: Scaler

Scaler that applies a reverse linear transformation: output = (raw - offset) / gain.

This is the inverse of LinearScaler and is useful when a signal of interest has been amplified prior to being measured.

Parameters:

  • gain ¤

    (float) –

    The gain factor to divide the offset-corrected value by.

  • offset ¤

    (float) –

    The offset to subtract from the raw value before scaling.

  • units ¤

    (str) –

    The units string for the scaled output.

units property ¤

units: str

Get the units of the scaled values.

Returns:

  • str

    The units string specified during initialization.

scale ¤

scale(raw: float) -> float

Scale the raw value using reverse linear transformation.

Parameters:

  • raw ¤
    (float) –

    The value to be scaled.

Returns:

  • float

    The scaled value: (raw - offset) / gain.

DevicePassthrough ¤

DevicePassthrough(units: str)

Bases: Scaler

Scaler that passes through raw values without scaling.

This is useful when the DAQ device already provides values in the desired units, or when no scaling is needed.

Parameters:

  • units ¤

    (str) –

    The units string for the output values.

units property ¤

units: str

Get the units of the output values.

Returns:

  • str

    The units string specified during initialization.

scale ¤

scale(raw: float) -> float

Pass through the raw value unchanged.

Parameters:

  • raw ¤
    (float) –

    The value to be scaled.

Returns:

  • float

    The raw value unchanged.

ScalerPipeline ¤

ScalerPipeline(stage: Scaler, *stages: Scaler)

Bases: Scaler

Scaler that chains multiple scaler stages together.

The pipeline applies each scaler stage sequentially, with the output of one stage becoming the input to the next. This allows for complex multi-stage transformations (e.g., voltage scaling followed by thermocouple conversion).

Parameters:

  • *stages ¤

    (Scaler, default: () ) –

    One or more Scaler instances to apply in sequence.

units property ¤

units: str

Get the units of the final output.

Returns:

  • str

    The units string from the last stage in the pipeline.

scale ¤

scale(raw: float) -> float

Scale the raw value through all pipeline stages.

Parameters:

  • raw ¤
    (float) –

    The value to be scaled.

Returns:

  • float

    The value after passing through all scaler stages.

Thermocouple Scaling¤

Thermocouple for data acquisition (DAQ).

Defines TC_TYPE and related helpers. Public API: TC_TYPE, ThermocoupleSensor

TC_TYPE ¤

Bases: Enum

B class-attribute instance-attribute ¤
B = 'B'
E class-attribute instance-attribute ¤
E = 'E'
J class-attribute instance-attribute ¤
J = 'J'
K class-attribute instance-attribute ¤
K = 'K'
N class-attribute instance-attribute ¤
N = 'N'
R class-attribute instance-attribute ¤
R = 'R'
S class-attribute instance-attribute ¤
S = 'S'
T class-attribute instance-attribute ¤
T = 'T'

ThermocoupleSensor ¤

ThermocoupleSensor(type: TC_TYPE, cjc_temp: float)

Bases: Scaler

Sensor class for thermocouple measurement scaling.

This sensor converts DAQ voltage readings (in volts or millivolts, as required by the thermocouple library) to temperature values in degrees Celsius using the appropriate thermocouple type and cold junction compensation (CJC).

Parameters:

  • type ¤
    (TC_TYPE) –

    The type of thermocouple (e.g., K, J, T, etc.).

  • cjc ¤
    (float) –

    Cold junction compensation (reference temperature) in degrees Celsius.

Example

sensor = ThermocoupleSensor(TC_TYPE.K, 25.0) # Type K with 25°C CJC

Methods:

  • scale

    Convert a raw input voltage to temperature in degrees Celsius.

  • units

    Returns "degC".

Parameters:

  • type ¤
    (TC_TYPE) –

    The thermocouple type (e.g., K, J, etc.).

  • cjc_temp ¤
    (float) –

    The cold junction compensation reference temperature in degC.

units property ¤
units: str

Units of the scaled measurement.

Returns:

  • str ( str ) –

    "degC" (degrees Celsius)

scale ¤
scale(raw: float | int) -> float

Convert voltage to temperature in degrees Celsius.

Parameters:

  • raw ¤
    (float | int) –

    The measured thermoelectric voltage (in volts or millivolts, depending on the thermocouple library's expectation).

Returns:

  • float ( float ) –

    The calculated temperature in degrees Celsius.

Driver Interface¤

data acquisition (DAQ) instrument interface and helpers.

Defines DAQDriverBase and related helpers. Public API: APIInstroDAQ, DAQDriverBase, DAQDriverDataHandler

logger module-attribute ¤

logger = getLogger(__name__)

APIInstroDAQ ¤

Bases: Protocol

API for the InstroDAQ instrument type.

ai_hw_timing_configs property ¤

ai_hw_timing_configs: HWTimingConfig

Get the hardware timing configuration for the analog input channels.

ai_sample_rate property ¤

ai_sample_rate: float

Get the sample rate for the analog input channels.

channels property ¤

channels: list[DAQChannel]

Get all the configured channels on the DAQ.

ai_channels property ¤

ai_channels: dict[str, AnalogChannel]

Get the configured analog input channels on the DAQ.

ao_channels property ¤

ao_channels: dict[str, AnalogChannel]

Get the configured analog output channels on the DAQ.

di_channels property ¤

di_channels: dict[str, DigitalChannel]

Get the configured digital input channels on the DAQ.

do_channels property ¤

do_channels: dict[str, DigitalChannel]

Get the configured digital output channels on the DAQ.

HWTimestamper ¤

HWTimestamper(last_timestamp: int)

Generates contiguous nanosecond timestamps for hardware-timed DAQ batches.

Anchors the timeline to the wall clock exactly once via seed(), then advances purely by sample period on every subsequent next() call. This eliminates timestamp overlap when two reads return in rapid succession.

seed classmethod ¤

Create a timestamper anchored to the first batch's wall-clock read-return time.

Parameters:

  • t_wall ¤
    (int) –

    Wall-clock ns timestamp captured when the first read returned.

  • dt ¤
    (int) –

    Sample period in nanoseconds.

  • length ¤
    (int) –

    Number of samples in the first batch.

Returns:

next_batch ¤

next_batch(dt: int, length: int) -> list[int]

Return timestamps for the next batch, continuing from the previous batch.

Parameters:

  • dt ¤
    (int) –

    Sample period in nanoseconds.

  • length ¤
    (int) –

    Number of samples in this batch.

Returns:

  • list[int]

    list[int]: Nanosecond timestamps, one per sample.

DAQDriverBase ¤

Bases: ABC

points_in_buffer instance-attribute ¤

points_in_buffer: int

hal instance-attribute ¤

get_driver classmethod ¤

get_driver(
    vendor: DAQVendor, resource: str | None = None
) -> DAQDriverBase

Get a driver instance for the specified vendor and resource.

Parameters:

  • vendor ¤
    (DAQVendor) –

    The vendor of the DAQ device.

  • resource ¤
    (str | None, default: None ) –

    The resource identifier for the DAQ device.

Returns:

  • DAQDriverBase ( DAQDriverBase ) –

    A driver instance for the specified vendor and resource.

open abstractmethod ¤

open()

Establish connection to the device.

close abstractmethod ¤

close()

Disconnect from the device.

configure_ai_channel abstractmethod ¤

configure_ai_channel(channel: AnalogChannel)

Configure a channel on the device.

configure_ao_channel ¤

configure_ao_channel(channel: AnalogChannel)

configure_ai_hw_timing abstractmethod ¤

configure_ai_hw_timing(hw_timing_config: HWTimingConfig)

Configure the DAQ for hardware timed sampling.

define_digital_channel abstractmethod ¤

define_digital_channel(
    direction: Direction,
    physical_channel: str,
    logic: Logic,
    logic_level: float | None = None,
    alias: str | None = None,
    port_width: DigitalPortWidth | None = None,
) -> DigitalChannel

configure_do_channel abstractmethod ¤

configure_do_channel(channel: DigitalChannel)

Configure a channel on the device.

configure_di_channel abstractmethod ¤

configure_di_channel(channel: DigitalChannel)

Configure a channel on the device.

start abstractmethod ¤

start(**kwargs)

Start the DAQ device for hw timed data acquisition.

stop abstractmethod ¤

stop(**kwargs)

Stop the DAQ device.

read_analog abstractmethod ¤

read_analog() -> Any

Read from analog input channels.

fetch_analog abstractmethod ¤

fetch_analog() -> Any

get_actual_sample_rate ¤

get_actual_sample_rate() -> float | None

Return the actual sample rate achieved by the hardware after start().

Returns None if the driver does not support this query or if start() has not been called.

write_analog_value ¤

write_analog_value(channel: AnalogChannel, value: float)

Write a value to an analog output channel.

Parameters:

write_digital_line abstractmethod ¤

write_digital_line(channel: DigitalChannel, data: int)

Write to digital output channels.

read_digital_line abstractmethod ¤

read_digital_line(channel: DigitalChannel) -> int

write_digital_port abstractmethod ¤

write_digital_port(channel: DigitalChannel, data: int)

Write a value to a digital output port.

read_digital_port abstractmethod ¤

read_digital_port(channel: DigitalChannel) -> int

define_relay_channel ¤

define_relay_channel(
    physical_channel: str, alias: str | None = None
) -> RelayChannel

Define a relay channel.

Parameters:

  • physical_channel ¤
    (str) –

    Physical channel identifier (e.g., "3101" for slot 3, channel 101).

  • alias ¤
    (str | None, default: None ) –

    Optional alias for the channel.

Returns:

  • RelayChannel ( RelayChannel ) –

    The configured relay channel object.

close_relay ¤

close_relay(channel: RelayChannel)

Close a relay channel (connect the circuit).

Parameters:

open_relay ¤

open_relay(channel: RelayChannel)

Open a relay channel (disconnect the circuit).

Parameters:

DAQDriverDataHandler ¤

DAQDriverDataHandler()

Bases: DAQDriverBase

data_handler property ¤

data_handler: DataHandler

Get the data handler, ensuring it's been set.

points_in_buffer instance-attribute ¤

points_in_buffer: int

hal instance-attribute ¤

set_data_handler ¤

set_data_handler(data_handler: DataHandler)

Set the data handler after construction.

get_driver classmethod ¤

get_driver(
    vendor: DAQVendor, resource: str | None = None
) -> DAQDriverBase

Get a driver instance for the specified vendor and resource.

Parameters:

  • vendor ¤
    (DAQVendor) –

    The vendor of the DAQ device.

  • resource ¤
    (str | None, default: None ) –

    The resource identifier for the DAQ device.

Returns:

  • DAQDriverBase ( DAQDriverBase ) –

    A driver instance for the specified vendor and resource.

open abstractmethod ¤

open()

Establish connection to the device.

close abstractmethod ¤

close()

Disconnect from the device.

configure_ai_channel abstractmethod ¤

configure_ai_channel(channel: AnalogChannel)

Configure a channel on the device.

configure_ao_channel ¤

configure_ao_channel(channel: AnalogChannel)

configure_ai_hw_timing abstractmethod ¤

configure_ai_hw_timing(hw_timing_config: HWTimingConfig)

Configure the DAQ for hardware timed sampling.

define_digital_channel abstractmethod ¤

define_digital_channel(
    direction: Direction,
    physical_channel: str,
    logic: Logic,
    logic_level: float | None = None,
    alias: str | None = None,
    port_width: DigitalPortWidth | None = None,
) -> DigitalChannel

configure_do_channel abstractmethod ¤

configure_do_channel(channel: DigitalChannel)

Configure a channel on the device.

configure_di_channel abstractmethod ¤

configure_di_channel(channel: DigitalChannel)

Configure a channel on the device.

start abstractmethod ¤

start(**kwargs)

Start the DAQ device for hw timed data acquisition.

stop abstractmethod ¤

stop(**kwargs)

Stop the DAQ device.

read_analog abstractmethod ¤

read_analog() -> Any

Read from analog input channels.

fetch_analog abstractmethod ¤

fetch_analog() -> Any

get_actual_sample_rate ¤

get_actual_sample_rate() -> float | None

Return the actual sample rate achieved by the hardware after start().

Returns None if the driver does not support this query or if start() has not been called.

write_analog_value ¤

write_analog_value(channel: AnalogChannel, value: float)

Write a value to an analog output channel.

Parameters:

write_digital_line abstractmethod ¤

write_digital_line(channel: DigitalChannel, data: int)

Write to digital output channels.

read_digital_line abstractmethod ¤

read_digital_line(channel: DigitalChannel) -> int

write_digital_port abstractmethod ¤

write_digital_port(channel: DigitalChannel, data: int)

Write a value to a digital output port.

read_digital_port abstractmethod ¤

read_digital_port(channel: DigitalChannel) -> int

define_relay_channel ¤

define_relay_channel(
    physical_channel: str, alias: str | None = None
) -> RelayChannel

Define a relay channel.

Parameters:

  • physical_channel ¤
    (str) –

    Physical channel identifier (e.g., "3101" for slot 3, channel 101).

  • alias ¤
    (str | None, default: None ) –

    Optional alias for the channel.

Returns:

  • RelayChannel ( RelayChannel ) –

    The configured relay channel object.

close_relay ¤

close_relay(channel: RelayChannel)

Close a relay channel (connect the circuit).

Parameters:

open_relay ¤

open_relay(channel: RelayChannel)

Open a relay channel (disconnect the circuit).

Parameters:

Vendor Drivers¤

Keysight 34980A¤

Keysight 34980A driver for data acquisition (DAQ) instruments.

Implements Keysight34980A and supporting helpers. Transport/protocols: SCPI.

Public API

KeysightData, keysight_str_to_ns, parse_datastring, get_scanlist, Keysight34980A

KeysightData dataclass ¤

KeysightData(
    data: str, timestamp: int | None = None, dt: int | None = None
)
data instance-attribute ¤
data: str
timestamp class-attribute instance-attribute ¤
timestamp: int | None = None
dt class-attribute instance-attribute ¤
dt: int | None = None

Keysight34980A ¤

Keysight34980A(sync_system_clock: bool = True)

Bases: DAQDriverDataHandler

points_in_buffer instance-attribute ¤
points_in_buffer: int = 0
hal instance-attribute ¤
data_handler property ¤
data_handler: DataHandler

Get the data handler, ensuring it's been set.

open ¤
open()
close ¤
close()
configure_ai_channel ¤
configure_ai_channel(channel: AnalogChannel)

Configure a channel on the device.

configure_ai_hw_timing ¤
configure_ai_hw_timing(hw_timing_config: HWTimingConfig)

Configure the DAQ for hardware timed sampling.

start ¤
start(**kwargs)

Start the DAQ device for hw timed data acquisition.

stop ¤
stop(**kwargs)

Stop the DAQ device.

read_analog ¤
read_analog() -> KeysightData
fetch_analog ¤
fetch_analog() -> KeysightData

Read from analog input buffer all channels available.

define_digital_channel ¤
define_digital_channel(
    direction: Direction,
    physical_channel: str,
    logic: Logic,
    logic_level: float | None = None,
    alias: str | None = None,
    port_width: DigitalPortWidth | None = None,
) -> DigitalChannel
configure_do_channel ¤
configure_do_channel(channel: DigitalChannel)

Configure a channel on the device.

configure_di_channel ¤
configure_di_channel(channel: DigitalChannel)

Configure a channel on the device.

write_digital_line ¤
write_digital_line(channel: DigitalChannel, data: int) -> None
read_digital_line ¤
read_digital_line(channel: DigitalChannel) -> int
write_digital_port ¤
write_digital_port(channel: DigitalChannel, data: int)
read_digital_port ¤
read_digital_port(channel: DigitalChannel) -> int
close_relay ¤
close_relay(channel: RelayChannel)

Close a relay channel using SCPI command.

open_relay ¤
open_relay(channel: RelayChannel)

Open a relay channel using SCPI command.

get_driver classmethod ¤
get_driver(
    vendor: DAQVendor, resource: str | None = None
) -> DAQDriverBase

Get a driver instance for the specified vendor and resource.

Parameters:

  • vendor ¤
    (DAQVendor) –

    The vendor of the DAQ device.

  • resource ¤
    (str | None, default: None ) –

    The resource identifier for the DAQ device.

Returns:

  • DAQDriverBase ( DAQDriverBase ) –

    A driver instance for the specified vendor and resource.

configure_ao_channel ¤
configure_ao_channel(channel: AnalogChannel)
get_actual_sample_rate ¤
get_actual_sample_rate() -> float | None

Return the actual sample rate achieved by the hardware after start().

Returns None if the driver does not support this query or if start() has not been called.

write_analog_value ¤
write_analog_value(channel: AnalogChannel, value: float)

Write a value to an analog output channel.

Parameters:

define_relay_channel ¤
define_relay_channel(
    physical_channel: str, alias: str | None = None
) -> RelayChannel

Define a relay channel.

Parameters:

  • physical_channel ¤
    (str) –

    Physical channel identifier (e.g., "3101" for slot 3, channel 101).

  • alias ¤
    (str | None, default: None ) –

    Optional alias for the channel.

Returns:

  • RelayChannel ( RelayChannel ) –

    The configured relay channel object.

set_data_handler ¤
set_data_handler(data_handler: DataHandler)

Set the data handler after construction.

keysight_str_to_ns ¤

keysight_str_to_ns(ts_str: str) -> int

Convert a Keysight timestamp string into nanoseconds since the Unix epoch (UTC).

Parameters:

  • ts_str ¤
    (str) –

    Timestamp string in format "YYYY,MM,DD,HH,MM,SS.sss"

Returns:

  • int ( int ) –

    Epoch timestamp in nanoseconds (UTC).

parse_datastring ¤

parse_datastring(data: str) -> tuple[list[float], list[int]]

Parse Keysight DAQ data string into measurement and timestamp lists.

Parameters:

  • data ¤
    (str) –

    String containing alternating measurements and timestamps

Returns:

get_scanlist ¤

get_scanlist(channels: list[DAQChannel]) -> list[DAQChannel]