0

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.

Zi Ming
  • 389
  • 4
  • 9
  • 15
  • What do you mean by "identifty the device on bus 002 device 004"? Do you mean figure out what the device is physically? Are you asking how to interpret the Vendor and Product codes? Try the [USB ID Repository](http://www.linux-usb.org/usb-ids.html) – Jim Garrison Dec 19 '16 at 06:31
  • Also [USB ID Database](http://www.the-sz.com/products/usbid/) – Jim Garrison Dec 19 '16 at 06:38
  • What i mean is .. i want to narrow down to just one USB and instead of all of the whole list coming out. Trying to improve the code so it can be flexible in detecting USB devices.. – Zi Ming Dec 19 '16 at 06:52

1 Answers1

0

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

user3801214
  • 25
  • 1
  • 4