TERMIOS详解

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值