通过 pip 安装,无需额外驱动或系统配置:Install via pip — no extra drivers or system configuration.
pyserial 为唯一第三方依赖,pip 安装时自动处理。pyserial is the only third-party dependency, installed automatically.
自动扫描所有串口,连接第一个 SmartUSBHub 设备,返回实例。Scans all serial ports, connects to the first SmartUSBHub, returns an instance.
返回设备实际通道编号列表。请始终使用此方法,不要硬编码通道数。Returns the device's actual channel numbers. Always use this — don't hardcode counts.
开关指定通道的电源输出。channel 从 1 开始。Enable or disable power on a channel. Channel is 1-indexed.
控制指定通道的 USB 2.0 D+/D− 数据线,可在保持供电的同时断开数据线。Control the USB 2.0 D+/D− lines on a channel — cut data while keeping power on.
读取指定通道的电压(mV)和电流(mA)。返回含 voltage_mv 与 current_ma 的对象。Read voltage (mV) and current (mA). Returns an object with voltage_mv and current_ma.
from smartusbhub import SmartUSBHub hub = SmartUSBHub.scan_and_connect() # 逐路上电并读取电流 for ch in hub.get_channels(): hub.set_channel_power(ch, True) m = hub.get_channel_measurements(ch) print(f"ch{ch}: {m.current_ma} mA")