Şahin Şengül
Şahin Şengül

Reputation: 21

How to get USB idVendor name and idProduct name in C#

I want to get usb device name like Kingston Technology DataTraveler.

Bus 004 Device 014: ID 0951:1666 Kingston Technology DataTraveler 100 G3/G4/SE9 G2

I am using libusb library for this but I was able to obtain idVendor number and idProduct number. How to get Kingston Technology part of the idVendor?

enter image description here

int hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev,
                     libusb_hotplug_event event, void *user_data) {
  static libusb_device_handle *dev_handle = NULL;
  struct libusb_device_descriptor desc;
  (void)libusb_get_device_descriptor(dev, &desc);

    printf("Device Descriptor:\n"
           "  bLength             %5u\n"
           "  bDescriptorType     %5u\n"
           "  bcdUSB              %2x.%02x\n"
           "  bDeviceClass        %5u %s\n"
           "  bDeviceSubClass     %5u %s\n"
           "  bDeviceProtocol     %5u %s\n"
           "  bMaxPacketSize0     %5u\n"
           "  idVendor           0x%04x %s\n"
           "  idProduct          0x%04x %s\n"
           "  bcdDevice           %2x.%02x\n"
           "  iManufacturer       %5u %s\n"
           "  iProduct            %5u %s\n"
           "  iSerial             %5u %s\n"
           "  bNumConfigurations  %5u\n",
           desc.bLength, desc.bDescriptorType,
           desc.bcdUSB >> 8, desc.bcdUSB & 0xff,
           desc.bDeviceClass, cls,
           desc.bDeviceSubClass, subcls,
           desc.bDeviceProtocol, proto,
           desc.bMaxPacketSize0,
           desc.idVendor, vendor, desc.idProduct, product,
           desc.bcdDevice >> 8, desc.bcdDevice & 0xff,
           desc.iManufacturer, mfg,
           desc.iProduct, prod,
           desc.iSerialNumber, serial,
           desc.bNumConfigurations);

Upvotes: 0

Views: 472

Answers (1)

Şahin Şengül
Şahin Şengül

Reputation: 21

I solved the problem. I added necessary functions of the lsusb library from github, the problem was solved.

https://github.com/gregkh/usbutils/blob/master/lsusb.c

Upvotes: 0

Related Questions