libftdi Archives

Subject: Re: Checking for available bytes

From: Grzegorz Cieslewski <cieslewski@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 18 Jun 2009 08:23:24 -0400
Matthias,

I think I had a lot of similar issues. Did you try to use usb_reset() right after ftdi_usb_open().  It fixed all problems for me.

Grzegorz Cieslewski

On Thu, Jun 18, 2009 at 3:47 AM, Matthias Nagl <libftdi2009@xxxxxxxx> wrote:
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 libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx




--
=====================================================
Grzegorz Cieslewski                                                
Research Assistant                                                  
High-performance Computing & Simulation (HCS) Research Laboratory
University of Florida, Dept. of Electrical and Computer Engineering
330 Benton Hall, Gainesville, FL, 32611-6200            
Phone: (352) 392-9041                                                
Email: cieslewski@xxxxxxxxxxx                                        
Web: www.hcs.ufl.edu
=====================================================


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread