4

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 not enough.

How can I get the device number (/dev/ttyUSBXX) or bus or port with this API.

thanks

Federico
  • 3,782
  • 32
  • 46
GLampros
  • 121
  • 1
  • 8
  • Have no idea what you are talking about, though in Linux kernel you have different APIs to access to USB serial device: a) TERMIOS which works directly on */dev/ttyXYZ* nodes, and b) USB IOCTL (libusb). – 0andriy Nov 11 '15 at 19:16
  • Hello. I will explain here with more details. I connect two _FTDI_ boards with usb each of which has two devices. So from _dmesg_ I get: `usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0 usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB1 usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB2 usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB3 `. When I call the D2XX API I also get four devices but it doesn't give me which device is ttyUSB1, which is ttyUSB2 e.t.c. It only gives me locid, serialnumbers and descriptions. – GLampros Nov 12 '15 at 10:19
  • So, in a few words I want to assign, ttyUSB0, ttyUSB1, ttyUSB2, ttyUSB3 to the devices I get from D2XX API (I use the FT_GetDeviceInfoDetail function) – GLampros Nov 12 '15 at 10:29
  • I have no idea what D2XX API means. Linux kernel seems to work here. – 0andriy Nov 14 '15 at 15:26
  • 1
    After some search I think that technically there is no solution for my problem. Anyway, FYI: Linux Kernel loads automatically VCP driver (ftdi_sio) when you plug in an FTDI chip. There is an other driver from the same company (D2XX) and this is which I use. These two drivers are incompatible. So, I have to unload (rmmod) ftdi_sio in order to use D2XX. [Linux ftdi_sio](http://www.ftdichip.com/Support/Documents/AppNotes/AN_220_FTDI_Drivers_Installation_Guide_for_Linux%20.pdf) [D2XX API](http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer's_Guide(FT_000071).pdf) – GLampros Nov 16 '15 at 10:05
  • It's pity that the official guide for Linux only offers the way to remove module (by `rmmod` command). However I've managed to solve this problem in a more sophisticated way as it shown on my [answer](http://stackoverflow.com/a/43514662/7893951). – Akira May 12 '17 at 04:55

1 Answers1

13

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.

paulmk
  • 3
  • 3
Akira
  • 4,385
  • 3
  • 24
  • 46
  • Author asks about getting device name for the FTDI device, you described something but nothing about author asks to. – borune Apr 04 '20 at 17:58
  • @borune, I actually described how the author will be able to use the D2XX driver at all. Until this is done, the device name cannot be obtained. Also there is the function that can be used to get the name of the device, among other things. – Akira Apr 04 '20 at 23:11
  • you propose to use FT_GetDeviceInfoDetail function for getting device filename. But this function doesn't provide that information. Read the description before advising https://www.ftdichip.com/Support/Knowledgebase/index.html?ft_getdeviceinfodetail.htm – borune Apr 06 '20 at 07:55
  • I found these instructions very helpful. – Richard W Feb 10 '21 at 18:25