elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Diferenciar USBs en uso
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Diferenciar USBs en uso  (Leído 1,321 veces)
DvNe

Desconectado Desconectado

Mensajes: 12


Ver Perfil
Diferenciar USBs en uso
« 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.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Infeccion de dispositivos USBs mediante archivos LNK
Análisis y Diseño de Malware
Jaixon Jax 4 6,755 Último mensaje 1 Diciembre 2010, 02:25 am
por Stelio Kontos
ayuda, mi pc no reconoce los USBs
Windows
priorigi_10 4 2,629 Último mensaje 13 Septiembre 2014, 07:24 am
por shaddom
Posible virus en mis USBs?
Análisis y Diseño de Malware
Fran 4 2,953 Último mensaje 20 Abril 2017, 09:56 am
por 3n31ch
USBs inservibles
Hardware
ivangijon 3 1,988 Último mensaje 7 Octubre 2017, 16:05 pm
por PalitroqueZ
JBOD o RAID 0 de USBs
Hardware
akantor 0 1,712 Último mensaje 22 Octubre 2017, 03:43 am
por akantor
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines