|
我在程序中用到 read函数,从串行口上读数据,测试花费的时间为100ms.实际上串行口以9600速度工作时.一个字节所花的时间不超过10ms.如何样改造,使得read响应变快.
uchar receive_DATA()
{
uchar buffer[3];
fd_set readfs;
timeout.tv_sec=0;
timeout.tv_usec=10;
// printf("receive_DATA\r\n");
FD_ZERO(&readfs);
FD_SET(commDevice,&readfs);
if(select(FD_SETSIZE, &readfs, 0, 0, &timeout)<0)
{
printf("receive_DATA select error\r\n");
// newdata=0;
return 1;
}
if(FD_ISSET(commDevice,&readfs))
{
read(commDevice,buffer,1);
printf("receive_DATA=0x%x\r\n",buffer[0]);
return buffer[0];
}
else
{
printf("receive_DATA timeout \r\n");
// newdata=0;
return 1;
}
} |
|