FTDI FT_Read from usb lag
Alec Jacobson
December 21, 2012
Yesterday, we hunted down a problem using FTDI's D2XX drivers on my mac that was causing reading from our device to lag unevenly. We timed our reading routines and couldn't find where we were losing framerate. Finally we found two issues, both fixed by changing parameters immediately after opening the device:
Originally we had
FT_SetTimeouts(ftHandle, 100, 100);
And we should have had
FT_SetTimeouts(ftHandle, 1, 1);
This function controls the maximum wait time during any call to FT_Read and FT_write.
Finally, the major cause of the lag was the absence of the following:
FT_SetUSBParameters(ftHandle, 64,64))
This defines the amount of data read and written each time from and to the device in bytes. It seems the default values were 4096 bytes. Our device sends a small amount of data at high frequency, so this number was way to high and was the major bottleneck causing the lag.