termios的结构体
struct termios
{
unsigned int c_iflag; // 输入参数
unsigned int c_oflag; // 输出参数
unsigned int c_cflag; // 控制参数
unsigned int c_lflag; // 局部控制参数
unsigned char c_cc[NCCS];// 控制字符
unsigned int c_ispeed; // 输入波特率
unsigned int c_ospeed; // 输出波特率
}
int tcgetattr(int fd,struct termios *option);
功能:得到串口终端的属性值
参数:fd :由open函数返回的文件句柄
option :串口属性结构体指针,termios的结构体:
相关头文件: <unistd.h>、<termios.h>
int tcsetattr(int fd,int optact,const struct termios *option );
功能:设置串口终端的属性
参数:fd :由open函数返回的文件句柄
optact : 选项值,有三个选项以供选择:
TCSANOW: 不等数据传输完毕就立即改变属性
TCSADRAIN:等待所有数据传输结束才改变属性
TCSAFLUSH:清空输入输出缓冲区才改变属性
option :串口属性结构体指针。
相关头文件:<unistd.h>、<termios.h>
int cfsetispeed( struct termios *option, speed_t speed );
功能:设置串口的输入波特率
参数:option: 串口属性结构体指针
speed: 波特率,如:B115200表示波特率为115200
相关头文件: <unistd.h>、<termios.h>
int cfgetospeed( struct termios *option, speed_t speed );
功能:设置串口的输出波特率
参数:option : 串口属性结构体指针
speed : 波特率,如:B115200表示波特率为115200
相关头文件: <unistd.h>、<termios.h>
。。。。待续
参考资料:http://blog.youkuaiyun.com/guo_wangwei/archive/2006/08/21/1102931.aspx