Skip to content

senxor.regmap

Register system for the senxor.

SenxorFieldsManager(regmap)

Bases: Fields

The field system for the senxor.

Attributes:

Name Type Description
regmap SenxorRegistersManager

The register system for the senxor.

fields dict[FieldName, Field]

The dictionary of field instances by name.

cache dict[FieldName, int | None]

The cache of the fields values.

cache_display dict[FieldName, str | int | float | None]

The cache of the fields display values.

Examples:

  1. Iterate over the fields:
>>> fieldmap = SenxorFieldsManager(regmap)
>>> for field in fieldmap:
...     print(field.name, field.address)
  1. Use subscript notation to get a field instance:
>>> fieldmap["MCU_TYPE"]
  1. Check if a field exists:
>>> "MCU_TYPE" in fieldmap
  1. Use the cache to get the cached field value:
>>> fieldmap.cache
{SENXOR_TYPE: 1, MODULE_TYPE: 19, ...}
  1. Use the cache_display to get the cached field display value:
>>> fieldmap.cache_display
{SENXOR_TYPE: "MI0801", MODULE_TYPE: "MI0802M5S", ...}

regmap = regmap instance-attribute

fields = {(field.name): (field(self)) for field in (self.__fields__)} instance-attribute

cache property

cache_display property

set_fields_changed_callback(callback)

get_field(name)

Get a field instance by name.

get_fields_by_addr(addr)

Get the fields by register address.

read_field(name)

Read a field value from the senxor.

set_field(name, value, *, force=False)

Set a field value on the senxor.

SenxorRegistersManager(interface)

Bases: Registers

The register system for the senxor.

Attributes:

Name Type Description
interface ISenxorInterface

The interface of the senxor.

registers dict[int, Register]

The dictionary of registers instance by address.

fieldmap SenxorFieldsManager

The field system for the senxor.

cache dict[int, int | None]

The cache of the registers values.

Examples:

  1. Iterate over the registers:
>>> regs = SenxorRegistersManager(interface)
>>> for reg in regs:
...     print(reg.name, reg.address)
  1. Use subscript notation to get a register instance:
>>> regs = SenxorRegistersManager(interface)
>>> regs["MCU_RESET"]
>>> regs[0x00]
  1. Check if a register exists:
>>> "MCU_RESET" in regs
>>> 0x00 in regs
  1. Use the cache to get the cached register value:
>>> regs.cache
{0x00: 0x00, 0x01: 0x01, ...}
  1. Refresh the cache of all registers:
>>> regs.refresh_all()
>>> regs.cache
{0x00: 0x00, 0x01: 0x01, ...}
Notes

Each register operation should be performed through this class to ensure logging, cache updating and error handling.

interface = interface instance-attribute

registers = {(register.address): (register(self)) for register in (self.__regs__)} instance-attribute

fieldmap = SenxorFieldsManager(self) instance-attribute

cache property

refresh_all()

Refresh the cache of all registers and fields.

get_reg(name_or_addr)

Get a register instance by name or address.

read_reg(addr)

Read a register value from the senxor.

write_reg(addr, value)

Write a value to a register.

read_regs(addrs)

Read the values from multiple registers at once.

write_regs(regs)

Write the values to multiple registers at once.