简体   繁体   中英

Why does this FTDI function return zero for the fthandle?

I have a FTDI USB3 development board and some FTDI provided code for accessing it. The code works fine for things like the Device number, VID/PID etc. but always returns zero for the 'ftHandle'. As the handle is required for driving the board, this is not helpful? Can anyone see why this should happen?

   static FT_STATUS displayDevicesMethod2(void)
   {
    FT_STATUS   ftStatus;
    FT_HANDLE   ftHandle = NULL;

    // Get and display the list of devices connected
    // First call FT_CreateDeviceInfoList to get the number of connected devices.
    // Then either call FT_GetDeviceInfoList or FT_GetDeviceInfoDetail to display device 
   info.
    // Device info: Flags (usb speed), device type (600 e.g.), device ID (vendor, 
 product), 
    handle for subsequent data access.
    DWORD numDevs = 0;
    ftStatus = FT_CreateDeviceInfoList(&numDevs);   // Build a list and return number 
    connected.
    if (FT_FAILED(ftStatus))
    {
        printf("Failed to create a device list, status = %d\n", ftStatus);
    }
    printf("Successfully created a device list.\n\tNumber of connected devices: %d\n", 
    numDevs);
    // Method 2: using FT_GetDeviceInfoDetail
    if (!FT_FAILED(ftStatus) && numDevs > 0)
    {
        ftHandle = NULL;
        DWORD Flags = 0;
        DWORD Type = 0;
        DWORD ID = 0;
        char SerialNumber[16] = { 0 };
        char Description[32] = { 0 };
        for(DWORD i = 0; i <numDevs; i++)
        {
            ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, NULL, SerialNumber, 
    Description, &ftHandle);
            if (!FT_FAILED(ftStatus))
            {
                printf("Device[%d] (using FT_GetDeviceInfoDetail)\n", i);
                printf("\tFlags: 0x%x %s | Type: %d | ID: 0x%08X | ftHandle=0x%p\n",
                    Flags,
                    Flags & FT_FLAGS_SUPERSPEED? "[USB 3]":
                    Flags & FT_FLAGS_HISPEED? "[USB 2]":
                    Flags & FT_FLAGS_OPENED? "[OPENED]": "",
                    Type,
                    ID,
                    ftHandle);
                printf("\tSerialNumber=%s\n", SerialNumber);
                printf("\tDescription=%s\n", Description);
            }
         }
      }
    return ftStatus;
    }

This is indeed not super straight forward, but a short peek in the FTDI Knowledgebase yields:

This function builds a device information list and returns the number of D2XX devices connected to the system. The list contains information about both unopen and open devices.

A handle only exists for an opened device. Thus, I assume that your code does not already include that step. If so you need to open it first, eg using FT_Open. There are plenty of examples available. You can check their page or stackoverflow for a working example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM