Source code for instro.daq.types

"""DAQ shared types: vendors, channel types, terminal configs, hardware-timing config."""

from dataclasses import dataclass
from enum import Enum, IntEnum

from instro.daq.scaling.scaling import Scaler
from instro.daq.scaling.thermocouple import TC_TYPE, TC_UNIT


[docs] class DAQVendor(Enum): NI = "NI DAQmx" LABJACK_T_SERIES = "LabJack T-Series" KEYSIGHT_34980 = "KEYSIGHT_34980" MCC = "MCC DAQ"
# Add other vendors as needed # TODO: kill this?
[docs] class ChannelType(Enum): ANALOG_INPUT = "ai" ANALOG_OUTPUT = "ao" DIGITAL_INPUT = "di" DIGITAL_OUTPUT = "do"
[docs] class Logic(Enum): HIGH = "HIGH" LOW = "LOW"
[docs] class Direction(Enum): INPUT = "INPUT" OUTPUT = "OUTPUT"
[docs] class TerminalConfig(Enum): DIFF = "DIFFERENTIAL" NRSE = "NRSE" RSE = "RSE"
[docs] class CJCSource(Enum): INTERNAL = "INTERNAL" CONSTANT = "CONSTANT" CHANNEL = "CHANNEL"
[docs] @dataclass(frozen=True) class HWTimingConfig: sample_rate: float sample_period: int samples_per_channel: int
# sample_clock_source: str | None = None
[docs] @dataclass(frozen=True, kw_only=True) class DAQChannel: physical_channel: str alias: str direction: Direction
# ======== Analog Channel Types ===========
[docs] @dataclass(frozen=True) class AnalogChannel(DAQChannel): range_max: float range_min: float scaler: Scaler | None terminal_config: TerminalConfig | None = None
[docs] @dataclass(frozen=True) class AnalogVoltageChannel(DAQChannel): range_max: float range_min: float scaler: Scaler | None terminal_config: TerminalConfig | None = None
[docs] @dataclass(frozen=True) class AnalogCurrentChannel(DAQChannel): range_max: float range_min: float scaler: Scaler | None
[docs] @dataclass(frozen=True) class AnalogThermocoupleChannel(DAQChannel): range_max: float range_min: float scaler: Scaler | None tc_type: TC_TYPE cjc_source: CJCSource | None cjc_temp: float | None cjc_channel: str | None # Unit of cjc_temp, range_min/range_max, and the temperatures the driver returns on read. unit: TC_UNIT # Volts-domain scaler applied before temperature conversion (LabJack only), e.g. descaling an amplified read from an LJTick-InAmp. tc_input_scaler: Scaler | None = None
# The analog channel types are siblings, so driver state that holds any of them is typed on this union. AnalogChannelUnion = AnalogChannel | AnalogVoltageChannel | AnalogCurrentChannel | AnalogThermocoupleChannel # ======== Digital Channel Types ===========
[docs] class DigitalPortWidth(IntEnum): WIDTH_8 = 8 WIDTH_16 = 16 WIDTH_32 = 32 WIDTH_64 = 64
[docs] @dataclass(frozen=True) class DigitalChannel(DAQChannel): logic_level: float | None logic: Logic
[docs] @dataclass(frozen=True) class DigitalPortChannel(DigitalChannel): width: DigitalPortWidth
[docs] @dataclass(frozen=True) class DigitalLineChannel(DigitalChannel): bit_position: int | None = None
[docs] @dataclass(frozen=True) class RelayChannel(DAQChannel): """A relay channel routed via open/close. ``direction`` is always ``OUTPUT`` (relay control is a command).""" pass