| Simon Elliott 2005-08-02, 7:51 am |
| On 01/08/2005, Floyd L. Davidson wrote:
>
> Here is an excellent tutorial on POSIX serial port programming,
>
> http://www.easysw.com/~mike/serial/serial.html
I'd already found this one...
> Here are some coding examples on my own web page,
>
> http://www.apaflo.com/floyd_davidson/code/terminal/
.... but hadn't seen this one. I like the way you've set up your serial
configuration with a set of #defines at the top: neatly keeps it all
together.
> Specifically, to turn on/off CTS/RTS flow control by setting or
> unsetting the CRTSCTS bits in the c_cflag member of the termios
> struct:
>
> int hw_flowcontrol(int fd, int onoff)
> {
> struct termios tty;
>
> tcgetattr(fd, &tty);
>
> if (onoff) {
> tty.c_cflag |= CRTSCTS; /* enable flowcontrol*/
> } else {
> tty.c_cflag &= ~CRTSCTS; /* disable flowcontrol*/
> }
>
> return tcsetattr(fd, TCSANOW, &tty);
> }
Thanks for this. I wonder why POSIX has options for XON/XOFF but not
for RTS/CTS.
[vbcol=seagreen]
.... or maybe I still don't! It seems that CLOCAL and CRTSCTS are
incompatible options. In the termios(3) man page:
CLOCAL Ignore modem control lines.
CRTSCTS (not in POSIX) Enable RTS/CTS (hardware) flow control.
Fair enough, I can see why these are mutually exclusive options. But in
Michael Sweet's guide:
"The c_cflag member contains two options that should always be enabled,
CLOCAL and CREAD. These will ensure that your program does not become
the 'owner' of the port subject to sporatic job control and hangup
signals, and also that the serial interface driver will read incoming
data bytes."
What if I want my program to not become the owner of the port, not be
hit by signals such as SIGHUP, but I do want RTS/CTS flow control?
--
Simon Elliott http://www.ctsn.co.uk
|