Dear all,
I'm working on a way to read in data form ADCs to a PC via the UM245R.
It is working, but i could only achieve 630 KB/s compared to the
theoretical speed of the device (1MB/s with d2xx drivers). I'm
assuming that my code is inefficient, since I'm only a hobbist at
programming.
I'm using an Ubuntu 12.04, and my code is:
int main(int argc, char **argv)
{
int f=0;
float dif=0;
unsigned long int k=0;
time_t start,end;
bool run;
run=true;
struct ftdi_context ftdic;
if (ftdi_init(&ftdic) < 0)
{
fprintf(stderr, "ftdi_init failed\n");
return EXIT_FAILURE;
run=false;
}
if (ftdi_usb_open(&ftdic, 0x0403, 0x6001) < 0){
fprintf(stderr, "Can't open ftdi device \n");
run=false;}
if(ftdi_setflowctrl(&ftdic,SIO_RTS_CTS_HS) < 0)
fprintf(stderr,"Can't set flow control");
unsigned int size = 64*1024;
if (ftdi_read_data_set_chunksize(&ftdic,size)!=0){
fprintf(stderr, "Can't set chunksize \n");}
unsigned char buf[size];
if(run){
fprintf(stderr,"Press 'Enter' to start, and any key to stop");
while (getchar() != '\n')
;
time (&start);
}
while (run) {
f = ftdi_read_data(&ftdic, buf, sizeof(buf));
if (f < 0){
fprintf(stderr, "Error");
return f;
}
k=k+f;
if(kbhit())
run=false;
for (int i = 0; i < f; ++i) {
printf("0x%02X",buf[i]);
}
fflush(stdin) ;
}
time (&end);
dif = difftime (end,start);
fprintf(stderr,"Speed: %02f KB/sec\n", k/(dif*1024));
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
return 0;
}
Is there any (obvious) mistakes I made? Did anyone achieved 1MB/s with
an FT245R chip using libftdi?
Thanks in advance:
Daniel Balog
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|