Re: serial port question.
- From: chris dewbery <chris.dewbery@xxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 11:25:46 +1200
int fd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY );
For portability, O_NONBLOCK is preferred over O_NDELAY. They
are exactly identical on Linux (and most other systems), but
have subtle differences on some platforms that make O_NDELAY
non-portable.
well you learn something new every day. i will use O_NONBLOCK from now on :)
well yes, there is a truck load of redundant code andoptions.c_cflag |= (CLOCAL | CREAD);
Why use an OR function, when you know that the initial value
is 0?
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD; /* Even parity */
options.c_cflag &= ~CSTOPB; /* 1 Stop bit */
options.c_cflag &= ~CSIZE;
Why clear bits, when the initial value is 0?
options.c_cflag |= CS8; /* 8 data bits */
options.c_cflag &= ~CRTSCTS;
All of the above can be a one liner:
options.c_cflag = (CLOCAL | CREAD | CS8 | PARENB);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag |= (IGNPAR); /* Ignore parity */
Why enable parity and then ignore it on input?
options.c_iflag &= ~(IXON | IXOFF | IXANY);
tcsetattr(fd, TCSANOW, &options);
This call really should be checked for an error return.
tcflush( fd, TCIOFLUSH );
un-handled return values. I agree with and thank you for your comments
however i was merely posting this as a quick example to the OP
in an attempt to probe for extra information about the problem.
not to be the be-all end-all of solutions. :)
.
- References:
- serial port question.
- From: Chris . Reath
- Re: serial port question.
- From: chris dewbery
- Re: serial port question.
- From: Floyd L. Davidson
- serial port question.
- Prev by Date: Re: serial port question.
- Next by Date: Re: serial port question.
- Previous by thread: Re: serial port question.
- Next by thread: Re: Warning
- Index(es):
Relevant Pages
|