Re: serial port question.
- From: chris dewbery <chris.dewbery@xxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 09:40:30 +1200
And I was successfully able to send and recieve an unsigned character
array of 255 chars. (from 00 to FF) However, I was only able to do so
by sending and receiving one byte at a time. I have been unable to
accurately send and receive more then 6 - 7 bytes at one time
what do you mean when you say "I have been unable to accurately send and receive" ?
Are you receiving corruption or an error message?
here is a snippet of code which sets the serial port to
19200 8E1. where fd is the file descriptor for the open serial port.
int fd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY );
struct termios options;
memset(&options, 0, sizeof( struct termios ) );
/* set baud rate to 19200 */
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD; /* Even parity */
options.c_cflag &= ~CSTOPB; /* 1 Stop bit */
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8; /* 8 data bits */
options.c_cflag &= ~CRTSCTS;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag |= (IGNPAR); /* Ignore parity */
options.c_iflag &= ~(IXON | IXOFF | IXANY);
tcsetattr(fd, TCSANOW, &options);
tcflush( fd, TCIOFLUSH );
you should then be able to just send and receive data by using the
commands.
write( fd, buffer, length );
bytes = read( fd, buffer, sizeof(buffer));
hope this helps :)
.
- Follow-Ups:
- Re: serial port question.
- From: Floyd L. Davidson
- Re: serial port question.
- References:
- serial port question.
- From: Chris . Reath
- serial port question.
- Prev by Date: Re: Warning
- Next by Date: Re: serial port question.
- Previous by thread: Re: serial port question.
- Next by thread: Re: serial port question.
- Index(es):
Relevant Pages
|