0
我想,如果設備被移除退出我PROGRAMM。 我的代碼:PyUsb:檢測設備移除
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 ....
我怎樣才能檢測到設備的拔掉。
使用'libudev'('pyudev'包裝以防'python')監視枚舉事件。你只需要'libusb'來進行實際的設備通信。 –