- 论坛徽章:
- 0
|
这是我在linux下的一个串口设置函数
int tty_set_attr(int fd)
{
int i;
int status;
struct termios options;
int baud=B115200;
tcgetattr(fd, &oldoptions);
options=oldoptions;
cfsetispeed(&options,baud);
cfsetospeed(&options,baud);
options.c_cflag|=(CLOCAL|CREAD|HUPCL);
options.c_cflag&=~CSIZE;
options.c_cflag|=CS8;
options.c_cflag&=~CSTOPB;
options.c_cflag&=~PARENB;
options.c_cflag&=~PARODD;
options.c_iflag=IGNBRK|IGNPAR; //(IXON|IXOFF) will use 0x11 0x13
options.c_lflag=0; //turn canonial
options.c_cc[VMIN]=1;
options.c_cc[VTIME]=0;
//options.c_cflag&=~CRTSCTS; // (hardware control)
status = tcsetattr(fd, TCSANOW, &options);
if (status != 0)
{
printf("tcsetattr fd error\n");
return -1;
}
return 0;
}
通过这个串口与一个无线模块进行通讯时,发现如果发出去的数据里有0x0a,0x0b,通讯就会不正常。
请大侠们指点 |
|