j5.backends package

Module contents

Backend classes.

class j5.backends.Backend[source]

Bases: object

The base class for a backend.

A backend is an implementation of a specific board for an environment.

It can hold data about the actual board it is controlling. There should be a ratio of one instance of a Backend to one instance of a Board. The Backend object should not hold any references to the Board, instead having it’s methods executed by the code for the individual Board.

A Backend usually also implements a number of ComponentInterfaces which thus allow a physical component to be controlled by the abstract Component representation.


Type of board this backend implements.

classmethod discover() → Set[Board][source]

Discover boards that this backend can control.


The firmware version of the board.

class j5.backends.BackendMeta[source]

Bases: abc.ABCMeta

The metaclass for a backend.

Ensures that the backend implements the correct interfaces when instantiated. It does this by checking that the class inherits from the interface classes defined on the Components in backend.board.supported_components.

exception j5.backends.CommunicationError[source]

Bases: Exception

A communication error occurred.

This error is thrown when there is an error communicating with a board, if a more specific exception is available, then that may be thrown instead, but it should inherit from this one.

class j5.backends.Environment(name: str)[source]

Bases: object

A collection of backends that can work together.

A number of Backends that we wish to use in a grouping, such as those that all work together in hardware can be added to this group. We can then pass Environments to a Robot object, so that the Robot object can call different methods based on where it is being used.

e.g Hardware Environment

We have n boards of n different types. They are all physical hardware. We create an Environment containing the Backends to control the physical hardware for our boards.

It is later realised that we want to test code without the physical hardware. We can add Console backends to an environment, and instantiate our Robot object with that environment, so that the console is manipulated rather than the hardware.

This allows for a high degree of code reuse and ensures API compatibility in different situations.

get_backend(board: Type[Board]) → Type[j5.backends.backend.Backend][source]

Get the backend for a board.

Parameters:board – board type to fetch a backend for.
Returns:Backend in this environment for the given board.
Raises:NotImplementedError – The environment does not support the board.
get_board_group(board: Type[BoardT]) → j5.boards.board_group.BoardGroup[~BoardT, j5.backends.backend.Backend][BoardT, j5.backends.backend.Backend][source]

Get a board group for the given board type.

Parameters:board – board type to fetch a backend for.
Returns:BoardGroup in this environment for the given board.
Raises:NotImplementedError – The environment does not support the board.
merge(other: j5.backends.environment.Environment) → None[source]

Merge in the board-backend mappings from another environment.

This allows vendors to predefine Environments and API authors can then merge several vendor environments to get the one that they need for their API.

This method will fail if any board is defined in both environments,
as it is unclear which one has the correct mapping.
Parameters:other – environment to merge into this one.
Raises:RuntimeError – a board was implemented in both backends, conflict.
register_backend(backend: Type[j5.backends.backend.Backend]) → None[source]

Register a new backend with this environment.

Parameters:backend – The backend to register in the environment.
Raises:RuntimeError – The backend has already been registered.

The boards that are supported by this environment.

Returns:set of boards that are supported by this environment.