Import
Methods
Exception Classes
Method Reference
Net.get(name, type=NetType.Usb)
Get a USB net by name.
Returns: USB Net instance
enable()
Enable (power on) the USB port.
disable()
Disable (power off) the USB port.
toggle()
Toggle the power state of the USB port. Returns the resulting state
(True if now enabled, False if now disabled).
state()
Read the current power state of the USB port without changing it. Returns
True if the port is currently enabled (powered on), False if disabled. The
value is read live from the hub, so it always reflects the real port state.
cycle(off_time=None)
Power-cycle the port: off, wait, on. Returns True if the device was seen to
re-enumerate, False if it did not come back in time, and None if the hub
reports nothing attached or the driver cannot observe re-enumeration.
None does not mean the port is unused. A hub only sees a device that pulls
up its data lines, so a charge-only cable — power on the other end, no data —
is indistinguishable from an empty socket. Power is cut and restored either way;
there is simply nothing on the bus to watch come back. Confirm a DUT on such a
port by its own behaviour instead: its UART output, or a current measurement.off_time is how long the port stays unpowered, defaulting to 1 second and
limited to 0.5-10 seconds. Too short an off time is the failure that matters:
the device’s rails do not fully discharge and it warm-starts while appearing to
have been reset. Raise it for a device with large bulk capacitance.
disable/sleep/enable: it holds the hub for
the whole sequence, so nothing else can switch the port while it is dark, and it
restores power on every failure path, so an exception partway through cannot
leave a port stranded.
cycle returns on the hub’s reconnect signal, a few hundred milliseconds
after power returns — not on Linux finishing enumeration. So /dev/ttyUSB* may
not exist yet when it returns, and a /sys read taken immediately still shows
the pre-cycle device number. Poll for what you need rather than reading once.recover()
Restore power after an interrupted operation left a port unpowered. On hubs where
lager can identify the whole physical device, this re-powers every port on it.
Examples
Basic Power Control
Power Cycle Device
Error Handling
Automated Test Setup
USB Device Reset
Toggle for Quick State Change
Supported Hardware
Notes
- USB nets must be configured on the Lager Box with hub serial number and port mapping
- Power state changes take effect immediately
- Allow time for USB enumeration after powering on (~1-3 seconds).
cycle()does this waiting for you and tells you whether the device returned - Power cycling can be useful for device reset/recovery; prefer
cycle()over a hand-rolleddisable/sleep/enableso a failure cannot leave a port off - A port that is powered off still appears in
lsusband keeps its device nodes, so never use device presence to test whether a port is off - The
toggle()function is useful for quick state changes - Use exception handling for robust error recovery

