toio.cube.multi_cubes module¶
- class toio.cube.multi_cubes.MultipleToioCoreCubes(cubes: int | ~typing.List[~toio.device_interface.CubeInfo], names: ~typing.Sequence[str] | None = None, scanner: ~typing.Type[~toio.device_interface.ScannerInterface] = <class 'toio.scanner.ble.UniversalBleScanner'>, scanner_args: ~typing.Sequence[~typing.Any] = ())[source]¶
Bases:
object
Multiple cube control class
This class is a wrapper to control multiple cubes easier.
When MultipleToioCoreCubes is initialized with an integer, the scan() function can search for a specified number of cubes. scan() can be followed by a call to the connect() function to connect to multiple cubes.
If you initialize MultipleToioCoreCubes with a list of CubeInfo, you can connect to multiple cubes by calling the connect() function. In this case, the scan() function does not work.
MultipleToioCoreCubes is an asynchronous context manager. When ‘async with’ is used, ‘__aenter__’ handles the process up to connection, and ‘__aexit__’ handles the disconnection.
Access to each cubes
Each cube can be accessed by the number.
>>> async with MultipleToioCoreCubes(2) as cubes: >>> cubes[0].api....() >>> cubes[1].api....()
Each cube can be accessd by ‘for’ also.
>>> async with MultipleToioCoreCubes(2) as cubes: >>> for c in cubes: >>> c.api....()
When ‘names’ is specified, cubes has each name and can be accessed with specified name.
>>> # accessing by cube name property >>> async with MultipleToioCoreCubes(2, "alpha", "beta") as cubes: >>> cubes.alpha.api....() >>> cubes.beta.api....()
>>> # accessing cubes using the cube interface obtained by name >>> async with MultipleToioCoreCubes(2, "alpha", "beta") as cubes: >>> alpha = cubes.named("alpha") >>> beta = cubes.named("beta") >>> alpha.api....() >>> beta.api....()
- OPERATION_INTERVAL: float = 0.5¶
- __init__(cubes: int | ~typing.List[~toio.device_interface.CubeInfo], names: ~typing.Sequence[str] | None = None, scanner: ~typing.Type[~toio.device_interface.ScannerInterface] = <class 'toio.scanner.ble.UniversalBleScanner'>, scanner_args: ~typing.Sequence[~typing.Any] = ())[source]¶
Initialize MultipleCubes
- Parameters:
cubes (Union[int, List[CubeInfo]]) – number of cubes to be scanned, or list of cubes to be handled
names (Optional[Sequence[str]]) – sequence of names of cubes
scanner (Type[ScannerInterface]) – scanner interface (default is UniversalBleScanner)
scanner_args (Sequence[Any]) – arguments given to the scanner.scan() function
- async scan()[source]¶
scan cubes
If MultipleCubes is initialized with integer number, this function performs to scan the number of cubes.
- async connect()[source]¶
connect to multiple cubes
cubes are connected at MultipleToioCoreCubes.OPERATION_INTERVAL second interval.