I'm trying to make use of FTDI's D2XX drivers to access a USB-Serial device on a Raspberry Pi 3. Here's what I've done so far:
sudo rmmod ftdi_sio
and sudo rmmod usbserial
commands as advised to unload the default kernel driverFT_SetVIDPID
function so that it is properly configured for my particular deviceFT_CreateDeviceInfoList
functionHowever, in my program, trying to call FT_Open
consistently fails with FT_DEVICE_NOT_FOUND
(2). I'll copy the program here for reference:
#include <stdio.h>
#include "ftd2xx.h"
int main(int argc, char[] argv)
{
FT_HANDLE ftHandle;
FT_STATUS ftStatus;
int iNumDevs = 0;
ftStatus = FT_SetVIDPID(0x0403, 0x6015);
if (FT_OK != ftStatus)
{
printf("Error: FT_SetPIDVID(%d)\n", (int)ftStatus);
return 1;
}
ftStatus = FT_CreateDeviceInfoList(&iNumDevs);
if (FT_OK != ftStatus)
{
printf("Error: FT_CreateDeviceInfoList(%d)\n", (int)ftStatus);
return 1;
}
printf("Devices: %d\n", iNumDevs);
ftStatus = FT_Open(0, &ftHandle);
if (FT_OK != ftStatus)
{
printf("Error: FT_Open(%d)\n", (int)ftStatus);
return 1;
}
// ...
return 0;
}
The output I get from this little program is consistent. It is always:
Devices: 1
Error: FT_Open(2)
I always build this program with:
gcc -lftd2xx -o test test.c
The fact that the first bit does say there is one connected device gives me hope that I can get this working. But basically any other function at all (FT_Open, FT_OpenEx, and even FT_ListDevices) fails with the same #2 error. What am I missing?
Since the FTDI D2XX drivers simply use libusb on the backend in order to actually talk with the device, you need to have the proper permissions in order to actually talk with it. The easiest way is to simply run the program under sudo
so that you will have full root permissions.
Alternatively, it should be possible to access the device as a non-root user if for some reason you are unable to run the program under sudo
.