FTDI Community

General Category => Discussion - Drivers => Topic started by: MauroDiamantino on April 24, 2019, 10:25:15 PM

Title: Unexpected behavior of timeout
Post by: MauroDiamantino on April 24, 2019, 10:25:15 PM
Hello, I'm working with a device which communicates with a PC using a FTDI chip and I found an unexpected behavior when I set up timeout and then I tried to read data from the device. The device is a Aaronia spectrum analyzer which utilizes a FTDI 232R chip. The PC is a Raspberry Pi 3B+ with Raspbian which I installed the D2XX driver (version 1.4.8 ARMv6). The problem arose when I set up the timeout values and then I tried to read data from the device. I decided to set it up to 10 seconds initially and then reduce it many times up to the minimum possible value which allows a correct operation. With the initial value (10s) I tried to read data from the device and I got error messages which stated no bytes were read. After many tries to solve the problem changing the read timeout, I  managed to solve it adding a call to "usleep" function with 200000 (200ms) as argument before the reading operation, so I found the reading function was not blocking to wait the data during the timeout. I tried the same operation in my notebook HP 14-an020la with Debian 4.9.130-2 and I got the same result.
What could it be the error? Am I correctly understanding the timeout?
Title: Re: Unexpected behavior of timeout
Post by: FTDI Community on April 26, 2019, 03:29:50 PM
Hello,

Have a look at our Data Throughput, Latency & Handshaking Application Note where you will find some information:

https://www.ftdichip.com/Support/Documents/AppNotes/AN232B-04_DataLatencyFlow.pdf (https://www.ftdichip.com/Support/Documents/AppNotes/AN232B-04_DataLatencyFlow.pdf)

Our USB Data Transfer Efficiency Technical Note may also be of use as it looks at the factors influencing the efficiency of data transfer for FTDI devices:
 
https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_103_FTDI_USB_Data_Transfer_Efficiency(FT_000097).pdf (https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_103_FTDI_USB_Data_Transfer_Efficiency(FT_000097).pdf)

In addition have a look at this Application Note on Optimizing D2XX Data Throughput:
 
https://www.ftdichip.com/Support/Documents/AppNotes/AN232B-03_D2XXDataThroughput.pdf (https://www.ftdichip.com/Support/Documents/AppNotes/AN232B-03_D2XXDataThroughput.pdf)

Regards,
FTDI Community
Title: Re: Unexpected behavior of timeout
Post by: MauroDiamantino on August 13, 2019, 04:09:08 PM
Hello, thanks you a lot for the documents you shared with me. I apologize for not having replied before. I read all documents and I got the conclusion that to improve the data transfer performance the user application should transfer through USB interface the biggest quantity of data at once, the latency timer should be set in a big value so this one does not interrupt the transferring, the USB IN and OUT request sizes should be set to big values and, ideally, the number of bytes requested by the user application should be an integer multiple of the number of data bytes in an USB IN transfer request.

I followed those rules but, painfully, I did not get good results, the application got frozen when I tried to read a lot of data at once. So, I decided to set up the FTDI chip following the recommendations for data transferring of small numbers of bytes, i.e. I set up the latency timer in the smallest value, 2 ms, and I modified the user application to request small number of bytes at once. And I got a little bit performance improvement with that configuration.

On the other hand, I analyzed the data transfer rate of the RS232 interface and I realized the maximum baud rate is 921600 bits/s (taking into account the constants defined in the header file ftd2xx.h) which is much smaller than the typical baud rates which are offered by the USB interface. Can I use a bigger baud rate of the RS232 interface? Will that produce data missing, taking into account I am not using flow data control?