How to get Vendor ID and Product Id of connected USB Device On Arduino Due board

I want to Read Vendor ID and Product Id of Connected USB device on Arduino Due board.

Can any one help me to read above parameters

Hello,
In short it is not easy. :frowning:

The reasons are many:

  1. Are there Vendor Id and Product Id in every USB Device? I can answer only for Mass Storage Class to some extent.
  2. Are you meaning the Vendor/Product id of a card that is mounted inside a card reader? I can tell you something about it too.

So, if you say the type of device then others might be able to help you. Types: HID, Mass Storage, CD-ROM, Etc.

For Mass Storage Class, here is my answer:

Case-1: You connected a rotating disk USB hard drive. The only similar drive I have reported something in USB Descriptor that is not "Transparent SCSI". So, I cannot help because I did not investigate further.

Case-2: You connect a Card Reader that can potentially have many slots (1 to 4 typically). Then you insert a media card in one of the slots. Then, whose Vendor/Product Id are you trying for? The Card Reader's or the media?

Case-3: You connect a thumb drive where the media is built-in and there is no slot for any more media.

There is no publicly available document that describes a way to get the vendor/product id of a media card using a Card Reader. A media card may be SD, CompactFlash, Memory Stick, MM2, etc. Of these, the SD Association is probably the easiest to deal with because they give out a short version of the SD card spec.
Now, even with that spec in hand, and a way to read the Card Structures (like using SdFat in Arduino on a Ethernet Shield), you would still have problem. Because, the SD Assoc has the Vendor/Product Id codified in some binary number and the list of these number is not publicly available.

However, if you want to know the Vendor/Product Id of the Card Reader, then it is possible. But beware... a Card Reader marketed under Kingston may not show as "Kingston Memory" as the vendor! Many of the Card Readers I have, they lie about the maker.

The thumb drives are a little better because they mostly say the correct vendor id.

I assumed by Vendor/Product Id you meant the fields of SCSI Inquiry data. In order to get that, you go through the USB descriptors (Device, Config, Interface and End Points) and then first get a USB device address for the device (I mean you just assign one if working in a bare bone system -- there is a USB command to tell the device what non-zero number you assigned).

After that you need to switch over to Mass Storage Class commands (CBW-CSW stuff). USBIF has openly available specs for these MSC devices. Once there, you can now fire a SCSI Inquiry to the device using CBW-CSW protocol and get the inquiry data!

Hope I didn't confuse you :astonished:

Regards.

It is not very difficult to read out them.

haturi
Each manufactor got it's own vendor id. And for each product, there is a product id. So if you have 2 of the same device, both id's are the same.

Actually what i want is similar to following link..

http://www.circuitsathome.com/mcu/arduino-usb-host-part-3-descriptors

above link work only withr Arduino Uno not for Arduino Due...

I want to read Device Descriptor for USB device connected to Native port of Due.

I will have to look it up. But I did it before.

Can you please share the code..

vijaypatil14:
Can you please share the code..

I will share it when I have time.

You can do something like this:

#include <Usb.h>

USBHost usb;

boolean found = false;

void setup()
 { 
         while(!found)
         {
               usb.Task();
               usb.ForEachUsbDevice(DeviceTest);
         }
}

void DeviceTest(UsbDevice *pdev)
{ 
     USB_DEVICE_DESCRIPTOR d;
     if(usb.getDevDescr(pdev->address, 0, DEV_DESCR_LEN, (byte*)&d) == 0)
     {
            //Now use d.idVendor and d.idProduct to indentify your device.
            //If you have found the right one, store pdev global and set found to true.
     }
}

Gericom: Please excuse my delay in responding to your suggestion on vendor/product id. What you say is surely possible and I have seen an unofficial list of USB vendor/product ids somewhere in web forum. But the basic problem is you cannot be too sure of what you get ... you know many users use multiple accounts to post in forums... :wink:

I think vijayPatil14 needs to distinguish what he wants to read: the vendor/product ids of a media card is simply not easy to get if being used with a card reader. Getting the USB Dev Descriptor's Vendor/product id would get him the id of card reader... not what is mounted on it. Does this mean it is impossible to know the SD Assoc defined CID, CSD using a card reader? Hardly.
If I am the manufacturer, I might leave a mechanism (vendor unique SCSI Command) to get that when working with common media cards like SD, SDIO, CompactFlash, MMC2, stick(?), etc.
If he wants to know how to process the USB descriptors, I recently made available the mass storage class driver for Native USB port and it has all the code needed to extract the four primary descriptors: dev, config, interface & endpoint. Look into doMscConfig(). While the driver code stops after discovering the first drivable interface, his code could carry on and discover all the descriptors if he likes.

regards.

haturi:
Gericom: Please excuse my delay in responding to your suggestion on vendor/product id. What you say is surely possible and I have seen an unofficial list of USB vendor/product ids somewhere in web forum. But the basic problem is you cannot be too sure of what you get ... you know many users use multiple accounts to post in forums... :wink:

I think vijayPatil14 needs to distinguish what he wants to read: the vendor/product ids of a media card is simply not easy to get if being used with a card reader. Getting the USB Dev Descriptor's Vendor/product id would get him the id of card reader... not what is mounted on it. Does this mean it is impossible to know the SD Assoc defined CID, CSD using a card reader? Hardly.
If I am the manufacturer, I might leave a mechanism (vendor unique SCSI Command) to get that when working with common media cards like SD, SDIO, CompactFlash, MMC2, stick(?), etc.
If he wants to know how to process the USB descriptors, I recently made available the mass storage class driver for Native USB port and it has all the code needed to extract the four primary descriptors: dev, config, interface & endpoint. Look into doMscConfig(). While the driver code stops after discovering the first drivable interface, his code could carry on and discover all the descriptors if he likes.

regards.

The code I posted is part of my msd library for the due as well. It only works with 2 usb sticks so far. But this snipped works great.

Its working Great!!!!!
Thanks you Sir..........

can i get usb.h thanks