# I2CDriverBase

## class I2CDriverBase[source]

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC "(in Python v3.15)")

Vendor I2C-adapter driver contract. Concrete drivers own their transport and lifecycle.

`address` arguments are 7-bit device addresses (the adapter SDK handles
the R/W bit). Drivers translate this contract to the vendor SDK’s master
primitives.

Methods

| [`close`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.close "instro.i2c.I2CDriverBase.close") | Close the adapter handle. |
| --- | --- |
| [`open`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.open "instro.i2c.I2CDriverBase.open") | Open the adapter (typically a USB host adapter) and prepare it for transactions. |
| [`read`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.read "instro.i2c.I2CDriverBase.read") | Read `length` bytes from the 7-bit `address` (master read transaction). |
| [`set_bitrate`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.set_bitrate "instro.i2c.I2CDriverBase.set_bitrate") | Set the master clock rate in kHz. |
| [`set_power_enable`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.set_power_enable "instro.i2c.I2CDriverBase.set_power_enable") | Enable or disable target-power output on the adapter (where supported). |
| [`set_pullups`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.set_pullups "instro.i2c.I2CDriverBase.set_pullups") | Enable or disable the adapter's internal bus pull-ups (typical: ~10 kΩ to VCC). |
| [`write`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.write "instro.i2c.I2CDriverBase.write") | Write `data` to the 7-bit `address` (master write transaction). |
| [`write_read`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.I2CDriverBase.md#instro.i2c.I2CDriverBase.write_read "instro.i2c.I2CDriverBase.write_read") | Write `data` then immediately read `read_len` bytes from `address` using a repeated START. |

### abstractmethod open() → None[source]

Open the adapter (typically a USB host adapter) and prepare it for transactions.

### abstractmethod close() → None[source]

Close the adapter handle. Idempotent.

### abstractmethod read(address: int, length: int) → bytes[source]

Read `length` bytes from the 7-bit `address` (master read transaction).

### abstractmethod write(address: int, data: bytes) → None[source]

Write `data` to the 7-bit `address` (master write transaction).

### abstractmethod write_read( address: int, data: bytes, read_len: int, ) → bytes[source]

Write `data` then immediately read `read_len` bytes from `address` using a repeated START.

Used for register reads: write the register address, then read its
contents without releasing the bus. No STOP is issued between the
write and the read.

### abstractmethod set_bitrate(bitrate: int) → None[source]

Set the master clock rate in kHz. Drivers may snap to the nearest supported rate.

### abstractmethod set_pullups(enable: bool) → None[source]

Enable or disable the adapter’s internal bus pull-ups (typical: ~10 kΩ to VCC).

### abstractmethod set_power_enable(enable: bool) → None[source]

Enable or disable target-power output on the adapter (where supported).
