Port expander

The LPF2 Port Expander is an accessory that plugs into a single hub port and provides four sub-ports. Two roles:

Sub-port numbering

lpf2.port_expander.port_num — constants P0, P1, P2, P3.

Client side

from lpf2 import devices, port_expander

dev = port.device()   # must be devices.port_expander
assert isinstance(dev, devices.port_expander)

sub_a = dev.getPort(port_expander.port_num.P0)
if sub_a.isDeviceConnected():
    inner = sub_a.device()

Sub-ports are polled through the parent expander’s update(), which is itself in the C-side registry (see Automatic polling) — no manual polling required.

Server side

import lpf2
from lpf2 import port_expander, virtual

my_expander = port_expander.virtual_device()

# Two child devices exposed as sub-ports 0 and 1:
for slot, child_port in enumerate([my_port_a, my_port_b]):
    my_expander.attachPort(slot, child_port)

host_port = virtual.port()
host_port.attachDevice(my_expander)
# Plug host_port into a hub_emulation port slot, etc.

See Virtual devices for the general virtual-device pattern.