For the sake of completeness: reducing the input buffer size to one byte and calling this in a loop solved the problem: unsigned char buffer; res = ftdi_read_data(&ftdi, buffer, 1);
Nevertheless an event-triggered callback solution would be a great feature. Greetings Matthias Am Donnerstag 18 Juni 2009 09:47:17 schrieb Matthias Nagl: > Hello Thomas, > > thanks for the reply. I also tried to poll in a thread that is independent > of other parts of my program but in this case the read-function seems not > to return after several new bytes (the number is smaller than the buffer > size) were received by the FT-chip. It returns the waiting bytes only after > new data has been sent to the chip. > > Is the "correct" solution to reduce the size of the buffer passed to the > read function in this way: > unsigned char buffer; > int ftdi_read_data(&ftdi, buffer, 1); > > or is there a more elegant/better way? > > Greetings > > Matthias > > Am Donnerstag 18 Juni 2009 09:27:23 schrieb Thomas Jarosch: > > Hello Matthias, > > > > On Wednesday, 17. June 2009 22:33:37 Matthias Nagl wrote: > > > I'm using libftdi to communicate with an AVR (via FT232R). To receive > > > bytes sent from the µC I am currently polling the FT with repeated > > > calls of ftdi_read_data() in a loop. However this method often doesn't > > > notice new bytes available before I send something downstream. Another > > > problem is that it blocks the calling thread which is also responsible > > > for sending commands (a nonblocking read function would be better in my > > > case). > > > > > > Is there a method to poll for the number of available bytes like > > > FT_GetStatus in the official D2XX-Driver? Or is there even an event > > > driven method (I think the ideal solution would be a callback-function, > > > that is automatically called after a newline has been received). As I > > > don't see any suitable methods I assume that this feature is not > > > available in libftdi (yet?). So my question is if it is possible / > > > makes sense considering the abilities of the FT hardware. > > > > AFAIK the D2XX-Driver uses threads to constantly poll the device > > for data in the background. So it's very easy to check for > > available bytes in the internal buffer. > > > > Maybe the new libusb 1.x API could be of help, > > though I haven't checked that yet. > > > > Cheers, > > Thomas > > > > > > -- > > libftdi - see http://www.intra2net.com/en/developer/libftdi for details. > > To unsubscribe send a mail to [email protected] > > -- > libftdi - see http://www.intra2net.com/en/developer/libftdi for details. > To unsubscribe send a mail to [email protected] -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to [email protected]
