Python Examples¶
Runnable examples for the SmartUSBHub Python library. Each script is self-contained, connects to the first hub it finds, and documents what it does in its top-of-file docstring.
Prerequisites¶
A SmartUSBHub connected over USB. The examples auto-detect it via
SmartUSBHub.scan_and_connect(); no port name is required.Make sure the serial port is not held open by another program.
Choose one setup method:
Install the released package:
pip install smartusbhub
Use this source checkout:
cd smartusbhub
pip install -r requirements.txt
python examples/power_control_example.py
GUI examples require extra packages:
pip install pyqtgraph PyQt5 numpy
Running¶
Run any script from the package root or from this source checkout:
python examples/power_control_example.py
Basics¶
Example |
What it shows |
|---|---|
Read the hub’s identity + runtime status; |
|
Turn channels on/off, individually and in groups; interlock mode |
|
Read device info; configure default states, address, operate mode and buttons; factory reset |
|
Power-cycle every controllable channel in sequence |
|
Configure power-on defaults (power ON, USB2 data line connected) |
Monitoring (models with voltage/current sensing)¶
Example |
What it shows |
|---|---|
Continuously print per-port voltage/current via V2 request/response |
|
Continuously print per-port voltage/current via the V3 measurement stream |
|
Real-time GUI plot of voltage/current (needs PyQt5 + pyqtgraph) |
|
Same plot, driven by the V3 measurement streaming protocol |
|
Poll overcurrent active/latch status on USB2 7P models only |
Advanced¶
Example |
What it shows |
|---|---|
Disconnect/reconnect a channel’s USB2.0 data line while power stays on |
|
Register callbacks invoked when a command is acknowledged |
|
Discover and control several hubs at once |