factory¶
Model auto-detection, bus discovery, and first-time multi-device address assignment (see First-time setup for multiple devices on one bus).
Auto-detection and instantiation of the right device class for each unit on a bus.
- tl_elliptec.factory.create_device(bus, address, timeout=None)[source]¶
Query the device at
addressand instantiate the matching model class.- Parameters:
bus (ElliptecBus) – The bus the device is on.
address (str) – Single hex-digit address to query.
timeout (float | None) – Reply timeout, in seconds. Defaults to the bus’s own
timeout.
- Returns:
A device instance of the appropriate
ELLxxclass.- Raises:
ElliptecError – If the device doesn’t answer or reports an unrecognized ELL type.
- Return type:
- tl_elliptec.factory.discover_devices(bus, addresses='0123456789ABCDEF', timeout=0.3)[source]¶
Scan
addressesand return a device instance for each one that answers.- Parameters:
bus (ElliptecBus) – The bus to scan.
addresses (str) – Iterable of single-hex-digit addresses to probe. Defaults to all 16 (
"0"-"F").timeout (float) – Per-address reply timeout, in seconds.
- Returns:
{address: device}for every address that answered with a recognized ELL type.- Return type:
- tl_elliptec.factory.setup_devices(bus, count, start_address='1', wait_for_next_device=None, detect_timeout=60.0, poll_interval=0.5)[source]¶
Assign unique addresses to
countfactory-default (address “0”) devices, one at a time.Every ELLx module ships at address “0”. Two or more of them on the same bus simultaneously both answer to “0” and their replies collide electrically – neither
scan()nordiscover_devices()can see anything in that state, and there’s no way to tell them apart in software once that’s already happened. This walks you through the one-time fix: address them one at a time.For each of
countdevices, this:Calls
wait_for_next_device(index, count)– by default, prints an instruction and blocks oninput()– so you can physically connect (or power up) the next unaddressed device now. Devices already given a unique, non-zero address in an earlier step (or before this call) can stay connected; only ever have one device at “0” at a time.Polls address “0” until something answers (or
detect_timeoutelapses, raisingElliptecError).Assigns it the next address starting at
start_address, skipping any address already occupied on the bus (detected viabus.scan()up front, so devices already addressed in a previous run aren’t reused).Confirms it now answers at the new address and saves it (
us, non-volatile – this is a one-time step per device, not a per-session one).
If two devices are already colliding at “0” when you call this, disconnect down to one of them first – this function has no way to un-collide them for you.
- Parameters:
bus (ElliptecBus) – The bus the new devices are (or will be) connected to.
count (int) – How many new devices to address.
start_address (str) – First address to try assigning, in ascending order (skipping any already occupied). Single hex digit,
"1"by default (since"0"is the factory default every new device arrives at).wait_for_next_device (Callable[[int, int], None] | None) – Called as
wait_for_next_device(index, count)before detecting each device; defaults to printing an instruction and blocking oninput(). Pass your own callback to drive this step from a GUI instead.detect_timeout (float) – How long to wait, in seconds, for a device to appear at address “0” before giving up on that slot.
poll_interval (float) – Polling interval, in seconds, while waiting for a device to appear, and the reply timeout used for the confirm/save steps.
- Returns:
The newly assigned addresses, in order.
- Raises:
ValueError – If
start_addressisn’t a valid single hex digit.ElliptecError – If no device appears at address “0” within
detect_timeoutfor some slot, or if there are no free addresses left to assign.
- Return type: