piripherals.bus module¶
Wrapper classes to abstract bus access.
-
class
piripherals.bus.
Bus
(bus=1)[source]¶ Bases:
object
Abstraction for a data bus, i.e. I2C.
Parameters: bus – something with read and write methods. It does not have such methods, bus is passed to SMBus(bus)
.The
bus
need to have at least the following methodsread_byte_data(addr,reg)
->byte
write_byte_data(addr,reg,byte)
and additionally
read_word_data(addr,reg)
->word
write_word_data(addr,reg,work)
read_i2c_block_data(addr,reg,size)
->[byte,...]
write_i2c_block_data(addr,reg,[byte,...])
If these are not present, it will read/write words and blocks using
read_byte_data
andwrite_byte_data
.The bus usually is an
smbus.SMBus
orsmbus2.SMBus
instance.- https://pypi.python.org/pypi/smbus2/
- https://pypi.python.org/pypi/smbus-cffi/
- https://packages.debian.org/de/stretch/python-smbus
-
device
(addr)[source]¶ Get a Device.
Parameters: addr (int) – device address Returns: device at given address Return type: Device
-
read_block
(addr, reg, n)[source]¶ read a block of bytes.
Parameters: - addr (int) – address of device to read the block from
- reg (int) – base register, first byte of the block
- n (int) – # of bytes to read n<=32
Returns: bytes, that were read
Return type: list of int
-
read_byte
(addr, reg)[source]¶ read a byte.
Parameters: - addr (int) – address of device to read the byte from
- reg (int) – register to be read
Returns: the byte, that was read
Return type: int
-
read_word
(addr, reg)[source]¶ read a word (2 bytes).
Parameters: - addr (int) – address of device to read the word from
- reg (int) – base register, low byte of the word is there, high byte is at reg+1
Returns: the word, that was read
Return type: int
-
write_block
(addr, reg, block)[source]¶ write a block of bytes.
Parameters: - addr (int) – address of device to write the block to
- reg (int) – base register, first byte of the block
- block (list of int) – bytes to be written, len(block)<=32