Hardware Reference
In-Depth Information
Use the
tcgetattr(3)
function to fetch the current serial device settings:
int tcgetattr(int fd, struct termios *termios_p);
where
fd
is the open TTY file descriptor.
termios_p
is the struct to be filled with current setting information.
struct termios term;
int rc;
rc = tcgetattr(fd,&term);
if ( rc < 0 ) {
perror("tcgetattr(3)");
tcsetattr(3)
When the
termios
structure has been defined with the serial parameters you wish to use,
the
tcsetattr(3)
call is used to set them in the device driver:
int tcsetattr(
int fd,
int optional_actions,
const struct termios *termios_p
);
where
fd
is the open TTY file descriptor to change.
optional_actions
is one of three actions (listed in the following table).
termios_p
is a pointer to the new settings to be applied.
The three choices for
optional_actions
are as follows:
optional_actions
Meaning
TCSANOW
The change occurs immediately.
TCSADRAIN
Change occurs after all output has been sent.
TCSAFLUSH
As TCSADRAIN, but pending input is discarded.