我希望我的程序退出,只要设备被拔下电源。我的代码:
device = usb.core.find(idVendor, idProduct)
device.detach_kernel_driver(0)
usb.util.claim_interface(device, 0)
usb_cfg = device.get_active_configuration()
usb_interface = usb_cfg[(0,0)]
port_in = usb_interface[0]
port_out = usb_interface[1]
while True:
# do read ....我怎么能检测到这个设备的插头。
发布于 2016-11-24 11:55:02
嗯,当我查看github上的代码时,我建议从这个问题中提取代码(我假设您知道回调是什么:)
PYUSB拔出请求-热插拔
在此代码中,您将register_callback与传递的事件LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT一起使用。
编辑5.12.2018:
在pyusb的分叉存储库中有一个指向热插拔分支的链接:
https://stackoverflow.com/questions/40785371
复制相似问题