专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
NXP
问题:MQX中用read函数读串口时如何做超时机制(已解决)
2020-02-11 10:00
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
8045
29
29
本帖最后由 FSL_TICS_ZP 于 2014-6-17 09:10 编辑
我目前在用MQX中的串口,我发现如果用read函数来读取串口数据时,当对方不发数据给串口接收,那么read函数会死等,而且会将CPU占用不放,没有超时机制,而且在线程中死等,别的线程也开启不了,就连想提示一下错误也做不了!怎么样在不改动驱动的情况下,可以让read超时自动跳出啊?
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
29条回答
wangpengcheng
2020-02-13 14:43
搞定了,还是自己看文档不仔细啊!串口在打开的时候有可以设置如下标志,是打开非阻塞读取串口驱动的!希望能给后面的同学提供帮助!
IO_SERIAL_NON_BLOCKING
Open the serial driver in non blocking mode. In this mode the _io_read() function doesn’t wait till the receive buffer is full, but it immediately returns received characters and number of received characters.
char read_buff[50];
int index = 0, size = 0;
MQX_FILE_PTR uart_handle = fopen("ittya:", (char const *)IO_SERIAL_NON_BLOCKING);
while(1)
{
//Wait Receive
while(size == 0)
{
_time_delay(2);
size = read(uart_handle, &read_buff[index], sizeof(read_buff));
}
//Buffer Index Change
index += size;
//Receive End Test
if((read_buff[index - 1] == ' ') && (read_buff[index - 2] == ' '))
break;
}
fclose(uart_handle);
复制代码
请版主帮忙结贴,谢谢!
加载中...
查看其它29个回答
一周热门
更多
>
相关问题
手把手学会例程系列:i.MX<二>:图解i.mx53源码补丁+烧录(...
59 个回答
从零开始MQX开发之二 创建与调试MQX项目
24 个回答
7009: Trim value invalid, value is blank or zero是什么错误
0 个回答
怎么头像消失啊?
23 个回答
求推荐KINETIS评估板:必备USB HS,ETHERNET
5 个回答
相关文章
基于IMX6Q移植uboot2018-09——添加单板
0个评论
IMX6UL定时器按键消抖实验
0个评论
I.MX6U处理器LED灯点亮汇编程序代码编写
0个评论
在NXP I.MX6上做一个基于Opencv和OpenGL的打砖块游戏
0个评论
【RFID安全】浅谈卡片破解
0个评论
LM75a
0个评论
emwin字库制作及汉字显示
0个评论
STM32学习之I2C
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
NXP
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
IO_SERIAL_NON_BLOCKING
Open the serial driver in non blocking mode. In this mode the _io_read() function doesn’t wait till the receive buffer is full, but it immediately returns received characters and number of received characters.
- char read_buff[50];
- int index = 0, size = 0;
- MQX_FILE_PTR uart_handle = fopen("ittya:", (char const *)IO_SERIAL_NON_BLOCKING);
- while(1)
- {
- //Wait Receive
- while(size == 0)
- {
- _time_delay(2);
- size = read(uart_handle, &read_buff[index], sizeof(read_buff));
- }
- //Buffer Index Change
- index += size;
- //Receive End Test
- if((read_buff[index - 1] == '
') && (read_buff[index - 2] == '
'))
- break;
- }
- fclose(uart_handle);
复制代码请版主帮忙结贴,谢谢!
一周热门 更多>