There's currently (10.0.0-beta.2) no good way to detect an unplugged USB device using the usb.core.Device API. Unplugging will occasionally raise an immediate usb.core.USBError, but often it just results in a delayed usb.core.USBTimeoutError when you next try to poll the USB device. There's nothing about such USBTimeoutError objects to distinguish them from other timeouts that happen in the normal course of polling some USB devices (e.g. USB receivers for wireless gamepads).
Desktop PyUSB handles unplug events and other error conditions by setting usb.core.USBError.errno and usb.core.USBTimeoutError.errno with values that correlate to different USB bus conditions. CircuitPython's usb.core implementation generally does not set .errno in a useful way, and its exception string descriptions don't provide enough information to identify unplug events.
I'm posting this issue at tannewt's request to split out one of the points I mentioned in USB Host Improvement Quest Umbrella Issue #10551. The point of this issue is to let people know I'm planning to work on this myself and to ask for comments and feedback.
There's currently (10.0.0-beta.2) no good way to detect an unplugged USB device using the
usb.core.DeviceAPI. Unplugging will occasionally raise an immediateusb.core.USBError, but often it just results in a delayedusb.core.USBTimeoutErrorwhen you next try to poll the USB device. There's nothing about suchUSBTimeoutErrorobjects to distinguish them from other timeouts that happen in the normal course of polling some USB devices (e.g. USB receivers for wireless gamepads).Desktop PyUSB handles unplug events and other error conditions by setting
usb.core.USBError.errnoandusb.core.USBTimeoutError.errnowith values that correlate to different USB bus conditions. CircuitPython'susb.coreimplementation generally does not set.errnoin a useful way, and its exception string descriptions don't provide enough information to identify unplug events.I'm posting this issue at tannewt's request to split out one of the points I mentioned in USB Host Improvement Quest Umbrella Issue #10551. The point of this issue is to let people know I'm planning to work on this myself and to ask for comments and feedback.