termios系列函数-tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed等,用以获取/设置终端设备的属性/控制/速度。1. 函数声明
函数声明
#include #include /*获取文件描述符fd对应设备状态置入termios_p所指向结构体中*/
int tcgetattr(int fd, struct termios *termios_p);
/*设置文件描述符对应设备状态*/
int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
/*向fd发送0比特*/
int tcsendbreak(int fd, int duration);
/*挂起直到所有写入fd的输出全部发送完毕*/
int tcdrain(int fd);
/*丢弃所有准备写入但还未发送给fd的数据或从fd已接收但还还未被读取的数据*/
/*丢弃对象取决于queue_selector*/
int tcflush(int fd, int queue_selector);
/*挂起fd发送操作或接收操作,挂起对象取决于action*/
int tcflow(int fd, int action);
/*设备终端属性*/
void cfmakeraw(struct termios *termios_p);
/*返回termios_p所指向结构体中的输入波特率*/
speed_t cfgetispeed(const struct termios *termios_p);
/*返回termios_p所指向结构体中的输出波特率*/
speed_t cfgetospeed(const struct termios *termios_p);
/*设置termios_p所指向结构体中的输入波特率*/
int cfsetispeed(struct termios *termios_p, speed_t speed);
/*设置termios_p所指向结构体中的输出波特率*/
int cfsetospeed(struct termios *termios_p, speed_t speed);
/*4.4BSD扩展,设置输入输出波特率*/
int cfsetspeed(struct termios *termios_p, speed_t speed);
glibc功能测试宏定义:
cfsetspeed(), cfmakeraw(): _BSD_SOURCE2. termios结构体
大多数termios函数都会用到termios结构。termios结构体定义如下:
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150typedefunsignedcharcc_t;
typedefunsignedintspeed_t;
typedefunsignedinttcflag_t;
structtermios
{
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
speed_t c_ispeed; /* input speed */
speed_t c_ospeed; /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED