|
在使用串口时,如果串口初始化如下:
int setup_com(int fd){
struct termios options;
tcgetattr(fd, &options);
/* Set the baud rates to 38400...*/
cfsetispeed(&options, B38400);
cfsetospeed(&options, B38400);
/* Enable the receiver and set local mode...*/
options.c_cflag |= (CLOCAL | CREAD);
/* Set c_cflag options.*/
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
/* Set c_iflag input options */
options.c_iflag &=~(IXON | IXOFF | IXANY);
options.c_iflag &=~(INLCR | IGNCR | ICRNL);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
/* Set c_oflag output options */
options.c_oflag &= ~OPOST;
/* Set the timeout options */
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 10;
tcsetattr(fd, TCSANOW, &options);
return 1;
}
在运行时即时改变波特率的话用
cfsetispeed(&options, 波特率);
cfsetospeed(&options, 波特率);
tcsetattr(fd, TCSANOW, &options);
但即时更改数据位停止位或校验方式这些怎么更改,已经试过如下方法无效:
options.c_cflag |= CS7; //原先初始化成CS8八位数据,现在要即时改成CS7七位数据
tcsetattr(fd, TCSANOW, &options);
难道更改这些参数必须关闭端口重新打开初始化? |
|