roboglia.base.BaseRegister¶
-
class
BaseRegister
(name='REGISTER', device=None, address=0, clone=None, size=1, minim=0, maxim=None, access='R', sync=False, word=False, bulk=True, order='LH', default=0, **kwargs)[source]¶ Bases:
object
A minimal representation of a device register.
- Parameters
name (str) – The name of the register
device (BaseDevice or subclass) – The device where the register is attached to
address (int (typpically but some devices might use other addressing)) – The register address
size (int) – The register size in bytes; defaults to 1
minim (int) – Minimum value represented in register in internal format; defaults to 0
maxim (int) – Maximum value represented in register; defaults to 2^size - 1. The setter method for internal value will check that the desired value is within the [min, max] and trim it accordingly
access (str) – Read (‘R’) or read-write (‘RW’); default ‘R’
clone (BaseRegister or subclass or
None
) –Indicates if the register is a clone; this value provides the reference to the register object that acts as the main register in interation with the communication bus. This allows you to define multiple represtnations of the same physical register (at a given address) with the purpose of having different external representations. For example:
you can have a position register that can provide the external value in degrees or radians,
a velocity register that can provide the external value in degrees per second, radians per second or rotations per minute,
a byte register that reads 8 inputs and mask them each as a
BoolRegister
with a different bit mask
In the device definition YAML file use
True
to indicate if a register is a clone. The device constructor will replace the reference of the main register with the same address in the constructor of this register.sync (bool) –
True
if the register will be updated from the real device using a sync loop. If sync isFalse
access to the register through the value property will invoke reading / writing to the real register; defaultFalse
word (bool) – Indicates that the register is a
word
register (16 bits) instead of a usual 8 bits. Some I2C and SPI devices use 16bit registers and need to use separate access functions to read them as opposed to the 8 bit registers. Default isFalse
which effectively makes it an 8 bit registerorder (
LH
orHL
) – Applicable only for registers with size > 1 that represent a value over successive internal registers, but for convenience are groupped as one single register with size 2 (or higher).LH
means low-high and indicates the bytes in the registry are organized starting with the low byte first.HL
indicates that the registers are with the high byte first. Technically theread
andwrite
functions always read the bytes in the order they are stored in the device and if the register is marked asHL
the list is reversed before being returned to the requester or processed as a number in case thebulk
isFalse
. Default isLH
.default (int) – The default value for the register; implicit 0
-
__init__
(name='REGISTER', device=None, address=0, clone=None, size=1, minim=0, maxim=None, access='R', sync=False, word=False, bulk=True, order='LH', default=0, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
name
¶ Register’s name.
-
property
device
¶ The device the register belongs to.
-
property
address
¶ The register’s address in the device.
-
property
clone
¶ Indicates the register is a clone of another.
-
property
size
¶ The regster’s size in Bytes.
-
property
minim
¶ The register’s minimum value in internal format.
-
property
maxim
¶ The register’s maximum value in internal format.
-
property
range
¶ Tuple with (minim, maxim) values in internal format.
-
property
min_ext
¶ The register’s minimum value in external format.
-
property
max_ext
¶ The register’s maximum value in external format.
-
property
range_ext
¶ Tuple with (minim, maxim) values in external format.
-
property
access
¶ Register’s access mode.
-
property
sync
¶ Register is subject to a sync loop update.
-
property
word
¶ Indicates if the register is an 16 bit register (
True
) or an 8 bit register.
-
property
order
¶ Indicates the order of the data representartion; low-high (LH) or high-low (HL)
-
property
default
¶ The register’s default value in internal format.
-
property
int_value
¶ Internal value of register, if a clone return the value of the main register.
-
value_to_external
(value)[source]¶ Converts the presented value to external format according to register’s settings. This method should be overridden by subclasses in case they have specific conversions to do.
- Parameters
value (int) – A value (internal representation) to be converted.
- Returns
For
BaseRegister
it returns the same value unchanged.- Return type
int
-
value_to_internal
(value)[source]¶ Converts the presented value to internal format according to register’s settings. This method should be overridden by subclasses in case they have specific conversions to do.
- Parameters
value (int) – A value (external representation) to be converted.
- Returns
For
BaseRegister
it returns the same value unchanged.- Return type
int
-
property
value
¶ Provides the value of the register in external format. If the register is not marked for
sync
then it requests the device to perform aread
in order to refresh the content of the register.- Returns
The value of the register in the external format. It invokes
value_to_external()
which can be overridden by subclasses to provide different representations of the register’s value (hence theany
return type).- Return type
any
-
write
()[source]¶ Performs the actual writing of the internal value of the register to the device. Calls the device’s method to write the value of register.