Finding the details of the single USB device plugged using java

1.3k views Asked by At

pardon my english as english is not my main language.

I am currently a student - to be frank and i am trying to work on my project .

Languages used is JAVA and IDE is eclipse.

Currently i used LIBUSB for my project which i downloaded from http://usb4java.org/ . it is pretty helpful and i managed to get a list of details of my devices. So my problem is... let say i just want to identified for example device 004. Is there any suggestion on this. ? i tried with scanning it two time and compare the output but failed due to the datatype given is not match. At first i thought that the datatype could be arraylist but is not. Is there another way to store the output to text file so i can do comparison?

my codes which i took from the libusb example online.

public class UsbBench {
/**
 * Main method.
 * 
 * @param args
 *            Command-line arguments (Ignored)
 * @throws IOException 
 */
public static void main(String[] args) throws IOException 
{
    // 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)
        {
            int address = LibUsb.getDeviceAddress(device);
            int busNumber = LibUsb.getBusNumber(device);
            DeviceDescriptor descriptor = new DeviceDescriptor();
            result = LibUsb.getDeviceDescriptor(device, descriptor);
            if (result < 0)
            {
                throw new LibUsbException(
                    "Unable to read device descriptor", result);
            }

        }

    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }



    // Deinitialize the libusb context
    LibUsb.exit(context);
}

}

And it is working good also. OUTPUT:

Bus 002, Device 003: Vendor 1bcf, Product 2c6e
Bus 001, Device 002: Vendor 06cb, Product 2970
Bus 001, Device 003: Vendor 0461, Product 4ded
Bus 001, Device 001: Vendor 8086, Product 8c31
Bus 002, Device 001: Vendor 8086, Product 8c26
Bus 002, Device 004: Vendor 04ca, Product 300b
Bus 002, Device 005: Vendor 8087, Product 8000

So my problem is... let say i just want to identified for example device 004. Is there any suggestion on this. ? this is also my first time in stackoverflow. i humblely seek your expertise. thanks. thanks.

1

There are 1 answers

0
user3801214 On

You can know several information about your USB device from settings of your Operating System, but I recommend you to download this software (http://www.nirsoft.net/).

it allow you to check every device connected on your computer and to know several information about it (example : VendorId & ProductId) which allow you to recognize your device.

example USB