首页 » 技术SOS » 嵌入式系统 » MCU和嵌入式微处理器 » select串口通讯容易丢失数据

select串口通讯容易丢失数据

菜鸟
2007-07-24 17:27:49
串口设置: ioctl(SerialDevFd, FIOBAUDRATE, 115200); /* set to 'line‘ mode */ ioctl(SerialDevFd, FIOSETOPTIONS, OPT_TERMINAL & OPT_LINE ); /* set to data bits*/ ioctl(SerialDevFd, SIO_HW_OPTS_SET,8); 接受: FD_ZERO (&readFds); /* initialize bit mask */ FD_SET (SerialDevFd, &readFds); width = SerialDevFd + 1; /* loop forever reading data and servicing clients */ FOREVER { /* pend, waiting for one or more fds to become ready */ if ((numbit=select (width, &readFds, NULL, NULL, NULL)) == ERROR) printf("typereadr: ERROR\n"); printf("typereadr: number=%d\n",numbit); /* check if this fd has data to read */ if (FD_ISSET (SerialDevFd, &readFds)) { FOREVER { bzero (buffer, MAX_DATA); /* typically read from fd now that it is ready */ if ( (DataLen = read (SerialDevFd, buffer, MAX_DATA))==ERROR ) { printf("typereadr: ERROR Reading\n"); } /* normally service request, for this example print it */ printf ("typereadr: Reading...DataLen=%d %s\n",DataLen,(char*)buffer ); if(DataLen == 0) break; } printf("typereadr: Read OK!"); } } 出现问题:接受打印的数据很容易丢失?谢谢关注!
关键词: 串口通讯, 数据丢失