Configuration

I2C.__init__(id=None, driver=None, freq=400000, auto_init=True)

Constructor for the Quanser i2cpy.I2C class.

Parameters
  • id (Union[string,int,None]) – An integer representing the bus number, which identifiers the I2C port used, or a string containing the path to the I2C device, such as “/dev/i2c-0”. If this parameter is not specified then bus number 0 is used.

  • driver (string) – Ignored. This parameter is only included for compatibility with the PyPi i2cpy library.

  • freq (int) – An integer representing the baud rate in Hz. The default is 400000 Hz.

  • auto_init (boolean) – A boolean indicating whether to call init() from the constructor. The default is True.

Raises

StreamError – If auto_init is True and initialization fails. A suitable error message may be retrieved using get_error_message.

Example

>>> from quanser.communications.i2cpy import I2C
>>>
>>> i2c = I2C()
>>> try:
>>>     ...
>>> finally:
>>>     i2c.deinit()
I2C.init()

Initializes the I2C bus.

Raises

StreamError – Raised due to an error in the underlying Quanser Stream API. A suitable error message may be retrieved using get_error_message.

Example

>>> from quanser.communications.i2cpy import I2C
>>>
>>> i2c = I2C(auto_init=False)
>>> try:
>>>     i2c.init()
>>>     ...
>>> finally:
>>>     i2c.deinit()
I2C.deinit()

Closes the I2C bus.

Raises

StreamError – Raised due to an error in the underlying Quanser Stream API. A suitable error message may be retrieved using get_error_message.

Example

>>> from quanser.communications.i2cpy import I2C
>>>
>>> i2c = I2C(auto_init=False)
>>> try:
>>>     i2c.init()
>>>     ...
>>> finally:
>>>     i2c.deinit()