manuelbl / JavaDoesUSB

USB library for Java
MIT License
143 stars 11 forks source link

Device ignored due to error in descriptor #6

Closed janicaud closed 1 year ago

janicaud commented 1 year ago
net.codecrete.usb.windows.WindowsUSBException: Cannot retrieve descriptor 1. L?opération a réussi. (error code: 0)
        at net.codecrete.usb.windows.WindowsUSBException.throwException(WindowsUSBException.java:50)
        at net.codecrete.usb.windows.WindowsUSBException.throwLastError(WindowsUSBException.java:72)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.getDescriptor(WindowsUSBDeviceRegistry.java:317)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.getDescriptor(WindowsUSBDeviceRegistry.java:293)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.getStringDescriptor(WindowsUSBDeviceRegistry.java:347)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.lambda$createDevice$4(WindowsUSBDeviceRegistry.java:285)
        at net.codecrete.usb.common.USBDeviceImpl.setProductString(USBDeviceImpl.java:171)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.createDevice(WindowsUSBDeviceRegistry.java:285)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.createDeviceFromDeviceInfo(WindowsUSBDeviceRegistry.java:249)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.enumeratePresentDevices(WindowsUSBDeviceRegistry.java:149)
        at net.codecrete.usb.windows.WindowsUSBDeviceRegistry.monitorDevices(WindowsUSBDeviceRegistry.java:97)
        at java.base/java.lang.Thread.run(Thread.java:1589)

Due to a error in USB descriptor. Should be fixed by catching the exception, and maybe setting productname to null

On line 285 of WindowsUsbDeviceRegistry :

device.setProductString(descriptorSegment, (index) -> getStringDescriptor(hubHandle, usbPortNum, index));

manuelbl commented 1 year ago

Thanks for reporting this. I agree that it should be handled without an exception.

Do you happen to know what device this is? Is it a USB device you have plugged in, or rather an internal device like a built-in camera or the USB controller/hub on the motherboard?

janicaud commented 1 year ago

Typically a oem dongle for ir : https://www.amazon.fr/Zerone-t%C3%A9l%C3%A9commande-Intelligente-Universelle-Anti-poussi%C3%A8re/dp/B07DBYZDSL Tiqiaa Tview

Connected directly to a USB A or C on PC.

manuelbl commented 1 year ago

I've made a change that will catch and ignore the exception (and output an info). It will fix the problem if the device has a slightly broken device descriptor. But if the problem is more severe, it won't get much further with this device.

janicaud commented 1 year ago

Yep totally agree !

Works on my side 👍 image

janicaud commented 1 year ago

On my side, everything is ok ! just waiting for the next release ! thank you

janicaud commented 1 year ago

Could you release next version to include the improvement ?

manuelbl commented 1 year ago

I plan to do it today. Note that it might take several hours until it appears on Maven Central.

manuelbl commented 1 year ago

It's now available on Maven Central.