|
楼主 |
发表于 2014-6-16 10:24:02
|
显示全部楼层
搞定了,还是自己看文档不仔细啊!串口在打开的时候有可以设置如下标志,是打开非阻塞读取串口驱动的!希望能给后面的同学提供帮助!
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] == '\n') && (read_buff[index - 2] == '\r'))
- break;
- }
- fclose(uart_handle);
复制代码
请版主帮忙结贴,谢谢! |
|