Results 1 to 20 of 35

Thread: How to get vendor id and product id of a USB device on windows system

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Device Manager and right click the device. Windows will show you the VID and PID of the device so you can compare.

    But the above seems incorrect.

    What are you trying to do exactly? If it's to notice when a device is inserted or removed, there is buildin APIs for this and you will then get a message telling you when a device is inserted or removed - no need to do it yourself. Eg. Look at WM_DEVICECHANGE

  2. #2
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    To be specific , my application has to display the vendor id and product id of a usb device

    Any suggestions on this...

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    I'd start with SetupDiGetClassDevs()

  4. The following user says thank you to squidge for this useful post:

    newb (28th May 2010)

  5. #4
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Thank you fatjuicymole for your reply.

    i did tried that do .

    below is the code i tried.

    HANDLE h = SetupDiGetClassDevs(&GUID_CLASS_COMPORT,NULL,NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

    if ( h == INVALID_HANDLE_VALUE )
    {
    qDebug ()<<"invalid";
    }
    else
    {
    qDebug ()<<"valid handle";

    qDebug ()<<h;


    }
    Handle is valid .

    can you please lead me further to proceed.

    Sorry to be annoying because i am very to new Qt and windows programming

    Thank you for your time.

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    So your only looking for serial ports?

  7. #6
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    For the usb device i need to get the device informations

    Any helps please

  8. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    The code you have written above will only get devices of type 'serial port'. Is that what you want?

  9. #8
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    does the manufacturer of that particular device you are interested in provide some sort of API?
    For example FTDI provides an API free of charge for their USB devices.

  10. #9
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Hello fatjuicymole...

    please find my code

    static GUID GUID_DEVINTERFACE_USB_DEVICE =
    { 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };

    HANDLE hInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL,NULL,DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

    if ( hInfo == INVALID_HANDLE_VALUE )
    {
    qDebug ()<<"invalid";
    }
    else
    {
    qDebug ()<<"valid handle";

    qDebug ()<<hInfo;


    }

    SP_DEVINFO_DATA DeviceInfoData;

    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

    SP_INTERFACE_DEVICE_DATA Interface_Info;

    Interface_Info.cbSize = sizeof(Interface_Info);

    //
    DWORD i;

    DWORD InterfaceNumber= 0;

    for (i=0;SetupDiEnumDeviceInfo(hInfo,i,&DeviceInfoData );i++)
    {
    DWORD DataT;

    LPTSTR buffer = NULL;

    DWORD buffersize = 0;

    while (!SetupDiGetDeviceRegistryProperty( hInfo,&DeviceInfoData,SPDRP_DEVICEDESC,&DataT,(PBY TE)buffer,buffersize,&buffersize))
    {
    //
    {
    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    {
    // Change the buffer size.
    if (buffer) LocalFree(buffer);

    buffer = (LPTSTR)LocalAlloc(LPTR,buffersize);

    }
    else
    {
    // Insert error handling here.
    break;

    }

    qDebug ()<<"hhhh";

    qDebug ()<<(TEXT("Device Number %i is: %s\n"),i, buffer);

    if (buffer) LocalFree(buffer);

    }

    if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS )
    {
    // Insert error handling here.
    qDebug ()<<"return false";

    }

    InterfaceNumber = 0; // this just returns the first one, you can iterate on this

    //DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);

    if (SetupDiEnumDeviceInterfaces(hInfo,NULL,&GUID_DEVI NTERFACE_USB_DEVICE,InterfaceNumber,&Interface_Inf o))
    {

    printf("\nGot interface");

    DWORD needed;

    h = SetupDiGetDeviceInterfaceDetail(hInfo, &Interface_Info, NULL, 0, &needed,&DeviceInfoData);





    //qDebug ()<<Interface_Info.InterfaceClassGuid;




    }




    else
    {
    printf("\nNo interface");

    //ErrorExit((LPTSTR) "SetupDiEnumDeviceInterfaces");

    if ( GetLastError() == ERROR_NO_MORE_ITEMS) printf(", since there are no more items found.");

    else printf(", unknown reason.");

    }

    // Cleanup
    SetupDiDestroyDeviceInfoList(hInfo);

    qDebug ()<<"return true";









    //
    }
    }


    Does this code seem correct?

    i dont know how to get the information from the device

    please lead me further..

    Thank you
    Last edited by newb; 29th May 2010 at 08:11.

  11. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Once you have SetupDiGetDeviceInterfaceDetail working ok, you have the vid and pid already

    However, you are saying you don't want the information as your passing NULL to that function.

  12. #11
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    can you please provide me some leads to proceed further please.

    i am stuck on this fuctionality.you may save me from this problem.

    Looking for your guidence

    Thank you for your time
    Last edited by newb; 29th May 2010 at 11:11.

  13. #12
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    eg:

    Qt Code:
    1. SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL;
    2. DWORD dwDetDataSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) + 256;
    3.  
    4. pDetData = (_SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc (dwDetDataSize);
    5. pDetData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
    6. bOk = SetupDiGetDeviceInterfaceDetail (hDevInfo, &ifcData, pDetData, dwDetDataSize, NULL, &devdata);
    To copy to clipboard, switch view to plain text mode 

    pDetData->DevicePath contains VID and PID in string form (eg. VID_xxxx&PID_xxxx), or you can use HidD_GetAttributes function in HID.DLL to extract these to a structure:

    typedef struct _HIDD_ATTRIBUTES {
    ULONG Size;
    USHORT VendorID;
    USHORT ProductID;
    USHORT VersionNumber;
    } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
    Last edited by squidge; 29th May 2010 at 11:23.

Similar Threads

  1. Get the product/device name using QT library?
    By predatorz in forum Newbie
    Replies: 3
    Last Post: 14th January 2010, 03:53
  2. Vendor and Model Name from USB Devices
    By NoRulez in forum Qt Programming
    Replies: 6
    Last Post: 20th July 2009, 09:01
  3. Replies: 1
    Last Post: 19th September 2008, 15:43
  4. Problem whis open device in Windows
    By Pavka in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2007, 10:13
  5. Ho to get the windows system directory with Qt4
    By rmagro in forum Qt Programming
    Replies: 4
    Last Post: 30th August 2007, 13:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.