Why can't I access my FTDI device using D2XX on a Raspberry Pi?

岁酱吖の 提交于 2019-12-08 03:59:52

问题


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:

  • I downloaded the 1.3.6 ARMv6 hard-float version of the driver (which states that it is suitable for a Raspberry Pi), and then followed the Readme instructions to install it into the /usr/local/lib folder
  • I ran the sudo rmmod ftdi_sio and sudo rmmod usbserial commands as advised to unload the default kernel driver
  • In my program, the first thing I do is invoke the FT_SetVIDPID function so that it is properly configured for my particular device
  • In my program, I can verify that there is 1 device plugged in via the FT_CreateDeviceInfoList function

However, 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?


回答1:


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.



来源:https://stackoverflow.com/questions/42375995/why-cant-i-access-my-ftdi-device-using-d2xx-on-a-raspberry-pi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!