Java - Diferenciar USBs en uso

 
Vista:
sin imagen de perfil

Diferenciar USBs en uso

Publicado por Jose (6 intervenciones) el 18/11/2015 18:08:16
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:

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

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.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder