FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: Linux D2XX won't open by locationID  (Read 165 times)

BigApple

  • Newbie
  • *
  • Posts: 3
    • View Profile
Linux D2XX won't open by locationID
« on: July 14, 2020, 04:48:51 PM »

For some reason D2XX won't open a FT4232H device on Linux.  I'm using function calls FT_CreateDeviceInfoList(), FT_GetDeviceInfoList(), and FT_OpenEx() in the driver.

Here is the code which is based on an example:
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "../ftd2xx.h"

static void showVersion (DWORD locationID)
{
     FT_STATUS ftStatus;
     FT_HANDLE ftHandle = (FT_HANDLE) NULL;

     ftStatus = FT_OpenEx((PVOID)(uintptr_t)locationID, FT_OPEN_BY_LOCATION, &ftHandle);

     if (!FT_SUCCESS(ftStatus))
     {
          printf("FT_OpenEx failed (error %d)\n",
                 (int)ftStatus);

          return;
     }

     (void)FT_Close(ftHandle);
}

int main (void)
{
     FT_STATUS                 ftStatus;
     FT_DEVICE_LIST_INFO_NODE *devInfo = NULL;
     DWORD                     numDevs = 0;
     int                       retCode = 0;

     ftStatus = FT_CreateDeviceInfoList(&numDevs);

     if (!FT_SUCCESS(ftStatus))
     {
          printf("FT_CreateDeviceInfoList failed (error %d)\n",
                 (int)ftStatus);
          retCode = EXIT_FAILURE;
          goto exit;
     }

     if (numDevs == 0)
     {
          printf("No devices connected\n");
          retCode = EXIT_FAILURE+1;
          goto exit;
     }
     else
     {
          printf("Number of devices is %d\n", numDevs);
     }

     /* Allocate Storage */
     devInfo = calloc((size_t)numDevs, sizeof(FT_DEVICE_LIST_INFO_NODE));

     if (devInfo == NULL)
     {
          printf("Allocation failure.\n");
          retCode = EXIT_FAILURE+2;
          goto exit;
     }

     ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs);

     if (!FT_SUCCESS(ftStatus))
     {
          printf("FT_GetDeviceInfoList failed (error %d)\n",
                 (int)ftStatus);
          retCode = EXIT_FAILURE+3;
          goto exit;
     }


     for (int i=0; i<(int)numDevs; i++)
     {
          printf("Device[%d] Type is 0x%x\n",  i, devInfo[i].Type);
          printf("Device[%d] LocId is 0x%x\n", i, devInfo[i].LocId);
          printf("Device[%d] Flags is 0x%x\n", i, devInfo[i].Flags);
          showVersion(devInfo[i].LocId);
     }


exit:
     free(devInfo);
     return retCode;

}

Here is the output (x4):
Number of devices is 4
Device[0] Type is 0x3
Device[0] LocId is 0x0
Device[0] Flags is 0x1
FT_OpenEx() fails with error 2 (FT_DEVICE_NOT_FOUND).

A device info flags value of 1 seems to indicate that the device is already open.  Is that correct?

The error code from open function seems to indicate that the device was not found, which is a little confusing.

I unloaded the VCP driver as explained in
https://www.ftdichip.com/Support/Documents/AppNotes/AN_220_FTDI_Drivers_Installation_Guide_for_Linux.pdf

Code: [Select]
linux@linux-desktop:~$ sudo rmmod ftdi_sio
linux@linux-desktop:~$ sudo rmmod usbserial
linux@linux-desktop:~$ dmesg | grep ftdi
[13124.959002] usbcore: registered new interface driver ftdi_sio
[13124.959155] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[13124.962715] ftdi_sio 1-1.2:1.1: FTDI USB Serial Device converter detected
[13124.963148] ftdi_sio 1-1.2:1.2: FTDI USB Serial Device converter detected
[13124.965881] ftdi_sio 1-1.2:1.3: FTDI USB Serial Device converter detected
[13171.085880] ftdi_sio ttyUSB3: FTDI USB Serial Device converter now disconnected from ttyUSB3
[13171.086023] ftdi_sio ttyUSB2: FTDI USB Serial Device converter now disconnected from ttyUSB2
[13171.086336] ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1
[13171.087592] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[13171.087638] usbcore: deregistering interface driver ftdi_sio
[13171.087688] ftdi_sio 1-1.2:1.3: device disconnected
[13171.087751] ftdi_sio 1-1.2:1.2: device disconnected
[13171.087810] ftdi_sio 1-1.2:1.1: device disconnected
[13171.087868] ftdi_sio 1-1.2:1.0: device disconnected

Anyone see why the device isn't opening? :-\
Logged

BigApple

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Linux D2XX won't open by locationID
« Reply #1 on: July 14, 2020, 07:10:49 PM »

Could this be a result of the compiled libraries being in the wrong location?
Logged

BigApple

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Linux D2XX won't open by locationID
« Reply #2 on: July 14, 2020, 10:27:55 PM »

Solved: Running the program as 'sudo' fixed the issue.  Why that's required I'm not really sure.
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: Linux D2XX won't open by locationID
« Reply #3 on: July 15, 2020, 01:28:07 PM »

Hello,

The USB subsystem requires root user privileges to access on Linux, as a result the sudo command may be required.

Best Regards,
FTDI Community
Logged