Skip to content

DMM (Digital Multimeter)¤

Interface¤

Digital multimeter (DMM) instrument interface.

Defines InstroDMM.

Public API

InstroDMM

logger module-attribute ¤

logger = getLogger(__name__)

InstroDMM ¤

InstroDMM(
    name: str,
    driver: DMMDriverBase,
    publishers: list[Publisher] | None = None,
    **kwargs,
)

Bases: Instrument

Digital multimeter hardware abstraction to communicate with various models and vendor DMMs.

Methods return Measurement and Command data types to be compatible with Nominal Instrumentation tools. Configure measurement with set_measurement_function(), then call read() to trigger a measurement.

Parameters:

  • name ¤

    (str) –

    A name to identify this DMM instance. Used in channel naming and published data.

  • driver ¤

    (DMMDriverBase) –

    Driver instance for the specific DMM vendor/model. Concrete drivers own their transport setup::

    dmm = InstroDMM(
        "main",
        driver=Agilent34401A("ASRL3::INSTR"),
    )
    
  • publishers ¤

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

    List of 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.

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

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] = {}

background_interval property writable ¤

background_interval

Get the background worker interval setting.

Returns:

  • float

    The current interval in seconds between background worker iterations. The worker waits this duration between executing background daemon functions.

background_enable property writable ¤

background_enable

Get the background worker enable state.

Returns:

  • bool

    True if the background worker is enabled, False otherwise.

start ¤

start() -> None

Start the background worker thread.

Raises:

  • ValueError

    If set_measurement_function() has not been called.

open ¤

open() -> None

Establish connection to the device.

close ¤

close() -> None

Disconnect from the device.

set_measurement_function ¤

set_measurement_function(
    function: MeasurementFunction, **kwargs
) -> Command

Set the DMM to the measurement function (dc voltage, resistance, etc.) you intend to perform.

Parameters:

  • function ¤
    (MeasurementFunction) –

    The measurement function to configure the DMM to.

  • **kwargs ¤

    Optional keyword arguments used as tags on the published Command.

Returns:

  • Command ( Command ) –

    A Command object containing the configuration, timestamp, and tags. The command is automatically published to all configured publishers.

set_digits ¤

set_digits(n: int, **kwargs) -> Command

Set resolution in digits. Requires set_measurement_function() to have been called.

set_aperture_seconds ¤

set_aperture_seconds(seconds: float, **kwargs) -> Command

Set integration time (aperture) in seconds. Requires set_measurement_function() first.

set_aperture_nplc ¤

set_aperture_nplc(nplc: float, **kwargs) -> Command

Set integration time (aperture) in number of power line cycles.

NPLC is number of power line cycles. DC Voltage, DC Current, and Resistance measurement resolution and accuracy are reduced by power line induced AC noise. Using NPLC of 1 or greater increases AC noise integration time and improves measurement resolution and accuracy at the cost of slower measurement rates. NPLC of 100 is recommended for highest accuracy.

Requires set_measurement_function() to have been called.

set_range ¤

set_range(value: float | None, **kwargs) -> Command

Set manual range; None = auto range. Requires set_measurement_function() first.

Publishes range_mode.cmd ("AUTO" / "MANUAL") on every call and range.cmd (float) only when a manual range is supplied. Splitting the two keeps each channel single-typed, which the Nominal streaming backend requires.

read ¤

read(**kwargs) -> Measurement

Trigger a measurement and return the value. Requires set_measurement_function() first.

The driver's measurement is dispatched based on the configured measurement function. The result is wrapped in a Measurement and published.

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.

stop ¤

stop()

Stop the background worker thread.

This method signals the background worker thread to stop and waits for it to complete. If the thread is not running, this method does nothing.

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.

Types & Configuration¤

Digital multimeter (DMM) instrument interface and helpers.

Defines MeasurementFunction, DMMMeasurementConfig and related helpers. Public API: MeasurementFunction, DMMMeasurementConfig

MeasurementFunction ¤

Bases: Enum

DMM measurement function (mode).

DC_VOLTAGE class-attribute instance-attribute ¤

DC_VOLTAGE = 'DC_VOLTAGE'

AC_VOLTAGE class-attribute instance-attribute ¤

AC_VOLTAGE = 'AC_VOLTAGE'

TWO_WIRE_RESISTANCE class-attribute instance-attribute ¤

TWO_WIRE_RESISTANCE = 'TWO_WIRE_RESISTANCE'

FOUR_WIRE_RESISTANCE class-attribute instance-attribute ¤

FOUR_WIRE_RESISTANCE = 'FOUR_WIRE_RESISTANCE'

DC_CURRENT class-attribute instance-attribute ¤

DC_CURRENT = 'DC_CURRENT'

AC_CURRENT class-attribute instance-attribute ¤

AC_CURRENT = 'AC_CURRENT'

RangeMode ¤

Bases: Enum

DMM range mode published on range_mode.cmd.

AUTO class-attribute instance-attribute ¤

AUTO = 'AUTO'

MANUAL class-attribute instance-attribute ¤

MANUAL = 'MANUAL'

DMMMeasurementConfig dataclass ¤

DMMMeasurementConfig(
    function: MeasurementFunction,
    digits: int | None = None,
    aperture_seconds: float | None = None,
    aperture_nplc: float | None = None,
    range: float | None = None,
)

Full acquisition configuration for a DMM measurement.

Holds the measurement function and optional acquisition options so users can adjust DMM acquisition in one place. Drivers apply only the options they support; unsupported options are ignored or can raise in the driver.

Attributes:

  • function (MeasurementFunction) –

    Measurement function (required).

  • digits (int | None) –

    Resolution in digits (optional). None = instrument default.

  • aperture_seconds (float | None) –

    Integration time in seconds (optional). Some instruments use this; others use aperture_nplc.

  • aperture_nplc (float | None) –

    Integration time in number of power-line cycles (optional). Some instruments use this; others use aperture_seconds.

  • range (float | None) –

    Manual range in current function's units (optional). None = auto range.

function instance-attribute ¤

digits class-attribute instance-attribute ¤

digits: int | None = None

aperture_seconds class-attribute instance-attribute ¤

aperture_seconds: float | None = None

aperture_nplc class-attribute instance-attribute ¤

aperture_nplc: float | None = None

range class-attribute instance-attribute ¤

range: float | None = None

Driver Interface¤

DMM driver base interface.

Defines DMMDriverBase.

Public API

DMMDriverBase

DMMDriverBase ¤

Bases: ABC

Abstract base class for vendor DMM drivers.

Concrete drivers own their transport setup and translate category-level calls into vendor-specific commands. The base declares only the category contract; transport choice and lifecycle live in the concrete driver.

Range and NPLC are split into per-function methods (set_voltage_range, set_current_nplc, ...) so the driver never has to track which measurement function is active. InstroDMM dispatches to the right method based on its own _measurement_config.function. This keeps the measurement function as a single source of truth on InstroDMM and makes it impossible to pass the wrong function to the driver.

open abstractmethod ¤

open() -> None

Open the driver's underlying transport.

close abstractmethod ¤

close() -> None

Close the driver's underlying transport.

set_measurement_function abstractmethod ¤

set_measurement_function(function: MeasurementFunction) -> None

Set the measurement function (mode) for the DMM.

set_digits ¤

set_digits(n: int) -> None

Set resolution in digits. Override if supported.

set_aperture_seconds ¤

set_aperture_seconds(seconds: float) -> None

Set integration time (aperture) in seconds. Override if supported.

set_dc_voltage_range ¤

set_dc_voltage_range(value: float | None) -> None

set_ac_voltage_range ¤

set_ac_voltage_range(value: float | None) -> None

set_dc_current_range ¤

set_dc_current_range(value: float | None) -> None

set_ac_current_range ¤

set_ac_current_range(value: float | None) -> None

set_two_wire_resistance_range ¤

set_two_wire_resistance_range(value: float | None) -> None

set_four_wire_resistance_range ¤

set_four_wire_resistance_range(value: float | None) -> None

set_dc_voltage_nplc ¤

set_dc_voltage_nplc(nplc: float) -> None

set_ac_voltage_nplc ¤

set_ac_voltage_nplc(nplc: float) -> None

set_dc_current_nplc ¤

set_dc_current_nplc(nplc: float) -> None

set_ac_current_nplc ¤

set_ac_current_nplc(nplc: float) -> None

set_two_wire_resistance_nplc ¤

set_two_wire_resistance_nplc(nplc: float) -> None

set_four_wire_resistance_nplc ¤

set_four_wire_resistance_nplc(nplc: float) -> None

measure_four_wire_resistance ¤

measure_four_wire_resistance() -> float

Measure 4-wire resistance. Override if supported.

measure_dc_voltage abstractmethod ¤

measure_dc_voltage() -> float

Measure DC voltage.

measure_ac_voltage abstractmethod ¤

measure_ac_voltage() -> float

Measure AC voltage.

measure_resistance abstractmethod ¤

measure_resistance() -> float

Measure 2-wire resistance.

measure_dc_current abstractmethod ¤

measure_dc_current() -> float

Measure DC current.

measure_ac_current abstractmethod ¤

measure_ac_current() -> float

Measure AC current.

Vendor Drivers¤

Keithley 2400¤

Keithley 2400 SourceMeter driver (DMM measurement portion only).

Implements DMM-style measurement (DC voltage, DC current, 2-wire resistance) for the Keithley 2400 SMU. Only the sense functionality is exposed; source configuration is kept minimal (zero level for V/I). AC voltage and AC current are not supported by the 2400 in this context.

The driver owns the SCPI/VISA transport.

Public API

Keithley2400

Keithley2400 ¤

Keithley2400(
    connection: str | VisaConnectionConfig,
    *,
    visa_backend: str = "@ivi",
    serial_config: SerialConfig | None = None,
    terminator: TerminatorConfig | None = None,
    timeout: TimeoutConfig | None = None,
)

Bases: DMMDriverBase

Driver for the Keithley 2400 SourceMeter (measurement only).

Supports DC voltage, DC current, and 2-wire resistance. Integration time is set via NPLC only (0.01 to 10); the 2400 does not expose aperture in seconds. Range and NPLC are scoped by the active measurement function, so those methods receive the function explicitly. Digits (resolution) is not directly settable; use NPLC. AC voltage/current are not supported.

Parameters:

  • connection ¤
    (str | VisaConnectionConfig) –

    VISA resource string, or a full VisaConnectionConfig when the caller needs to pass a prebuilt config object.

  • visa_backend ¤
    (str, default: '@ivi' ) –

    pyvisa backend specifier. Ignored when connection is already a VisaConnectionConfig.

  • serial_config ¤
    (SerialConfig | None, default: None ) –

    Optional serial-line settings for ASRL resources.

  • terminator ¤
    (TerminatorConfig | None, default: None ) –

    Optional read/write terminator settings.

  • timeout ¤
    (TimeoutConfig | None, default: None ) –

    Optional operation timeout settings.

open ¤
open() -> None
close ¤
close() -> None
set_measurement_function ¤
set_measurement_function(function: MeasurementFunction) -> None

Configure the 2400 for the selected measurement function.

set_digits ¤
set_digits(n: int) -> None

The 2400 does not expose a direct digits SCPI; use NPLC for resolution.

set_dc_voltage_nplc ¤
set_dc_voltage_nplc(nplc: float) -> None
set_dc_current_nplc ¤
set_dc_current_nplc(nplc: float) -> None
set_two_wire_resistance_nplc ¤
set_two_wire_resistance_nplc(nplc: float) -> None
set_dc_voltage_range ¤
set_dc_voltage_range(value: float | None) -> None
set_dc_current_range ¤
set_dc_current_range(value: float | None) -> None
set_two_wire_resistance_range ¤
set_two_wire_resistance_range(value: float | None) -> None
measure_dc_voltage ¤
measure_dc_voltage() -> float
measure_dc_current ¤
measure_dc_current() -> float
measure_resistance ¤
measure_resistance() -> float
measure_ac_voltage ¤
measure_ac_voltage() -> float
measure_ac_current ¤
measure_ac_current() -> float
set_aperture_seconds ¤
set_aperture_seconds(seconds: float) -> None

Set integration time (aperture) in seconds. Override if supported.

set_ac_voltage_range ¤
set_ac_voltage_range(value: float | None) -> None
set_ac_current_range ¤
set_ac_current_range(value: float | None) -> None
set_four_wire_resistance_range ¤
set_four_wire_resistance_range(value: float | None) -> None
set_ac_voltage_nplc ¤
set_ac_voltage_nplc(nplc: float) -> None
set_ac_current_nplc ¤
set_ac_current_nplc(nplc: float) -> None
set_four_wire_resistance_nplc ¤
set_four_wire_resistance_nplc(nplc: float) -> None
measure_four_wire_resistance ¤
measure_four_wire_resistance() -> float

Measure 4-wire resistance. Override if supported.

Agilent 34401A¤

Agilent/HP/Keysight 34401A digital multimeter driver.

Implements DMM-style measurements (DC/AC voltage, DC/AC current, 2- and 4-wire resistance) for the Agilent 34401A. The driver owns the SCPI/VISA transport.

Transport/protocols: SCPI over GPIB or RS-232.

Public API

Agilent34401A

Agilent34401A ¤

Agilent34401A(
    connection: str | VisaConnectionConfig,
    *,
    visa_backend: str = "@ivi",
    serial_config: SerialConfig | None = None,
    terminator: TerminatorConfig | None = None,
    timeout: TimeoutConfig | None = None,
)

Bases: DMMDriverBase

Driver for the Agilent/HP/Keysight 34401A digital multimeter.

The driver owns the SCPI/VISA transport. Users provide connection parameters for the instrument, and the driver handles VisaDriver construction internally.

Parameters:

  • connection ¤
    (str | VisaConnectionConfig) –

    VISA resource string, or a full VisaConnectionConfig when the caller needs to pass a prebuilt config object.

  • visa_backend ¤
    (str, default: '@ivi' ) –

    pyvisa backend specifier. Ignored when connection is already a VisaConnectionConfig.

  • serial_config ¤
    (SerialConfig | None, default: None ) –

    Optional serial-line settings for ASRL resources.

  • terminator ¤
    (TerminatorConfig | None, default: None ) –

    Optional read/write terminator settings.

  • timeout ¤
    (TimeoutConfig | None, default: None ) –

    Optional operation timeout settings.

set_dc_voltage_range class-attribute instance-attribute ¤
set_dc_voltage_range = _store_range
set_ac_voltage_range class-attribute instance-attribute ¤
set_ac_voltage_range = _store_range
set_dc_current_range class-attribute instance-attribute ¤
set_dc_current_range = _store_range
set_ac_current_range class-attribute instance-attribute ¤
set_ac_current_range = _store_range
set_two_wire_resistance_range class-attribute instance-attribute ¤
set_two_wire_resistance_range = _store_range
set_four_wire_resistance_range class-attribute instance-attribute ¤
set_four_wire_resistance_range = _store_range
open ¤
open() -> None

Open transport and place the instrument in remote mode.

Clears the error queue, then sends SYST:REM to disable the front panel and the RS-232 echo that can interfere with communication.

close ¤
close() -> None
set_measurement_function ¤
set_measurement_function(function: MeasurementFunction) -> None

Set the measurement function for subsequent reads.

Performs a dummy measurement to configure the instrument for this function.

set_digits ¤
set_digits(n: int) -> None

Set measurement resolution for subsequent reads.

Maps digits to an approximate resolution value passed to the MEAS:...? commands.

Parameters:

  • n ¤
    (int) –

    Number of digits (4, 5, or 6).

measure_dc_voltage ¤
measure_dc_voltage() -> float
measure_dc_current ¤
measure_dc_current() -> float
measure_resistance ¤
measure_resistance() -> float
measure_four_wire_resistance ¤
measure_four_wire_resistance() -> float
measure_ac_voltage ¤
measure_ac_voltage() -> float
measure_ac_current ¤
measure_ac_current() -> float
set_aperture_seconds ¤
set_aperture_seconds(seconds: float) -> None

Set integration time (aperture) in seconds. Override if supported.

set_dc_voltage_nplc ¤
set_dc_voltage_nplc(nplc: float) -> None
set_ac_voltage_nplc ¤
set_ac_voltage_nplc(nplc: float) -> None
set_dc_current_nplc ¤
set_dc_current_nplc(nplc: float) -> None
set_ac_current_nplc ¤
set_ac_current_nplc(nplc: float) -> None
set_two_wire_resistance_nplc ¤
set_two_wire_resistance_nplc(nplc: float) -> None
set_four_wire_resistance_nplc ¤
set_four_wire_resistance_nplc(nplc: float) -> None