小智 4
查看标准库中的subprocess模块:
您需要什么命令取决于操作系统。
对于 Windows,您需要查看devcon
这个问题在之前的帖子里已经回答过
import subprocess
# Fetches the list of all usb devices:
result = subprocess.run(['devcon', 'hwids', '=usb'],
capture_output=True, text=True)
# ... add code to parse the result and get the hwid of the device you want ...
subprocess.run(['devcon', 'disable', parsed_hwid]) # to disable
subprocess.run(['devcon', 'enable', parsed_hwid]) # to enable
Run Code Online (Sandbox Code Playgroud)
import subprocess
# determine desired usb device
# to disable
subprocess.run(['echo', '0', '>' '/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms'])
subprocess.run(['echo', 'auto', '>' '/sys/bus/usb/devices/usbX/power/control'])
# to enable
subprocess.run(['echo', 'on', '>' '/sys/bus/usb/devices/usbX/power/control'])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11167 次 |
| 最近记录: |