roboglia.i2c.I2CDevice¶
-
class
I2CDevice(**kwargs)[source]¶ Bases:
roboglia.base.device.BaseDeviceImplements a representation of an I2C device.
It only adds an override for the
get_model_path()in order to localize the device definitions in thedevicedirectory of thei2cmodule and the methodopen()that will attempt to read all the registers not marked assync.-
get_model_path()[source]¶ Builds the path to the .yml documents.
- Returns
- the path to the standard` directory with device
definitions. In this case
devicesin thei2cmodule directory.
- Return type
str
-
__str__()¶ Return str(self).
-
property
bus¶ The bus where the device is connected to.
-
close()¶ Perform device closure.
BaseDeviceimplementation does nothing.
-
default_register()¶ Default register for the device in case is not explicitly provided in the device definition file.
Subclasses of
BaseDevicecan overide the method to derive their own class.BaseDevicesuggests as default registerBaseRegister.
-
property
dev_id¶ The device number.
- Returns
The device number
- Return type
int
-
property
name¶ Device name.
- Returns
The name of the device
- Return type
str
-
open()¶ Performs initialization of the device by reading all registers that are not flagged for
syncreplication and, ifinitparameter provided initializes the indicated registers with the values from theinitparamters.
-
read_register(register)¶ Implements the read of a register using the associated bus. More complex devices should overwrite the method to provide specific functionality.
BaseDevicesimply calls the bus’sreadfunction and returns the value received.
-
register_by_address(address)¶ Returns the register identified by the given address. If the address is not available in the device it will return
None.- Returns
The device at address or
Noneif no register with that address exits.- Return type
BaseDevice or subclass or
None
-
property
registers¶ Device registers as dict.
- Returns
The dictionary of registers with the register name as key.
- Return type
dict
-
write_register(register, value)¶ Implements the write of a register using the associated bus. More complex devices should overwrite the method to provide specific functionality.
BaseDevicesimply calls the bus’swritefunction and returns the value received.
-