|
发表于 2016-11-14 12:27:41
只看该作者
地板
本帖最后由 andGo 于 2016-11-14 12:29 编辑
int speed_arr[] = {B115200,B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600, B4800, B2400, B1200, B300};
int name_arr[] = {115200,38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400, 1200, 300};
tcgetattr(uartFd,&oldtio);
newtio = oldtio;
cfmakeraw(&newtio);
for(i = 0; i < sizeof(speed) / sizeof(int); i++)
{
if(baudrate == name_arr)
{
cfsetispeed(&newtio, speed_arr);
cfsetospeed(&newtio, speed_arr);
break;
}
}
newtio.c_cflag |= (CLOCAL|CREAD);
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;
newtio.c_cflag &= ~PARENB;
newtio.c_iflag &= ~INPCK;
newtio.c_cc[VMIN]=0;
newtio.c_cc[VTIME] = 0;
tcflush(uartFd,TCIFLUSH);
tcsetattr(uartFd,TCSANOW,&newtio);
//fcntl(uartFd,F_SETFL,FNDELAY);
按这个改 |
|