Gets and sets input and output baud rates.
Standard C Library (libc.a)
#include <termios.h>
speed_t cfgetospeed ( TermiosPointer)
const struct termios *TermiosPointer;
int cfsetospeed (TermiosPointer, Speed)
struct termios *TermiosPointer;
speed_t Speed;
speed_t cfgetispeed (TermiosPointer)
const struct termios *TermiosPointer;
int cfsetispeed (TermiosPointer, Speed)
struct termios *TermiosPointer;
speed_t Speed;
The baud rate subroutines are provided for getting and setting the values of the input and output baud rates in the termios structure. The effects on the terminal device described below do not become effective and not all errors are detected until the tcsetattr function is successfully called.
The input and output baud rates are stored in the termios structure. The supported values for the baud rates are shown in the table that follows this discussion.
The termios.h file defines the type speed_t as an unsigned integral type.
The cfgetospeed subroutine returns the output baud rate stored in the termios structure pointed to by the TermiosPointer parameter.
The cfsetospeed subroutine sets the output baud rate stored in the termios structure pointed to by the TermiosPointer parameter to the value specified by the Speed parameter.
The cfgetispeed subroutine returns the input baud rate stored in the termios structure pointed to by the TermiosPointer parameter.
The cfsetispeed subroutine sets the input baud rate stored in the termios structure pointed to by the TermiosPointer parameter to the value specified by the Speed parameter.
Certain values for speeds have special meanings when set in the termios structure and passed to the tcsetattr function. These values are discussed in the tcsetattr subroutine.
The following table lists possible baud rates:
Name | Description |
---|---|
B0 | Hang up |
B5 | 50 baud |
B75 | 75 baud |
B110 | 110 baud |
B134 | 134 baud |
B150 | 150 baud |
B200 | 200 baud |
B300 | 300 baud |
B600 | 600 baud |
B1200 | 1200 baud |
B1800 | 1800 baud |
B2400 | 2400 baud |
B4800 | 4800 baud |
B9600 | 9600 baud |
B19200 | 19200 baud |
B38400 | 38400 baud |
The termios.h file defines the name symbols of the table.
Item | Description |
---|---|
TermiosPointer | Points to a termios structure. |
Speed | Specifies the baud rate. |
The cfgetospeed and cfgetispeed subroutines return exactly the value found in the termios data structure, without interpretation.
Both the cfsetospeed and cfsetispeed subroutines return a value of 0 if successful and -1 if unsuccessful.
To set the output baud rate to 0 (which forces modem control lines to stop being asserted), enter:
cfsetospeed (&my_termios, B0);
tcsetattr (stdout, TCSADRAIN, &my_termios);