Thanks Nikolaus. Using /dev/ttyUSB0, the code from your link also produces 
spurious communications, receiving some characters but not others.

I should point out my posted code was for illustration only.

On Wednesday, 24 September 2014 14:34:03 UTC+1, Dr. H. Nikolaus Schaller 
wrote:
>
>
> Am 24.09.2014 um 13:42 schrieb Julian Gold <[email protected] 
> <javascript:>>:
>
> So I have been trying to write code to read data asynchronously from a 
> serial port. I have tried it with /dev/ttyO1 (using UART1), and also with 
> /dev/ttyUSB0 (using an FTDI USB cable in the USB port). 
>
> Here is a snippet of code. This fails on both serial ports, but in 
> different manners:
>
>
>     
> void readSerial( int fd )
> {
>     fd_set readfs;
>     FD_ZERO( &readfs );
>     FD_SET( fd, &readfs );
>     while( 1 )
>     {
>         select( fd+1, &readfs, 0, 0, 0 );
>         if (FD_ISSET( fd, &readfs ))
>         {
>             char buffer[32];
>             int n = read( fd, buffer, 32 );
>             printf( buffer ); fflush( stdout );
>         }
>      }
> }
>
>
> On /dev/ttyO1, the select() call blocks permanently, with no input being 
> acknowledged. On /dev/ttyUSB0, the function prints EVERY OTHER character, 
> so if I type "connect" into my PC terminal program, I will get either 
> "cnet" or "onc" depending on what came before. Either way, it appears 
> select() is broken because if I replace this with
>
> while((n= read(fd,buffer,32)) > 0)
> {
>    printf(buffer); fflush(stdout);
> }
>
> Then I get "connect" as expected on /dev/ttyUSB0 (untried as yet on 
> /dev/ttyO1). This seems like a fundamental problem with the Angstrom kernel?
>
>
> No. With your program logic. You do not process the return value of the 
> read() system call which might be 1..32.
> And, printf(buffer) is very dangerous. What would happen if you receive 
> the string "%sā€œ?
>
> Try this code:
>
>
> http://git.goldelico.com/?p=gta04-rootfs.git;a=blob;f=config/root/femtocom.c;h=7f15df363f384786fad084c1217d05d00a6746e3;hb=HEAD
>
> — hns
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to