pylab_ml.misc.registermaster.RegisterMaster

class RegisterMaster(logger=None, filename=None, interface=None, instname='regs', read_mod_write=False)[source]

Bases: mqtt_deviceattributes

Returns a container object for registers imported from registermaster.

filename: name of registermaster (excel file), default from ENV:registermaster atomic: enables read-modify-write behavoiur of bit-slices

(reset: False)

interface: hardware object for STI/BiPhase protocol

__init__(logger=None, filename=None, interface=None, instname='regs', read_mod_write=False)[source]

Initialize a RegisterMaster instance, which serves as a container for registers imported from a register master excel file. The initialization process includes setting up attributes for caching, debugging, hardware interface, protocol, atomic operations, bank management, and MQTT publishing.

Parameters:
  • logger (Logger, optional) – A Logger instance for logging messages (default is None, which creates a new Logger).

  • filename (str, optional) – The name of the register master excel file (default is None, which uses the environment variable “registermaster”).

  • interface (object, optional) – The hardware interface object for STI/BiPhase protocol (default is None).

  • instname (str, optional) – The instance name for the RegisterMaster (default is “regs”).

  • read_mod_write (bool, optional) – Enables read-modify-write behavior for bit-slices (default is False).

Methods

__init__([logger, filename, interface, ...])

Initialize a RegisterMaster instance, which serves as a container for registers imported from a register master excel file.

apply_configuration(data)

Call from the Plugin if the modul placed in the hardwaresetups.

close()

find(addr)

Find the name of a register based on its address, depending on the protocol type being used.

handle_exception(msg[, typ, name])

Handle exceptions by logging an error message using the logger instance, and optionally raising a specified exception type with the provided message.

init()

Initialize the RegisterMaster instance by loading the register definitions from the specified register master excel file, building the register database, and creating Register objects for each register defined in the database.

mqtt_add(client, instrument[, liste, qos])

Add the instrument to mqtt.

mqtt_disconnect()

Remove the instrument from mqtt.

publish(topic, value)

Publish topic as type='cmd' with payload=value.

publish_get(function_name, value)

Publish function_name as type='get' with paylad=value.

publish_set(function_name, value)

Publish function_name as type='set' with paylad=value.

readreg(adr[, bank, compare, onlycheck, ...])

Read Register with selected protocol.

reset()

Reset the RegisterMaster instance by resetting the protocol and clearing the cache for all registers.

reset_internal()

Reset the internal state of the RegisterMaster instance by resetting the protocol's internal state and clearing the cache for all registers.

reset_regs([default, force])

Reset the slices to the reset value

set_bank(adr)

Set the bank from a giving adr and recalculate adr.

set_configuration_values(data)

Only empty dummy function.

writereg(adr, dat[, bank])

Write Register with selected protocol.

Attributes

command

mqtt_enable

mqtt_list

mqtt_status

Getter for the mqtt_status.

use

Get the current protocol type.

apply_configuration(data)[source]

Call from the Plugin if the modul placed in the hardwaresetups.

Parameters:

data (dict) – A dictionary containing configuration values to be applied to the RegisterMaster instance, such as the filename.

Return type:

None.

find(addr)[source]

Find the name of a register based on its address, depending on the protocol type being used.

Parameters:

addr (int) – The address of the register to be found.

Returns:

The name of the register if found, or None if no register with the specified address exists.

Return type:

str or None

handle_exception(msg, typ=None, name=None)[source]

Handle exceptions by logging an error message using the logger instance, and optionally raising a specified exception type with the provided message.

Parameters:
  • msg (str) – The error message to be logged and potentially included in the raised exception.

  • typ (Exception class, optional) – The type of exception to be raised. If None, no exception is raised.

  • name (str, optional) – The name associated with the error message.

Return type:

None.

init()[source]

Initialize the RegisterMaster instance by loading the register definitions from the specified register master excel file, building the register database, and creating Register objects for each register defined in the database.

json = <module 'json' from '/home/runner/miniconda3/envs/test/lib/python3.9/json/__init__.py'>
mqtt_add(client, instrument, liste='#', qos=0)

Add the instrument to mqtt. Calling from base_instrument, after the instrument (device) has been create. Normally you have not to use this function, only base_instrument use it.

Parameters:
  • client (mqtt_init) – The MQTT client instance to which the instrument should be added.

  • instrument (object) – The instrument to be added to the MQTT client.

  • liste (list or str) – A list of attributes for which MQTT messages should be sent. If set to “#”, all attributes will be included (default: “#”).

  • qos (int) – The Quality of Service level for MQTT messages (default: 0).

Return type:

None

mqtt_disconnect()

Remove the instrument from mqtt. Calling from base_instrument, if the instrument are closing. Normally you have not to use this function, only base_instrument use it.

property mqtt_status

Getter for the mqtt_status.

publish(topic, value)

Publish topic as type=’cmd’ with payload=value.

Parameters:
  • topic (str) – The name of the topic to publish.

  • value (any) – The value to be published.

Return type:

None

publish_get(function_name, value)

Publish function_name as type=’get’ with paylad=value.

Parameters:
  • function_name (str) – The name of the function to be published as a ‘get’ command.

  • value (any) – The value to be published as the payload of the ‘get’ command.

Return type:

None

publish_set(function_name, value)

Publish function_name as type=’set’ with paylad=value.

Parameters:
  • function_name (str) – The name of the function to be published as a ‘set’ command.

  • value (any) – The value to be published as the payload of the ‘set’ command.

Return type:

None

readreg(adr, bank=None, compare=None, onlycheck=True, tolerance=0, mask=None)[source]

Read Register with selected protocol.

Parameters:
  • adr (int or str or list) – The address or addresses of the register(s) to read.

  • bank (int, optional) – The bank address, if applicable.

  • compare (int or list, optional) – The value(s) to compare against, if any.

  • onlycheck (bool, optional) – If True, only perform the check without returning the value.

  • tolerance (int, optional) – The tolerance for the comparison.

  • mask (int, optional) – The mask to apply to the value before comparison.

Returns:

The result of the read operation, which can be an integer value, a list of values, or a tuple containing the comparison result and the value, depending on the parameters provided.

Return type:

int or list or tuple

reset()[source]

Reset the RegisterMaster instance by resetting the protocol and clearing the cache for all registers.

reset_internal()[source]

Reset the internal state of the RegisterMaster instance by resetting the protocol’s internal state and clearing the cache for all registers.

reset_regs(default=None, force=False)[source]

Reset the slices to the reset value

Parameters:
  • default (int, optional) – The value to set the register to. If None, default values 0 will be used.

  • force (bool, optional) – False -> Only a writable slice sees a reset. True -> Readable and writable slice sees a reset.

Return type:

None.

set_bank(adr)[source]

Set the bank from a giving adr and recalculate adr.

Parameters:

adr (int) – address.

Returns:

adr – address without bank.

Return type:

int

set_configuration_values(data)[source]

Only empty dummy function.

Parameters:

data (dict) – A dictionary containing configuration values to be set for the RegisterMaster instance.

Return type:

None.

property use

Get the current protocol type.

eg. self.regs.use returns “tin” or “spi” or “biphase” depending on the protocol type being used.

Returns:

The current protocol type.

Return type:

str

writereg(adr, dat, bank=None)[source]

Write Register with selected protocol.

Parameters:
  • adr (int or str or list) – The address or addresses of the register(s) to write to.

  • dat (int or list) – The data to write to the register(s).

  • bank (int, optional) – The bank address. If None, the current bank is used.

Return type:

None.