开源项目地址:https://github.com/pavel-a/usb-relay-hid
lsusb 显示连接到USB总线上的设备信息和驱动信息
root@test:/home/# lsusb
Bus 001 Device 014: ID 16c0:05df Van Ooijen Technische Informatica HID device except mice, keyboards, and joysticks
root@test:/home/# lsusb -v -d 16c0:05df
安装软件包
#或者下载发布到bin文件,直接执行
$ sudo apt-get install usbrelay
# 0是关闭 1是开启
root@test:/home/# usbrelay
0_1=0
0_2=1
# 永久更改序列号,由0_为AUTOC_
root@test:/home/# usbrelay 0_0=AAAA
AAAA_1=0
AAAA_2=1
# 设置1个模块的继电器状态
root@test:/home/# usbrelay AAAA_1=0
# 设置多个模块的继电器状态
root@test:/home/# usbrelay AAAA_1=1 AAAA_2=0
AAAA_1=1
AAAA_2=0
Python实现
在这里插入代码片