roboglia.base.RegisterWithMapping

class RegisterWithMapping(mask=None, mapping={}, **kwargs)[source]

Bases: roboglia.base.register.BaseRegister

A register that can specify a 1:1 mapping of internal values to external values.

Parameters
  • mask (int or None) – Optional, can indicate that only certain bits from the value of the register are used in the mapping. Ex. using 0b11110000 as a mask indicates that only the most significant 4 bits of the internal value are significant for the conversion to external values.

  • mapping (dict) – A dictionary that provides {internal : external} mapping. Internally the register will construct a reverse mapping that is used in converting external values to internal ones.

__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 a read 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 the any 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.

__init__(mask=None, mapping={}, **kwargs)[source]

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

property mapping

external}.

Type

The mapping {internal

property inv_mapping

internal}.

Type

The mapping {external

property mask

The bit mask is any.

value_to_external(value)[source]

Converts the internal value of the register to external format. Applies mask on the internal value if one specified before checking the mapping. If no entry is found returns 0.

value_to_internal(value)[source]

Converts the external value into an internal value using the inverse mapping dictionary. If no entry is found logs a warning and returns the already existing value in the int_value. If mask was specified it only affects the bits specified in the mask.