How can I get Linux device with FTDI D2XX driver API

前端 未结 1 521
攒了一身酷
攒了一身酷 2020-12-30 17:55

I am using FTDI D2XX driver API to communicate with a FTDI device. It gives me some information about the device like locid, serialnumber, description but it is no

相关标签:
1条回答
  • 2020-12-30 18:37

    As the D2XX Programmer's Guide tells in the Introduction:

    For Linux, Mac OS X (10.4 and later) and Windows CE (4.2 and later) the D2XX driver and VCP driver are mutually exclusive options as only one driver type may be installed at a given time for a given device ID.

    The problem is that your Linux may automatically loads the VCP driver (ftdi_sio) and therefore you cannot use D2XX driver. Type the following into your terminal to make sure, the ftdi_sio is loaded:

    sudo lsmod | grep -a "ftdi_sio"
    

    By this article I succesfully overcame the problem. My working solution is to create two text files under the /etc/udev/rules.d/. The first unbinds my device from the ftdi_sio driver and the second adjusts the permissions for my device. Let assume the first file which unbinds my device is named to 98-my-device.rules and has the following content:

    ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{product}=="FTDI Device",\
    PROGRAM="/bin/sh -c '\
        echo -n $id:1.0 > /sys/bus/usb/drivers/ftdi_sio/unbind;\
        echo -n $id:1.1 > /sys/bus/usb/drivers/ftdi_sio/unbind\
    '"
    

    Now let assume the second file which makes my device usable without root rights is named to 99-my-device.rules and has the following content:

    ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{product}=="FTDI Device",\
    MODE="0666"
    

    These rules will be active from the next restart or they can be applied by:

    sudo udevadm trigger
    

    The device's attributes (vendor id, product id and the product description) can be obtained by the sudo lsusb -v command but this will show too much information. You can filter the results with something like this:

    sudo lsusb -v | grep -a "Bus ... Device ...:\|idVendor\|idProduct\|iProduct"
    

    After you succesfully prevented the Linux to load the ftdi_sio driver for a specific device, you can use the D2XX API. To get informations from all connected devices try the example code of function FT_GetDeviceInfoDetail from the D2XX Programmer's Guide.

    0 讨论(0)
提交回复
热议问题