herosdevices.core.bus.i2c

Primitive functions and classes representing I2C connections.

Module Contents

herosdevices.core.bus.i2c.smbus2 = None
class herosdevices.core.bus.i2c.I2CConnection(bus_id: int, keep_alive: bool = True)[source]

A class to manage I2C communication connections via smbus2.

Parameters:
  • bus_id – I2C bus id (e.g. 1 for /dev/i2c-1).

  • keep_alive – if True, keep the bus open between operations.

bus_id
keep_alive = True
connection
property is_open: bool

Return whether the bus is currently open.

Returns:

True if the bus file descriptor is open.

open() None[source]

Open the I2C bus if not already open.

close() None[source]

Close the I2C bus.

operation() collections.abc.Iterator[None][source]

Context manager for I2C operations.

Ensures the bus is open before performing operations and closes it afterward if keep_alive is False.

Yields:

Yields control back to the caller.