I2CInterface#

class I2CInterface(
name: str,
driver: I2CDriverBase,
system_definition: SystemDefinition,
publishers: list[Publisher] | None = None,
**kwargs,
)[source]#

Bases: Instrument

I2C interface supporting register-based and command-based devices.

Commands are enum values OR’d together and sent as a single byte stream. The SystemDefinition is read-only — I2CInterface resolves names to transactions on every call; the vendor driver never sees it.

Initialize an I2CInterface.

Parameters:
  • name – Channel-name prefix for published data.

  • driver –

    Concrete I2C-adapter driver; owns its own transport:

    i2c = I2CInterface(
        "main",
        driver=Aardvark(serial_number="2239-764425"),
        system_definition=system,
    )
    

  • system_definition – Bus description (devices, register maps, comms params).

  • publishers – Publishers that receive emitted Measurement/Command data.

  • **kwargs – Default tags applied to every emitted Measurement/Command. Pass dataset_rid="<rid>" to auto-create a NominalCorePublisher (uses the on-disk ‘default’ Nominal credential).

Attributes

background_interval

Seconds between background daemon iterations (0 = no wait).

channel_names

Return an insertion-ordered snapshot of all published channel names.

Methods

add_background_daemon_function

Append method to the daemon's call list.

add_publisher

Register a publisher to receive this instrument's Measurement/Command data.

close

Close the underlying driver and stop the daemon.

define_background_daemon

Replace all daemon functions with a single method (called with the given args).

get_channel

Return the most recent length samples for channel_name from the in-memory buffer.

get_single_channel_value

Return the most recent sample for channel_name from the in-memory buffer.

open

Open the underlying I2C-adapter driver.

publish

Fan data out to every configured publisher; kwargs pass through.

query

Send a batch command (OR of its enum members) to peripheral and read the response.

read

Read a register (or one of its named fields) on peripheral.

read_raw

Read length bytes from the 7-bit I2C address and decode as an integer.

reset_reg

Write a register's defined default value back to hardware (initialization/recovery).

start

Start the background daemon thread.

stop

Signal the background daemon to stop and join it.

write

Write a register (or one of its named fields) on peripheral.

write_raw

Write data to the 7-bit I2C address.

write_read_raw

Write-then-read without an intermediate I2C STOP (uses repeated START); decode as integer.

write_then_read_raw

Write-then-read with an I2C STOP between operations (required by devices that need STOP to process input).