roboglia.base.BaseSync

class BaseSync(group=None, registers=[], auto=True, **kwargs)[source]

Bases: roboglia.base.thread.BaseLoop

Base processing for a sync loop.

This class is intended to be subclassed to provide specific functionality. It only parses the common elements that a sync loop would need: the devices (provided by a group) and registers (provided by a list). It will check that the provided devices are on the same bus and that the provided registers exist in all devices.

Note

Please note that this class does not actually perform any sync. Use the subclasses BaseReadSync or BaseWriteSync that implement read or write syncs.

BaseSync inherits the parameters from BaseLoop. In addition it includes the following parameters.

Parameters
  • group (set) – The set with the devices used by sync; normally the robot constructor replaces the name of the group from YAML file with the actual set built earlier in the initialization.

  • registers (list of str) – A list of register names (as strings) used by the sync

  • auto (bool) – If the sync loop should start automatically when the robot starts; defaults to True

Raises

KeyError – if mandatory parameters are not found:

__init__(group=None, registers=[], auto=True, **kwargs)[source]

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

property auto_start

Shows if the sync should be started automatically when the robot starts.

property bus

The bus this sync works with.

property devices

The devices used by the sync.

property register_names

The register names used by the sync.

process_devices()[source]

Processes the provided devices.

The devices are exected as a set in the init_dict. This is normally performed by the robot class when reading the robot definition by replacing the name of the group with the actual content of the group. This method checks that all devices are assigned to the same bus otherwise raises an exception. It returns the single instance of the bus that manages all devices.

process_registers()[source]

Checks that the supplied registers are available in all devices.

get_register_range()[source]

Determines the start address of the range of registers and the whole length. Registers do not need to be order, but be careful that not all communication protocols can support gaps in the bulk read of registers.

start()[source]

Checks that the bus is open, then refreshes the register, sets the sync flag before calling the inherited :py:meth:BaseLoop.`start.

stop()[source]

Before calling the inherited method it unflags the registers for syncing.

atomic()

This method implements the periodic task that needs to be executed. It does not need to check paused or stopped as the run method does this already and the subclasses should make sure that the implementation completes quickly and does not raise any exceptions.

property frequency

Loop frequency.

property name

Returns the name of the thread.

pause()

Requests the thread to pause.

property paused

Indicates the thread was paused.

property period

Loop period = 1 / frequency.

resume()

Requests the thread to resume.

property review

Indicates the amount of time in seconds before the thread will review the actual frequency against the target and take action.

run()

Run method of the thread.

property running

Indicates if the thread is running.

setup()

Thread preparation before running. Subclasses should override

property started

Indicates if the thread was started.

property stopped

Indicates if the thread was stopped.

teardown()

Thread cleanup. Subclasses should override.

property warning

Control the warning level for the warning message, the setter is smart: if the value is larger than 2 it will assume it is a percentage and divied it by 100 and ignore if the number is higher than 110. The over 100 is available for testing purposes.