网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月02日漏签0天
嵌入式吧 关注:98,709贴子:417,548
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 0回复贴,共1页
<<返回嵌入式吧
>0< 加载中...

为什么要进行if (fcntl(fd,F_SETFL,0)<0)的判断?求解,谢谢!

  • 只看楼主
  • 收藏

  • 回复
  • 潜龙赋
  • 启动代码
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
int uart_port_open(int com_port)//打开相应的uart端口(0~4中的一个),返回值为fd
{
int fd;
char device[20];
#if 0
//char *dev[]={"/dev/ttyO1","/dev/ttyO2","/dev/ttyO3","/dev/ttyO4","/dev/ttyO5"};
if ((com_port < 0)||(com_port > MAX_COM_NUM))
{
return -1;
}
fd = open(dev[com_port],O_RDWR|O_NOCTTY);//|O_NDELAY);
#endif
sprintf(device,"/dev/ttyO%d",com_port);
if ((com_port < 0)||(com_port > MAX_COM_NUM))
{
return -1;
}
fd = open(device,O_RDWR|O_NOCTTY);
if(fd<0)
{
printf("open serial port failed\n");
return -1;
}
/*restore the serial port blocking state,wait for the readed data of the uart*/
if (fcntl(fd,F_SETFL,0)<0) //set the flag of file status,and set access module//设置为阻塞模式
{
printf("open fcntl F_SETFL failed\n" );
}
/*test whether is the terminal device*/
if (isatty(STDIN_FILENO) == 0)
{
printf("standaed input is not a terminal device");
}
return fd;
}
可以不进行判断吗?为什么要进行判断?


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 0回复贴,共1页
<<返回嵌入式吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示