PYTHON 控制HID-USB蜂鸣器
本文地址:http://tongxinmao.com/Article/Detail/id/446
USB-hid 蜂鸣器
https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-22451767025.9.64041349oIFB55&id=605695967804
#pip install pyusb win32-libusb device filter
import usb.core
import usb.util
all_devs = usb.core.find(find_all=True)
for d in all_devs:
print(d)
# find our device
dev = usb.core.find(idVendor= 0x5131, idProduct= 0x2019)
# was it found?
if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(1,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
# write the data
beepcmd=[0,0,0,0xa0,1] # 1*100ms
ep.write(beepcmd)
上一篇:打印机连接技术概述(LPR&RAW&AppleTalk)
下一篇:嵌入式Linux上移植unzip