Hello, 



I take your example serial_read.c and i just want to show data by a printf 
function. 

But,  i have a problem with libftdi. That is to say, i receive data but when 
i look all bytes as 00! 

Obviousely, it is wrong, the packet size is 38, but not 
000000000000000000000000000... 

I use an USB modem 802.15.4 (DIGI xstick). 



Have you an idea for my problem? 



Please, i search from 2 weeks about this bug..., may you help me? 



Best regards. 

M. DORIGNY Robert 

Montigny le bretonneux 

France  



> root@D2Plug:/travail # gcc serial_read2.c -lftdi 
> root@D2Plug:/travail # ./a.out 
> read 1 bytes 
> 00 
> 00 
> read 38 bytes 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> read 38 bytes 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> read 38 bytes 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> read 38 bytes 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> 0000000000000000000000000000000000000000000000000000000000000000000000000000 
> 







/* serial_read.c 

   Read data via serial I/O 

   This program is distributed under the GPL, version 2 
> */ 

#include <stdio.h> 
> #include <unistd.h> 
> #include <getopt.h> 
> #include <ftdi.h> 

int main(int argc, char **argv) 
> { 
>     struct ftdi_context ftdic; 
>     char buf[128]; 
>     int f, i , j; 
>     int vid = 0x0403; 
>     int pid = 0x6001; 
>     int baudrate = 115200; 
>     int interface = INTERFACE_ANY; 

    while ((i = getopt(argc, argv, "i:v:p:b:")) != -1) 
>     { 
>         switch (i) 
>         { 
>  case 'i': // 0=ANY, 1=A, 2=B, 3=C, 4=D 
>   interface = strtoul(optarg, NULL, 0); 
>   break; 
>  case 'v': 
>   vid = strtoul(optarg, NULL, 0); 
>   break; 
>  case 'p': 
>   pid = strtoul(optarg, NULL, 0); 
>   break; 
>  case 'b': 
>   baudrate = strtoul(optarg, NULL, 0); 
>   break; 
>  default: 
>   fprintf(stderr, "usage: %s [-i interface] [-v vid] [-p pid] [-b 
> baudrate]\n", *argv); 
>   exit(-1); 
>         } 
>     } 

    // Init 
>     if (ftdi_init(&ftdic) < 0) 
>     { 
>         fprintf(stderr, "ftdi_init failed\n"); 
>         return EXIT_FAILURE; 
>     } 

    // Select first interface 
>     ftdi_set_interface(&ftdic, interface); 

    // Open device 
>     f = ftdi_usb_open(&ftdic, vid, pid); 
>     if (f < 0) 
>     { 
>         fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, 
> ftdi_get_error_string(&ftdic)); 
>         exit(-1); 
>     } 

    // Set baudrate 
>     f = ftdi_set_baudrate(&ftdic, 115200); 
>     if (f < 0) 
>     { 
>         fprintf(stderr, "unable to set baudrate: %d (%s)\n", f, 
> ftdi_get_error_string(&ftdic)); 
>         exit(-1); 
>     } 
>   
>     char * adr; 
>   
>     // Read data forever 
>     while ((f = ftdi_read_data(&ftdic, buf, sizeof(buf))) >= 0) { 
>      if (f!=0) 
>           {   
>     fprintf(stderr, "read %d bytes\n", f); 
>     //printf("%s",buf); 
>     for (j=0;j<f;j++) 
>       printf("%02x",buf[j]); 
>     printf("\n"); 
>     
>     adr=&buf[0]; 
>     for (j=0;j<f;j++) 
>       { 
>    printf("%02x",*adr); 
>    adr++; 
>    }    
>     printf("\n"); 
>     
>        fwrite(buf, f, 1, stdout); 
>        fflush(stderr); 
>        fflush(stdout); 
>     } 
>     } 

    ftdi_usb_close(&ftdic); 
>     ftdi_deinit(&ftdic); 
> } 
> 






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

Reply via email to