public static UsbDevice findDevice(UsbHub usbHub) { for (UsbDevice device : usbHub.getAttachedUsbDevices()) { if (device.isUsbHub()) { device = findDevice((UsbHub) device); if (device != null) { return device; } } else { UsbDeviceDescriptor deviceDescriptor = device.getUsbDeviceDescriptor(); if (deviceDescriptor.idVendor() == 0x0403 && deviceDescriptor.idProduct() == 0x6001) { return device; } } } return null; }
/** * Find the specified device. * * <p>This method will look at child devices of hubs in effort to find the specified device. * * @param vendor the vendor ID of the requested device * @param product the product ID of the requested device * @param currDevice the current device being examined * @return the requested device or {@code null} if not found */ private UsbDevice findDevice(int vendor, int product, UsbDevice currDevice) { if (currDevice.isUsbHub()) { UsbHub hub = (UsbHub) currDevice; @SuppressWarnings("unchecked") List<UsbDevice> attachedUsbDevices = (List<UsbDevice>) hub.getAttachedUsbDevices(); for (UsbDevice child : attachedUsbDevices) { UsbDevice possible = findDevice(vendor, product, child); if (possible != null) { return possible; } } } else { UsbDeviceDescriptor desc = currDevice.getUsbDeviceDescriptor(); if ((desc.idVendor() & 0xffff) == vendor && (desc.idProduct() & 0xffff) == product) { return currDevice; } } // Nothing matched at this level return null; }