基于 USB CDC 的开源 Python 库;Windows 10/11、macOS 和 Linux 使用系统内置驱动。 An open-source Python library that controls SmartUSBHub devices over USB CDC. Windows 10/11, macOS and Linux use built-in drivers.
通过 pip 安装,所需 Python 依赖会自动安装: Install via pip; the required Python dependency is installed automatically:
pyserial 为唯一第三方依赖,pip 安装时自动处理。 pyserial is the only third-party dependency and is installed automatically.
自动扫描串口并连接第一个 SmartUSBHub。成功时返回已连接实例;未找到设备时返回 None,使用前必须检查。 Scans serial ports and connects to the first SmartUSBHub. Returns a connected instance on success or None when no device is found; always check before use.
返回当前连接设备的实际通道编号列表。请始终使用此方法,不要硬编码通道数量。 Returns the actual channel numbers of the connected device. Always use this method instead of hard-coding channel counts.
开关一个或多个通道的电源输出。通道编号从 1 开始,state 必须作为关键字参数传入;设备确认成功返回 True,否则返回 False。 Enables or disables power on one or more 1-indexed channels. state is keyword-only; returns True when acknowledged, otherwise False.
控制一个或多个通道的 USB 2.0 D+/D− 数据线,state 必须作为关键字参数传入。仅适用于带 USB 2.0 数据线开关的型号。 Controls USB 2.0 D+/D− data lines on one or more channels. state is keyword-only. Available only on models with a USB 2.0 data-line switch.
批量读取指定通道的电压和电流。返回值以通道号为键,每路数据包含 voltage(mV)、current(mA)、fresh、stale 和 valid;超时返回 None。 Batch-reads voltage and current for selected channels. The result is keyed by channel; each reading contains voltage (mV), current (mA), fresh, stale and valid. Returns None on timeout.
| 操作系统Operating system | 驱动要求Driver | 备注Notes |
|---|---|---|
| Windows 10 / 11 | 无需安装None required | 内置 CDC 驱动Built-in CDC driver |
| macOS 12+ | 无需安装None required | 内置 CDC ACM 驱动Built-in CDC ACM driver |
| Linux (Ubuntu 20.04+) | 无需安装None required |
可能需要将用户加入 dialout 组:
You may need to add your user to the dialout group:
sudo usermod -aG dialout $USER
|