locked
Strange FTDI device detection RRS feed

  • Question

  • Hi!

    I am developing an mfc app which needs to recognise the insertion and removal of a FTDI chip (USB to UART) based device via USB.

    I use the functions provided by FTDI in a .dll file to check the device serial number etc.

    If the device is connected before i lunch the application everything is fine, i can get the data i need from the chip, so the functions are working. But if i lunch the application first and then plug the device i dont get data sometimes. Usually after three times plug-unplug i can not reach the chip but this is also happened for the first or second insertion to got nothing.

    So i thing i have made something wrong about registering the device notificiation or about handling the messages.

    My code snippets,

    for registering:

    DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
    ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
    NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    NotificationFilter.dbcc_classguid = GuidInterfaceList;
    NotificationFilter.dbcc_size = sizeof(NotificationFilter);
    NotificationHandle = RegisterDeviceNotification(GetSafeHwnd(),&NotificationFilter,DEVICE_NOTIFY_WINDOW_HANDLE);

    where the class guid is the FTDI_D2XX_Device Class GUID, {0x219d0508,0x57a8,0x4ff5,{0x97, 0xa1, 0xbd, 0x86, 0x58, 0x7c, 0x6c, 0x7e}} only. For the handler:

    BOOL MyDlg::OnDeviceChange(UINT EventType, DWORD dwData)
    {
        switch((int)EventType)
        { 
        case DBT_DEVICEARRIVAL:
            // check device etc.
        case DBT_DEVICEREMOVECOMPLETE:
            // check device etc.
        }
    
        return TRUE;
    }

    The notification request got unregistered when the application quits.

    During debugging i noticed, that after the DBT_DEVNODES_CHANGE notification i get the DBT_DEVICEARRIVAL twice at insertion and DBT_DEVICEREMOVECOMPLETE twice at removal. This is also the situation with an example app downloaded from ftdi. If i use one more class guid for instance the Human Interface Device Class GUID, i got 4 messages/notifications.

    I tried several ftdi functions, class guid but did not help. Any idea?

    Thanks,

    Overshoot


    Tuesday, January 20, 2015 9:37 PM

Answers

  • you need to register the device interface guid. the device class guid (the same one that shows up in the INF at the top) is not the same. the device class guid controls the UI icon in device manager. once you register for the device interface guid, you will receive messages upon its arrival. you would then open a handle and then register for file handle notifications on that handle.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, January 20, 2015 9:56 PM

All replies

  • you need to register the device interface guid. the device class guid (the same one that shows up in the INF at the top) is not the same. the device class guid controls the UI icon in device manager. once you register for the device interface guid, you will receive messages upon its arrival. you would then open a handle and then register for file handle notifications on that handle.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, January 20, 2015 9:56 PM
  • Thanks Mr. Holan!

    I have tried register different interfaces (usb raw device, com port) but nothing special. I still get notifications every time arrival,removal but sometimes the device responds nothing. So the code runs that has to run at insertion or removal, but the imported .dll functions not always return the information i want. It is random.

    By the way in an application note provided by FTDI, they register two interface class guids and three device class guids. All the same problems rises if i do like they do.

    Overshoot

    Wednesday, January 21, 2015 4:45 PM
  • It seems that i have found what the problem was.

    The application should communicate through only one of the interfaces: d2xx driver, virtual com port.

    If i disable the loading of the VCP it can not confuse the insertion or removal process i think.

    Wednesday, January 21, 2015 10:22 PM