roboglia.base.RegisterWithConversion¶
-
class
RegisterWithConversion
(factor=1.0, offset=0, sign_bit=None, **kwargs)[source]¶ Bases:
roboglia.base.register.BaseRegister
A register with an external representation that is produced by using a linear transformation:
external = (internal - offset) / factor internal = external * factor + offset
The
RegisterWithConversion
inherits all the paramters fromBaseRegister
and in addition includes the following specific parameters that are used when converting the data from internal to external format.- Parameters
factor (float) – A factor used for conversion. Defaults to 1.0.
offset (int) – The offset for the conversion; defaults to 0 (int)
sign_bit (int or None) – If a number is given it means that the register is “signed” and that bit represents the sign. Bits are numbered from 1 meaning that if
sign_bit
is 1 the less significant bit is used and if we have a 2 bytes register the most significant bit would be 16. The convention is that numbers having 0 in this bit are positive and the ones having 1 are negative numbers.Raises – KeyError: if any of the mandatory fields are not provided ValueError: if value provided are wrong or the wrong type
-
__init__
(factor=1.0, offset=0, sign_bit=None, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
factor
¶ The conversion factor for external value.
-
property
offset
¶ The offset for external value.
-
property
sign_bit
¶ The sign bit, if any.
-
value_to_external
(value)[source]¶ The external representation of the register’s value.
Performs the translation of the value according to:
external = (internal - offset) / factor
-
value_to_internal
(value)[source]¶ The internal representation of the register’s value.
Performs the translation of the value according to:
internal = external * factor + offset
The resulting value is rounded to produce an integer suitable to be stored in the register.
-
__str__
()¶ Representation of the register [name]: value.
-
property
access
¶ Register’s access mode.
-
property
address
¶ The register’s address in the device.
-
property
clone
¶ Indicates the register is a clone of another.
-
property
default
¶ The register’s default value in internal format.
-
property
device
¶ The device the register belongs to.
-
property
int_value
¶ Internal value of register, if a clone return the value of the main register.
-
property
max_ext
¶ The register’s maximum value in external format.
-
property
maxim
¶ The register’s maximum value in internal format.
-
property
min_ext
¶ The register’s minimum value in external format.
-
property
minim
¶ The register’s minimum value in internal format.
-
property
name
¶ Register’s name.
-
property
order
¶ Indicates the order of the data representartion; low-high (LH) or high-low (HL)
-
property
range
¶ Tuple with (minim, maxim) values in internal format.
-
property
range_ext
¶ Tuple with (minim, maxim) values in external format.
-
read
()¶ Performs the actual reading of the internal value of the register from the device. Calls the device’s method to read the value of register.
-
property
size
¶ The regster’s size in Bytes.
-
property
sync
¶ Register is subject to a sync loop update.
-
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
-
property
word
¶ Indicates if the register is an 16 bit register (
True
) or an 8 bit register.
-
write
()¶ 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.