c语言中把串口当成文件来操作时 fread函数不工作是咋回事?Windows下

c语言中把串口当成文件来操作时 fread函数不工作是怎么回事?Windows下
程序就卡在fread函数那里。。请各位大侠看看怎么回事啊 
我的代码是

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char* argv[])
{
unsigned char AT[3];
unsigned char RBUF[20];
FILE *portfp;

AT[0] = 0x41; AT[1] = 0x54; AT[2] = 0x0D;

system("mode com1: baud=115200 parity=n data=8 stop=1 to=off xon=off");
portfp = fopen("com1","wb+");

if (NULL == portfp){
printf("open com port fail!\n");
exit(0);
}

memset(RBUF, 0, sizeof(RBUF));

printf("will write data to uart\n");
fwrite(AT, 1, 3, portfp);
fflush(portfp);//清除指针缓冲区使数据立即发出

printf("write over, had flush\n");

printf("press any key to continue...\n");
printf("input char:%c\n", getchar());

//Sleep(5000);

fread(RBUF, 1, 3, portfp);
printf("RBUF:%s\n", RBUF);



printf("%#4x,%#4x,%#4x",RBUF[0],RBUF[1],RBUF[2]);
printf("hello world");
return 0;
}


------解决方案--------------------
探讨

引用:

windows下还是用OpenFile、ReadFile、WriteFile等api吧


目前想用纯C,以后会给linux下移植。。可能linux下比较简单,但是windows下fwrite完全好用啊 而且用的很舒服。。

------解决方案--------------------
fflush(portfp);//清除指针缓冲区使数据立即发出
fseek(portfp,0, SEEK_SET);

试试
------解决方案--------------------
探讨

3楼说的用改成read , 在linux下确实用的是read 但是这个是系统调用并非库函数,所以基本可以肯定linux下的系统调用在windows下是行不通的。。4楼的fseek目的也是把指针指向文件的开头,我之前也用过rewind是不行得 ,不过我也试了下fseek 结果还是行不通