用PC的串口调试助手发送数据下来,我发誓11个字节,我一次从串口读取512个字节,但是Linux串口的只接收到8个字节,怎么回事呢?

串口一些配置如下:

newtio.c_lflag  &= ~(ICANON);  /*Input*/

newtio.c_cc[VTIME]  = 5;//超时时间 百ms

newtio.c_cc[VMIN] = 0;

串口读取如下;

fd_set rfds;

struct timeval tv;

tv.tv_sec = 0;

tv.tv_usec = 200000;

int retval;

int nn = 0;

memset((*ReadUartDat).ReadBuf,0,UARTBUFFSIZE);

FD_ZERO(&rfds);

FD_SET(((*ReadUartDat).uart_fd),&rfds);

nn = (FD_ISSET(((*ReadUartDat).uart_fd),&rfds));

if(nn >0)

{

FD_ZERO(&rfds);

FD_SET(((*ReadUartDat).uart_fd),&rfds);

if ((select(((*ReadUartDat).uart_fd + 1),&rfds,NULL,NULL,&tv)) 

{

perror("select()");

}

else

{

while(1)

{

if(R_uartDatNumAll >= 512)

break;

R_uartDatNum = read(((*ReadUartDat).uart_fd),(*ReadUartDat).ReadBuf,512);

if(R_uartDatNum <= 0)

{

// tcflush(((*ReadUartDat).uart_fd),TCIFLUSH);

break;

}

R_uartDatNumAll += R_uartDatNum;

}

}

}

串口的缓存有1K,我只读512字节,理论上一次读取512字节应该是可以的。。。

此文章对您是否有帮助? 是

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐