none
Is it possible to detect "USB Device Not Recognized"

    Question

  • Hi All,

    I have an application which programs a microchip over USB. When the USB device is connected to the PC, about 50% of the time it enumerates properly and the rest of the time Windows pops up a "USB device not recognized" message.

    Currently, I override WndProc and handle the WM_DEVICECHANGE message to determine when this USB device is attached (also using SetupDixxx functions to extract extra device information). The problem comes when the device fails to enumerate - ideally, I'd like to be able to trap the event when a device does not enumerate properly.

    Is this at all possible?

    What I'm seeing so far is that in WndProc, when a device fails to enumerate I get a DBT_DEVNODES_CHANGED event yet no information which comes with this event informs me of an unsuccessful connection.

    I've considered implementing some kind of timeout which expires if a device hasn't been seen for a couple of seconds, however as this application is to be run on various different hardware setups, the time taken for enumeration can vary greatly.

    Any suggestions? Unfortunately, it isn't possible to fix the USB device so that it enumerates successfully every time.

    This post may well be in the wrong forum too, would there be a better forum for this?

    Thanks,

    Kev

    Thursday, July 15, 2010 6:28 AM

All replies

  • You should be able to accomplish this using WMI event triggers. I don't have the code at hand though.
    Thursday, July 15, 2010 9:40 AM
  • hi Kev,

     

    Would you please give me more detail information about your question, for example the develop language, some code snippets and work environment. I will try our best to help to solve your problems. If your question over my ability, I will escalate your questions.

     

    if you have any problems, please feel free to let me know.

     

    Best Regards,

    Alan Chen

    *** Please mark as Answer, if this reply helps you***

    Monday, July 19, 2010 8:00 AM
  • Ok, I'll try and elaborate a little more. I have the following code to detect USB device arrival and removal...

    protected override void WndProc(ref Message m)
    {
      switch (m.Msg)
      {
        case WM_DEVICECHANGE:  // 0x219;
        {
          int wParam = (int)m.WParam;
    
          switch (wParam)
          {
            case DBT_DEVICEARRIVAL:          // 0x8000;
            case DBT_DEVICEREMOVECOMPLETE:  // 0x8004;
              // Handle any device notifications
              .....
              break;
            case DBT_DEVNODESCHANGE:       // 0x0007;
              // Handle any device node change
              .....
              break;
          }
        }
      }
    }
    

    Now, the problem with the above code is that regardless of whether a USB device enumerates successfully, I receive the same notification information.

    So, I guess my question is relating to the fact that how would I ever know if the device connected has enumerated successfully, rather than "USB device not recognized" notification within Windows?

    Kev

     

     

    Monday, July 19, 2010 12:38 PM
  • Kev,

    Your code is waiting for WM_DEVICECHANGE windows message, which is right and then it is trying to differentiate the message info by DBT_DEVNODES_CHANGE.

    If you look at documentation of WM_DEVICECHANGE http://msdn.microsoft.com/en-us/library/aa363480(VS.85).aspx , wParam is...

    DBT_DEVNODES_CHANGED
    0x0007 A device has been added to or removed from the system.

    And lParam is...

    lParam
    A pointer to a structure that contains event-specific data. Its format depends on the value of the wParam parameter. For more information, refer to the documentation for each event.

    So your code gets this, and lParam specific information for this event type is listed here http://msdn.microsoft.com/en-us/library/aa363211(VS.85).aspx

    Parameters
    hwnd
    A handle to a window.
    uMsg
    The WM_DEVICECHANGE message identifier.
    wParam
    Set to DBT_DEVNODES_CHANGED.
    lParam
    Set to zero.
    Return Value
    Return TRUE.
    Remarks

    There is no additional information about which device has been added to or removed from the system. Applications that require more information should register for device notification using the RegisterDeviceNotification function.

    Now, if you again go to http://msdn.microsoft.com/en-us/library/aa363431(VS.85).aspx , it will tell you same thing and sample is only an unmanaged sample http://msdn.microsoft.com/en-us/library/aa363432(VS.85).aspx


    With the original question in his post as below—
    • “So, I guess my question is relating to the fact that how would I ever know if the device connected has enumerated successfully, rather than "USB device not recognized" notification within Windows?”
    • The answer is--

    DBT_DEVICEARRIVAL
    0x8000 A device or piece of media has been inserted and is now available.

    Please test further for DBT_DEVICEARRIVAL. More information http://msdn.microsoft.com/en-us/library/aa363205(VS.85).aspx
    Minimal Sample http://msdn.microsoft.com/en-us/library/aa363215(VS.85).aspx

    If you need more assistance from us beyond this Kev you will need to open a support case. Please visit this link to see the various paid support options that are available to better meet your needs:  http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone.

     


    --Trevor H.
    Send files to Hotmail.com: "MS_TREVORH"
    Check out the Microsoft CTS TFS BLOG: blogs.msdn.com/b/dstfs
    Friday, August 20, 2010 3:01 PM
  • Trevor,

    Thanks for your reply. I've pretty much tested the DBT_DEVICEARRIVAL event to death and I believe that it is not possible to know whether a USB device has been recognized or not during this event. I don't think the RegisterDeviceNotification will give me any additional information that the 3 events (ARRIVAL, REMOVECOMPLETE and DEVNODES_CHANGED) don't already give me.

    I guess what I can do is try to be smart with the SetupDixxx calls and re-enumerate all devices within a specified device class inside the DEVNODES_CHANGED event. I can probably retrieve some parameters against each device which gives me their operational state. Hmmm, some investigating to do on MSDN.

    Thanks again for your help,

    Kev

    Friday, August 20, 2010 7:36 PM
  • Hi Dev,

    I have a same problem as you had with USB device, did you find any solutions?

    My sample application is able to detect USB device arrivales and removal(DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE) messages, by overriding the WndProc procedure based on WM_DEVICECHANGE. Ehwn the USB device is connected to the OC, most of the time it enumerates properly and the rest of time whonows pops up a "Unknown Device" or USB device not recognized" messages. What I am seeing so far is that in WndProc, when a device fails to enumerate I get a DBT_DEVNODES_CHANGED event yet no information which comes with this event informs me of an unsuccessfull connection.

    Any suggestion?

    please help me.

    Bob

    Monday, June 11, 2012 9:02 PM