roboglia.base.BaseBus¶
-
class
BaseBus
(name='BUS', robot=None, port='', auto=True)[source]¶ Bases:
object
A base abstract class for handling an arbitrary bus.
You will normally subclass
BaseBus
and define particular functionality specific to the bus by implementing the methods of theBaseBus
. This class only stores the name of the bus and the access to the physical object. Your subclass can add additional attributes and methods to deal with the particularities of the real bus represented.- Parameters
name (str) – The name of the bus
robot (BaseRobot) – A reference to the robot using the bus
port (any) – An identification for the physical bus access. Some busses have string description like
/dev/ttySC0
while others could be just integers (like in the case of I2C or SPI buses)auto (Bool) – If
True
the bus will be opened when the robot is started by callingBaseRobot.start()
. IfFalse
the bus will be left closed during robot initialization and needs to be opened by the programmer.Raises – KeyError: if
port
not supplied
-
__init__
(name='BUS', robot=None, port='', auto=True)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
name
¶ (read-only) the bus name.
-
property
robot
¶ The robot that owns the bus.
-
property
port
¶ (read-only) the bus port.
-
property
auto_open
¶ Indicates if the bus should be opened by the robot when initializing.
-
close
()[source]¶ Closes the actual physical bus. Must be overridden by the subclass, but the implementation in the subclass should first check for the return from this method before actually closing the bus as dependent object on this bus might be affected:
def close(self): if super().close() ... do the close activities # optional; the handling in the ``BaseBus.close()`` will # issue error message to log else: logger.<level>('message')
-
__repr__
()[source]¶ Returns a representation of a BaseBus that includes the name of the class, the port and the status (open or closed).
-
property
is_open
¶ Returns True or False if the bus is open. Must be overridden by the subclass.
-
read
(reg)[source]¶ Reads one register information from the bus. Must be overridden.
- Parameters
reg (BaseRegister or subclass) – The register object that needs to be read. Keep in mind that the register object also contains a reference to the device in the
device
attribute and it is up to the subclass to determine the way the information must be processed before providing it to the caller.- Returns
Typically it would return an
int
that will have to be handled by the caller.- Return type
int
-
write
(reg, val)[source]¶ Writes one register information from the bus. Must be overridden.
- Parameters
reg (BaseRegister or subclass) – The register object that needs to be written. Keep in mind that the register object also contains a reference to the device in the
device
attribute and it is up to the subclass to determine the way the information must be processed before providing it actual device.val (int) – The value needed to the written to the device.