This code appears to work:
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/poll.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <aio.h>
int openPort()
{
struct termios oldtio, newtio;
int fd = open("/dev/ttyUSB0",O_RDWR|O_NOCTTY);
if (fd == -1)
{
printf( "could not open tty" );
return -1;
}
if ( tcgetattr( fd, &oldtio ) == -1 )
{
printf( "error getting tcattr\n" );
close( fd );
return -1;
}
//newtio = oldtio;
//cfmakeraw( &newtio );
cfsetispeed( &newtio, B9600 );
cfsetospeed( &newtio, B9600 );
newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS8 | B9600;
newtio.c_cflag |= (CLOCAL | CREAD);
newtio.c_cflag &= ~(PARENB | PARODD);
newtio.c_cflag &= ~CRTSCTS;
newtio.c_cflag &= ~CSTOPB;
newtio.c_iflag = IGNPAR;
//newtio.c_iflag &= ~(IXON | IXOFF | IXANY);
newtio.c_lflag = IEXTEN;
newtio.c_oflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;
tcflush( fd, TCIOFLUSH );
if ( tcsetattr( fd, TCSANOW, &newtio ) == -1 )
{
close( fd );
printf( "error setting attrs\n" );
return -1;
}
return fd;
}
int main( int n, char ** v )
{
int fd = openPort();
if (fd == -1)
return 0;
struct aiocb aiocb;
memset( &aiocb, 0, sizeof(aiocb) );
char buffer[32];
aiocb.aio_fildes = fd;
aiocb.aio_buf = buffer;
aiocb.aio_nbytes = 1;
aiocb.aio_lio_opcode = LIO_READ;
while(1)
{
aio_read( &aiocb );
while( aio_error( &aiocb ) == EINPROGRESS )
{
usleep( 10000 );
}
int n = aio_return( &aiocb );
for( int i = 0; i < n; ++i )
{
putchar( buffer[i] );
}
fflush( stdout );
}
return 0;
}
--
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.