1. TrainScanner

from intelino.trainlib import TrainScanner
class trainlib.TrainScanner(device_identifier: Optional[str] = None, timeout: float = 5.0)

Obtaining a Train object using the with statement.

Connecting to a single train (basic usage):

with TrainScanner() as train:
    train.drive_at_speed(40)

Connecting to multiple trains:

trains = TrainScanner(timeout=3.0).get_trains(2)
for train in trains:
    train.drive_at_speed(40)
__init__(device_identifier: Optional[str] = None, timeout: float = 5.0)
Parameters
  • device_identifier (str) – The Bluetooth/UUID address of the Bluetooth peripheral sought. If not specified, it will return the first found intelino train.

  • timeout (float) – Optional timeout to wait for detection of specified peripheral before giving up. Defaults to 5.0 seconds.

get_train(**kwargs) trainlib.train.Train

Get a blocking train instance synchronously.

Keyword Arguments

adapter (str) – Bluetooth adapter to use for discovery.

Raises

TrainNotFoundError – If no train is found.

Returns

A connected Train instance.

get_trains(count: Optional[int] = None, **kwargs) List[trainlib.train.Train]

Get a list of blocking train instances synchronously.

Parameters

count (int) – Optional detection limit. If not satisfied, raises an exception. If omited or 0, it searches for all trains in the surroundings until it timeouts.

Keyword Arguments
  • at_most (int) – Connect to at most N trains. No exception is raised if the count argument is omitted.

  • adapter (str) – Bluetooth adapter to use for discovery.

Raises

TrainNotFoundError – If the requested number of trains is not found.

Returns

A list of Train instances.

Example

>>> # connect to all trains in 5 seconds (always takes 5 seconds)
>>> trains = TrainScanner(timeout=5.0).get_trains()
>>> # connect to exactly 2 trains, max. waiting time 3 seconds
>>> trains = TrainScanner(timeout=3.0).get_trains(2)
>>> # connect to 0 - 4 trains within 10 seconds
>>> trains = TrainScanner(timeout=10.0).get_trains(at_most=4)