This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB device insert/remove notification

Using USB with the tm4c eval kit, I have an MFC VC++ app that can detect the virtual com port usb insertion/removal events, which the device id shows USB along with the PID and all that is good.  However, unlike an FTDI board I'd used in the past which, along with the USB event, also gives a "Ports" device insert/remove event that identifies the port number that you can immediately use to process.  Without having this info, I need some way to identify the com port with just the USB event (since the tm4c ek doesn't provide a ports class event).  I've tried interrogating the registry for active serial comm ports, but it doesn't appear to interactively update as it still shows the removed port as active until a short time later.  I'm sure this has been discussed somewhere, but I haven't found anything in various searches.  Can anyone provide some assistance?  Summarizing, I just need to know what the com port is for that usb insert/remove event.

  • Your trouble of usbser.sys, Windows inbox VCP driver, is caused by its defect.
    MS clearly state that every serial driver, including VCP, should register its device interface to system with GUID_DEVINTERFACE_COMPORT.
    http://msdn.microsoft.com/en-us/library/windows/hardware/ff545821%28v=vs.85%29.aspx
    Most of VCP drivers, FTDI, SiLabs and Prolific, follow this rule, but usbser.sys doesn't register any device interface. If usbser.sys would register GUID_DEVINTERFACE_COMPORT, your PC application could get port WM_DEVICECHANGE message at attach/detach, like other VCP drivers.

    The workarounds are twofold,
    A) Application regularly polls the connection of target COM port.
    Here are two ways to list up VCP, specifying its VID/PID
    - Using WMI
    http://www.microchip.com/forums/FindPost/560699
    or
    - Using SetupDi-APIs
    http://www.microchip.com/forums/FindPost/365029

    B) Assign serenum.sys as a filter driver of usbser.sys.
    Modifying the INF file for usbser.sys, you may assign serenum.sys as its upper filter driver.
    You may import these sections from Windows\inf\msports.inf
    [SerialEnumerator.NT]
    [ComPort.NT.HW.AddReg]
    [SerialEnumerator.NT.Services]

    In your PC application, register GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR of serenum.sys for device notification, to get DBT_DEVICEARRIVAL / DBT_DEVICEREMOVECOMPLETE WM_DEVICECHANGE message.

    Tsuneo

  • @ Tsuneo,

    Sir - you are (indeed) a USB "treasure."  (both here & multiple other ARM/other forums - we note)

    As always - well introduced, superbly detailed - and even including (multiple) methods to "escape" user issues.

    Your work is noted and very much appreciated - thank you, Tsuneo!

  • Dear Sir,

    I am also facing similar type of problem. I am using TM4C123H6PZ device in my board. The USB is configured as VCP. It works fine when I restart the device, i.e data is received in the PC  (Serial terminal software). In between if I disconnect and connect the usb cable, the data is not getting received on the PC. 

    I am using "usbstdio" in buffered mode. When I disconnect the usb cable, I am getting USB_EVENT_DISCONNECTED in the control handler.

    I want to know whether any work around is there on device side because I dont have expertise in PC  software application development. 

    Thank you.

  • Thank you, Tsuneo!

    I have some good news about Windows 10. Seems that new usbser.sys registers GUID_DEVINTERFACE_COMPORT. My device is working with default drivers now. DBT_DEVICEREMOVECOMPLETE is also working.

    For the compatibility with Windows 7, where I used serenum.sys as an upper filter, I use now following code:

    const GUID guid[2] = {

    GUID_DEVCLASS_PORTS, // Windows 7

    GUID_DEVINTERFACE_COMPORT // Windows 10 or other VCP

    };

    for (int i=0; i<2; ++i) {

    HDEVINFO hDevInfoList = SetupDiGetClassDevs(&guid[i], NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));

    .....

    Dmitry