Hi,

I'm trying to get ftdi_readstream() working but must have some fundamental 
misunderstanding.


I'd like it to work in the background (or in another thread) and simply parse 
data while I am free to use ftdi_write_data() to send commands to my 
application.


I declare a handler that simply prints data to the console:


static int readcallback(uint8_t *buffer, int length, FTDIProgressInfo 
*progress, void *userdata)
{
    int i;
    printf("callback! %d\n", length);
    if (length) {
       for (i = 0; i < length; i ++) {
          printf("%d 0x%2x\n", i, buffer[i]);
       }
    }
    return (exitRequested ? 1 : 0);
}



Then I register the callback:


 err = ftdi_readstream(&ftdic, readcallback, NULL, 8, 256);
  printf("error: %d\n", err);
  if (err < 0 && !exitRequested) {
        exit(1);
 }

ftdi_readstream() never returns.  I was expecting it to create a separate 
thread, and asynchronously handle incoming data.  I expected that I could set 
it up and then start using ftdi_write_data() to send control requests to my  
application.

Digging a little deeper, I can determine that my readcallback() routine gets 
called continuously at high speed with length=0.

Do I have to start readcallback() in it's own thread myself?

I am also unclear on the purpose of the 8,256 arguments.  I thought it should 
get a callback on every transfer.  Do the 8,256 arguments bundle these up into 
larger chunks?  Can I set them to be 1,1 for minimal latency?

Everything works fine if I simply do ftdi_write_data() followed by 
ftdi_read_data() in a while(1) loop.  I'd just like to increase efficiency by 
making reads happen in the background.

kind regards,
--
Rick Walker




--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   

Reply via email to