Import
Methods
| Method | Description |
|---|---|
config() | Configure I2C bus parameters |
scan() | Scan bus for connected devices |
read() | Read bytes from a device |
write() | Write bytes to a device |
write_read() | Write then read in a single transaction (repeated start) |
get_config() | Get raw net configuration |
Method Reference
Net.get(name, type=NetType.I2C)
Get an I2C net by name.
| Parameter | Type | Description |
|---|---|---|
name | str | Name of the I2C net |
type | NetType | Must be NetType.I2C |
config(frequency_hz, pull_ups)
Configure I2C bus parameters. Only explicitly-provided parameters are changed; omitted parameters retain their stored values.
| Parameter | Type | Description |
|---|---|---|
frequency_hz | int or None | Clock frequency in Hz (e.g., 100000, 400000). None keeps stored value |
pull_ups | bool or None | Enable/disable internal pull-ups (Aardvark only). None keeps stored value |
scan(start_addr, end_addr)
Scan the I2C bus for connected devices.
| Parameter | Type | Description |
|---|---|---|
start_addr | int | First 7-bit address to probe (default 0x08) |
end_addr | int | Last 7-bit address to probe (default 0x77) |
list[int] - List of 7-bit addresses that responded with ACK
read(address, num_bytes, output_format, overrides)
Read bytes from an I2C device.
| Parameter | Type | Description |
|---|---|---|
address | int | 7-bit device address (0x00-0x7F) |
num_bytes | int | Number of bytes to read |
output_format | str | "list" (default), "hex", "bytes", or "json" |
overrides | dict or None | Per-call config overrides (e.g., {"frequency_hz": 400000}) |
list[int] - Received bytes as integers (when output_format="list")
write(address, data, overrides)
Write bytes to an I2C device.
| Parameter | Type | Description |
|---|---|---|
address | int | 7-bit device address (0x00-0x7F) |
data | list[int] | Bytes to write |
overrides | dict or None | Per-call config overrides (e.g., {"frequency_hz": 400000}) |
write_read(address, data, num_bytes, output_format, overrides)
Write then read in a single I2C transaction using a repeated start condition. This is the standard pattern for reading device registers.
| Parameter | Type | Description |
|---|---|---|
address | int | 7-bit device address (0x00-0x7F) |
data | list[int] | Bytes to write before reading (typically a register address) |
num_bytes | int | Number of bytes to read after writing |
output_format | str | "list" (default), "hex", "bytes", or "json" |
overrides | dict or None | Per-call config overrides (e.g., {"frequency_hz": 400000}) |
list[int] - Received bytes as integers (when output_format="list")
get_config()
Get the raw net configuration dictionary.
dict - Full net configuration including name, role, instrument, and params
Output Formats
Theoutput_format parameter on read() and write_read() controls how data is returned:
| Format | Return Type | Example |
|---|---|---|
"list" | list[int] | [72, 118, 153] |
"hex" | str | "48 76 99" |
"bytes" | str | "72 118 153" |
"json" | dict | {"data": [72, 118, 153]} |
Examples
Basic Device Read
Register Read/Write
Bus Configuration
Multi-Device Setup
Per-Call Configuration Override
Supported Hardware
| Adapter | Description |
|---|---|
| LabJack T7 | Uses GPIO pins (FIO/EIO) for SDA and SCL |
| Aardvark I2C/SPI | Dedicated USB I2C adapter with pull-up support |
Notes
- Net must be configured as
NetType.I2C - Addresses are 7-bit format (
0x00-0x7F), not left-shifted pull_upsonly works on the Aardvark adapter; ignored on LabJack T7write_read()uses a repeated start condition for atomic register reads- Default scan range (
0x08-0x77) skips reserved addresses - Configuration changes persist to
saved_nets.jsonfor subsequent commands - LabJack T7 runs at approximately 450 kHz regardless of requested frequency due to hardware limitations

