Skip to main content
Cut and restore power to one port of a programmable USB hub. A test uses this to force a DUT to re-enumerate, or to simulate a cable pull.

Handle

Methods

Method Reference

enable() -> Result<()> and disable() -> Result<()>

Power the port on or off.

toggle() -> Result<bool>

Invert the port’s power state. Returns: true if the port is now enabled, false if now disabled — the state after the toggle, not before.

state() -> Result<bool>

Read whether the port is powered.
Returns: true when enabled.
state() needs box software 0.29.0 or newer. Older boxes reject the action, and the crate turns that specific rejection into Error::UnsupportedByBox with the message the 'state' action on /usb/command requires box software >= 0.29.0; update the box or use toggle/enable/disable.

cycle() -> Result<Option<bool>>

Power the port off, wait, and power it on again. The box watches for the device to re-enumerate. It requires box software 0.39.0 or later.
The port is powered at the end on every path, including failures. The default off time is 1 s. cycle_with_off_time(secs) takes another value from 0.5 to 10 s. When in doubt, choose a longer time: a short one lets the DUT warm-start without a real reset.

cycle_report(off_time_secs: Option<f64>) -> Result<UsbCycleReport>

Like cycle(), and the report also carries the box’s outcome (box 0.49.0 or later). A UsbCycleReport has three fields: reconnected, the same value that cycle() returns; outcome; and the box’s message. The outcome tells an empty port apart from a port the box did not watch:

recover() -> Result<()>

Power the port on again after a command stopped partway through. On a Plugable dock, this powers every port of that dock.

Examples

Force a DUT to re-enumerate and wait for it to come back

On a Plugable dock, a device on a powered-off port stays listed on the bus until power returns. The loop above can then match the old entry at once, before the DUT re-enumerates. Use cycle() instead, which waits for the hub to report the reconnect.

Supported Hardware

Notes

  • One net is one port. Cycling usb1 leaves the hub’s other ports alone.
  • The port’s devnum on the bus changes across a re-enumeration. Match a device by serial or vid/pid, never by devnum, when checking that it came back.
  • Powering a port down can remove a device that the box uses for another net. A debug probe or serial adapter behind that port will disappear mid-test.