i2c_communicator Module
Communicator for I2C Communication
- class CommunicatorCommon.i2c_communicator.I2CCommunicator(bus_id: int = 1)
Bases:
objectA class to handle I2C communication.
- bus_id
The I2C bus ID.
- Type:
int
- __init__(bus_id: int = 1) None
Initialize the I2CCommunicator.
- Parameters:
bus_id (int) – The I2C bus ID. Default is 1.
- send_msg(address: int, msg: bytes) None
Send a message via I2C.
- Parameters:
address (int) – The I2C device address.
msg (bytes) – The message to send.
- Raises:
Exception – If there is an I2C communication failure.
- receive_msg(address: int, length: int) bytes
Receive data of the specified length via I2C.
- Parameters:
address (int) – The I2C device address.
length (int) – The length of the expected received data.
- Returns:
The received data.
- Return type:
bytes
- Raises:
Exception – If there is an I2C communication failure.