Foro de elhacker.net

Programación => Java => Mensaje iniciado por: DvNe en 18 Noviembre 2015, 18:03 pm



Título: Diferenciar USBs en uso
Publicado por: DvNe en 18 Noviembre 2015, 18:03 pm
Buenas,

Estoy realizando un proyecto en Java con el que necesito saber qué USB está siendo usado, me explico:

Estoy programando en un portátil que tiene 3 entradas USB:
  • USB 3.0
  • USB 2.0
  • USB 2.0

Y por otro lado, tengo un escaner de huella dactilar que se conecta por USB.

He estado mirando la librería jUSB pero esta necesita instalar un driver para poder usarla así que la he descartado.
Luego he estado indagando sobre la librería usb4java y he visto sus ejemplos. Copiando y pegando he preparado este pequeño código:

Código
  1. package pruebausb;
  2.  
  3. import org.usb4java.Context;
  4. import org.usb4java.Device;
  5. import org.usb4java.DeviceDescriptor;
  6. import org.usb4java.DeviceList;
  7. import org.usb4java.LibUsb;
  8. import org.usb4java.LibUsbException;
  9.  
  10. public class PruebaUSB {
  11.  
  12.    public static void main(String[] args) {
  13.          // Create the libusb context
  14.        Context context = new Context();
  15.  
  16.        // Initialize the libusb context
  17.        int result = LibUsb.init(context);
  18.        if (result < 0)
  19.            throw new LibUsbException("Unable to initialize libusb", result);
  20.  
  21.        // Read the USB device list
  22.        DeviceList list = new DeviceList();
  23.        result = LibUsb.getDeviceList(context, list);
  24.        if (result < 0)
  25.            throw new LibUsbException("Unable to get device list", result);
  26.  
  27.        try {
  28.            // Iterate over all devices and list them
  29.            for (Device device: list) {
  30.  
  31.                DeviceDescriptor descriptor = new DeviceDescriptor();
  32.                result = LibUsb.getDeviceDescriptor(device, descriptor);
  33.                if (result < 0)
  34.                    throw new LibUsbException("Unable to read device descriptor", result);                
  35.                System.out.println(descriptor.dump());
  36.            }
  37.        } finally {
  38.            // Ensure the allocated device list is freed
  39.            LibUsb.freeDeviceList(list, true);
  40.        }
  41.  
  42.        // Deinitialize the libusb context
  43.        LibUsb.exit(context);
  44.    }
  45. }

Y al ejecutarlo me aparece esto:

Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                0.00
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0          0
  idVendor            0x1022
  idProduct           0x7809
  bcdDevice             0.00
  iManufacturer            0
  iProduct                 0
  iSerial                  0
  bNumConfigurations       1

Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                0.00
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0          0
  idVendor            0x1022
  idProduct           0x7807
  bcdDevice             0.00
  iManufacturer            0
  iProduct                 0
  iSerial                  0
  bNumConfigurations       1

Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                0.00
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0          0
  idVendor            0x1022
  idProduct           0x7807
  bcdDevice             0.00
  iManufacturer            0
  iProduct                 0
  iSerial                  0
  bNumConfigurations       1

Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                0.00
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0          0
  idVendor            0x1022
  idProduct           0x7808
  bcdDevice             0.00
  iManufacturer            0
  iProduct                 0
  iSerial                  0
  bNumConfigurations       1

Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                0.00
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0          0
  idVendor            0x1022
  idProduct           0x7808
  bcdDevice             0.00
  iManufacturer            0
  iProduct                 0
  iSerial                  0
  bNumConfigurations       1

Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                2.00
  bDeviceClass           239 Unknown
  bDeviceSubClass          2
  bDeviceProtocol          1
  bMaxPacketSize0         64
  idVendor            0x04f2
  idProduct           0xb3b1
  bcdDevice            57.16
  iManufacturer            3
  iProduct                 1
  iSerial                  2
  bNumConfigurations       1

Por esto deduzco que usb4java no soporta USB 3.0 (no se si estoy en lo cierto), pero lo que me confunde es que deberían aparecer bcdUSB con valor 2.00 (que creo que es la versión del puerto USB si estoy en lo cierto).

Necesito saber si hay alguna forma de darle a cada puerto USB un nombre estilo COM1, COM2, etc. para distinguir cuándo conecto el escaner de huella dactilar a un USB u otro.