roboglia.i2c.I2CDevice

class I2CDevice(**kwargs)[source]

Bases: roboglia.base.device.BaseDevice

Implements a representation of an I2C device.

It only adds an override for the get_model_path() in order to localize the device definitions in the device directory of the i2c module and the method open() that will attempt to read all the registers not marked as sync.

__init__(**kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

get_model_path()[source]

Builds the path to the .yml documents.

Returns

the path to the standard` directory with device

definitions. In this case devices in the i2c module directory.

Return type

str

__str__()

Return str(self).

property bus

The bus where the device is connected to.

Returns

The bus object using this device.

Return type

BaseBus or SharedBus or subclass

close()

Perform device closure. BaseDevice implementation does nothing.

default_register()

Default register for the device in case is not explicitly provided in the device definition file.

Subclasses of BaseDevice can overide the method to derive their own class.

BaseDevice suggests as default register BaseRegister.

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 sync replication and, if init parameter provided initializes the indicated registers with the values from the init paramters.

read_register(register)

Implements the read of a register using the associated bus. More complex devices should overwrite the method to provide specific functionality.

BaseDevice simply calls the bus’s read function 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 None if 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.

BaseDevice simply calls the bus’s write function and returns the value received.