From d1d0c606fa773564e61cd2b8a837b7758529ef51 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 18 Jan 2016 22:04:56 +0530 Subject: [PATCH] More debug prints --- src/calibre/devices/winusb.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/winusb.py b/src/calibre/devices/winusb.py index 7669595a35..1c68ed6d31 100644 --- a/src/calibre/devices/winusb.py +++ b/src/calibre/devices/winusb.py @@ -813,11 +813,15 @@ def get_usb_info(usbdev, debug=False): # {{{ try: parent = next(iterancestors(usbdev.devinst)) except StopIteration: + if debug: + prints('Cannot get USB info as device has no parent (was probably disconnected)') return ans for devinfo, parent_path in DeviceSet(guid=GUID_DEVINTERFACE_USB_HUB).interfaces(): if devinfo.DevInst == parent: break else: + if debug: + prints('Cannot get USB info as parent of device is not a HUB') return ans for devlist, devinfo in DeviceSet(guid=GUID_DEVINTERFACE_USB_DEVICE).devices(): if devinfo.DevInst == usbdev.devinst: @@ -825,6 +829,10 @@ def get_usb_info(usbdev, debug=False): # {{{ break else: return ans + if not device_port: + if debug: + prints('Cannot get usb info as the SPDRP_ADDRESS property is not present int he registry (can happen with broken USB hub drivers)') + return ans handle = CreateFile(parent_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None) try: buf, dd = get_device_descriptor(handle, device_port) @@ -838,10 +846,11 @@ def get_usb_info(usbdev, debug=False): # {{{ buf, ans[name] = get_device_string(handle, device_port, index, buf=buf) except WindowsError as err: if debug: - if err.winerror == ERROR_GEN_FAILURE: - prints('Failed to read %s from device, try rebooting the device' % name) - else: - prints('Failed to read %s from device, with error: %s' % (name, as_unicode(err))) + # Note that I have observed that this fails + # randomly after some time of my Kindle being + # connected. Disconnecting and reconnecting causes + # it to start working again. + prints('Failed to read %s from device, with error: [%d] %s' % (name, err.winerror, as_unicode(err))) finally: CloseHandle(handle) return ans