FileDocCategorySizeDatePackage
USBDeviceDescriber.javaAPI DocExample2488Thu Feb 16 09:12:50 GMT 2006None

USBDeviceDescriber

public class USBDeviceDescriber extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringdecodeBCD(short bcd)

    int upper = (0xFF00 & bcd) >> 8;
    int middle = (0xF0 & bcd) >> 4;
    int lower = 0x0F & bcd;
    return upper + "." + middle + "." + lower;
  
public static voiddescribe(UsbDevice device)

        UsbDeviceDescriptor descriptor = device.getUsbDeviceDescriptor();
    byte manufacturerCode = descriptor.iManufacturer();
    System.out.println("Manufacturer index: " + manufacturerCode); 
    System.out.println("Manufacturer string: " 
     + device.getString(manufacturerCode)); 
    byte productCode = descriptor.iProduct();
    System.out.println("Product index: " + productCode); 
    System.out.println("Product string: " + device.getString(productCode)); 
    byte serialCode = descriptor.iSerialNumber();
    System.out.println("Serial number index: " + serialCode); 
    System.out.println("Serial Number string: " + device.getString(serialCode)); 

    System.out.println("Vendor ID: 0x" 
     + Integer.toHexString(descriptor.idVendor())); 
    System.out.println("Product ID: 0x" 
     + Integer.toHexString(descriptor.idProduct())); 
    System.out.println("Class: " + descriptor.bDeviceClass()); 
    System.out.println("Subclass: " + descriptor.bDeviceSubClass()); 
    System.out.println("Protocol: " + descriptor.bDeviceProtocol()); 
    System.out.println("Device version: " + decodeBCD(descriptor.bcdDevice())); 
    System.out.println("USB version: " + decodeBCD(descriptor.bcdUSB())); 
    System.out.println("Maximum control packet size: " 
     + descriptor.bMaxPacketSize0()); 
    System.out.println("Number of configurations: " 
     + descriptor.bNumConfigurations()); 

    System.out.println();
  
public static voidlistDevices(UsbHub hub)

    List devices = hub.getAttachedUsbDevices();
    Iterator iterator = devices.iterator();
    while (iterator.hasNext()) {
      UsbDevice device = (UsbDevice) iterator.next();
      describe(device);
      if (device.isUsbHub()) {
        listDevices((UsbHub) device);
      }
    } 
  
public static voidmain(java.lang.String[] args)

    UsbServices services = UsbHostManager.getUsbServices();
    UsbHub root = services.getRootUsbHub();
    listDevices(root);