当前位置: 技术问答>linux和unix
急!(ARM9开发板)select+read,串口一次无法读出一个完整的接收到的数据帧内容.
来源: 互联网 发布时间:2015-12-10
本文导语: 串口在系统初始化时打开(波特率4800,8N1,无流控制,非阻塞) ------------------------------- #define MAXDATASIZE 1024 int com_fd; int max_fd; fd_set rd_set,wr_set,er_set; struct timeval timeout; void serial_test(void) { int i,ret,nlen; ...
串口在系统初始化时打开(波特率4800,8N1,无流控制,非阻塞)
-------------------------------
#define MAXDATASIZE 1024
int com_fd;
int max_fd;
fd_set rd_set,wr_set,er_set;
struct timeval timeout;
void serial_test(void)
{
int i,ret,nlen;
char temp[10];
char com_recv_buf[MAXDATASIZE];
i=0;
temp[i++]=0xaa;
temp[i++]=0xaa;
temp[i++]=0x00;
temp[i++]=0x00;
temp[i++]=0xbb;
temp[i++]=0xbb;
while(1)//
{
write(com_fd,temp,10);//发送给MCU,MCU接收后,立即发回数据
max_fd = com_fd + 1;
FD_ZERO(&rd_set);
FD_ZERO(&wr_set);
FD_ZERO(&er_set);
FD_SET(com_fd,&rd_set);
FD_SET(com_fd,&er_set);
printf("nStart com select ");
timeout.tv_sec=6;
timeout.tv_usec=0;
ret=select(max_fd,&rd_set,NULL,&er_set,&timeout);
if (ret
-------------------------------
#define MAXDATASIZE 1024
int com_fd;
int max_fd;
fd_set rd_set,wr_set,er_set;
struct timeval timeout;
void serial_test(void)
{
int i,ret,nlen;
char temp[10];
char com_recv_buf[MAXDATASIZE];
i=0;
temp[i++]=0xaa;
temp[i++]=0xaa;
temp[i++]=0x00;
temp[i++]=0x00;
temp[i++]=0xbb;
temp[i++]=0xbb;
while(1)//
{
write(com_fd,temp,10);//发送给MCU,MCU接收后,立即发回数据
max_fd = com_fd + 1;
FD_ZERO(&rd_set);
FD_ZERO(&wr_set);
FD_ZERO(&er_set);
FD_SET(com_fd,&rd_set);
FD_SET(com_fd,&er_set);
printf("nStart com select ");
timeout.tv_sec=6;
timeout.tv_usec=0;
ret=select(max_fd,&rd_set,NULL,&er_set,&timeout);
if (ret