smbus3 Documentation¶
smbus3 - A drop-in replacement for smbus2/smbus-cffi/smbus-python
- class smbus3.SMBus(bus=None, force=False)¶
The main SMBus class.
- __init__(bus=None, force=False)¶
Initialize and (optionally) open an i2c bus connection.
- open(bus)¶
Open a given i2c bus.
- close()¶
Close the i2c connection.
- Raises:
OSError – if the file descriptor in self.fd does not exist
- Return type:
None
- enable_pec(enable=True)¶
Enable/Disable PEC (Packet Error Checking) - SMBus 1.1 and later
- property pec¶
Get and set SMBus PEC. 0 = disabled (default), 1 = enabled.
- enable_tenbit(enable=True)¶
Enable 10 bit addresses if they are supported.
- property tenbit¶
Get and set 10bit addressing. 0 = disabled (default), 1 = enabled.
- set_timeout(timeout)¶
Set the timeout in units of 10ms.
- Parameters:
timeout (int) – timeout as positive int in units of 10ms.
- Return type:
None
- property timeout¶
Get and set I2C timeout in units of 10ms.
- set_retries(retries)¶
Set the retries.
- Parameters:
retries (int) – retries as positive int.
- Return type:
None
- property retries¶
Get and set I2C retries.
- _set_address(address, force=None)¶
Set i2c slave address to use for subsequent calls. Private.
- write_quick(i2c_addr, force=None)¶
Perform quick transaction. Throws IOError if unsuccessful.
- read_byte(i2c_addr, force=None)¶
Read a single byte from a device.
- write_byte(i2c_addr, value, force=None)¶
Write a single byte to a device.
- read_byte_data(i2c_addr, register, force=None)¶
Read a single byte from a designated register.
- write_byte_data(i2c_addr, register, value, force=None)¶
Write a byte to a given register.
- read_word_data(i2c_addr, register, force=None)¶
Read a single word (2 bytes) from a given register.
- write_word_data(i2c_addr, register, value, force=None)¶
Write a single word (2 bytes) to a given register.
- process_call(i2c_addr, register, value, force=None)¶
Executes a SMBus Process Call, sending a 16-bit value and receiving a 16-bit response
- read_block_data(i2c_addr, register, force=None)¶
Read a block of up to 32-bytes from a given register.
- write_block_data(i2c_addr, register, data, force=None)¶
Write a block of byte data to a given register.
- Parameters:
- Raises:
ValueError – if length of data in bytes is > I2C_SMBUS_BLOCK_MAX
- Return type:
None
- block_process_call(i2c_addr, register, data, force=None)¶
Executes a SMBus Block Process Call, sending a variable-size data block and receiving another variable-size response
- Parameters:
- Raises:
ValueError – if length of data in bytes is > I2C_SMBUS_BLOCK_MAX
- Returns:
List of bytes
- Return type:
- read_i2c_block_data(i2c_addr, register, length, force=None)¶
Read a block of byte data from a given register.
- write_i2c_block_data(i2c_addr, register, data, force=None)¶
Write a block of byte data to a given register.
- Parameters:
- Raises:
ValueError – if length of data in bytes is > I2C_SMBUS_BLOCK_MAX
- Return type:
None
- i2c_rdwr(*i2c_msgs)¶
Combine a series of i2c read and write operations in a single transaction (with repeated start bits but no stop bits in between).
This method takes i2c_msg instances as input, which must be created first with
i2c_msg.read()ori2c_msg.write().- Parameters:
i2c_msgs (i2c_msg) – One or more i2c_msg class instances.
- Return type:
None
- i2c_rd(i2c_addr, length, flags=1)¶
Perform a single i2c read operation, given an i2c_addr and length.
- class smbus3.i2c_msg¶
As defined in
i2c.h.- Variables:
addr (c_uint16) – i2c address
flags (c_uint16) – bit flags
len (c_uint16) – length
buf (POINTER(c_char)) – data buffer
- __iter__()¶
Iterator / Generator
- Returns:
iterates over
buf- Return type:
generatorwhich returns int values
- __repr__()¶
Return repr(self).
- __str__()¶
Return a string, discarding non decodable bytes.
- Returns:
string of i2c_msg.__bytes__()
- Return type:
- static read(address, length, flags=1)¶
Prepares an i2c read transaction.
- class smbus3.I2cFunc(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
These flags identify the operations supported by an I2C/SMBus device.
You can test these flags on your smbus.funcs
- I2C = 1¶
- ADDR_10BIT = 2¶
- PROTOCOL_MANGLING = 4¶
- SMBUS_PEC = 8¶
- NOSTART = 16¶
- SLAVE = 32¶
- SMBUS_BLOCK_PROC_CALL = 32768¶
- SMBUS_QUICK = 65536¶
- SMBUS_READ_BYTE = 131072¶
- SMBUS_WRITE_BYTE = 262144¶
- SMBUS_READ_BYTE_DATA = 524288¶
- SMBUS_WRITE_BYTE_DATA = 1048576¶
- SMBUS_READ_WORD_DATA = 2097152¶
- SMBUS_WRITE_WORD_DATA = 4194304¶
- SMBUS_PROC_CALL = 8388608¶
- SMBUS_READ_BLOCK_DATA = 16777216¶
- SMBUS_WRITE_BLOCK_DATA = 33554432¶
- SMBUS_READ_I2C_BLOCK = 67108864¶
- SMBUS_WRITE_I2C_BLOCK = 134217728¶
- SMBUS_HOST_NOTIFY = 268435456¶
- SMBUS_BYTE = 393216¶
- SMBUS_BYTE_DATA = 1572864¶
- SMBUS_WORD_DATA = 6291456¶
- SMBUS_BLOCK_DATA = 50331648¶
- SMBUS_I2C_BLOCK = 201326592¶
- SMBUS_EMUL = 251592712¶