int set_speci_baud(int fd, int baud)
{
struct serial_struct ss, ss_set;
struct termios Opt;
tcgetattr(fd, &Opt);
cfsetispeed(&Opt, B38400);
cfsetospeed(&Opt, B38400);
tcflush(fd, TCIFLUSH);/handle unrecevie char/
tcsetattr(fd, TCSANOW, &Opt);
if((ioctl(fd, TIOCGSERIAL, &ss)) < 0)
{
printf(“BAUD: error to get the serial_struct info:%s\n”, strerror(errno));
return -1;
}
ss.flags = ASYNC_SPD_CUST;
ss.custom_divisor = ss.baud_base/baud;
if((ioctl(fd, TIOCSSERIAL, &ss)) < 0)
{
printf(“BAUD: error to set serial_struct:%s\n”, strerror(errno));
return -2;
}
ioctl(fd, TIOCGSERIAL, &ss_set);
printf(“BAUD: success set baud to %d,custom_divisor=%d,baud_base=%d\n”,baud, ss_set.custom_divisor, ss_set.baud_base);
return 0;
}
我用这段代码设置分辨率不够最接近的就是250000了又2%的误差,
这个是我运行打印的log BAUD: success set baud to 256000,custom_divisor=5,baud_base=1500000,
custom_divisor是整型,baud_base又不够大,所以设置不到256000,请问有什么别的方法设置吗?或者是
baud_base的大小可以调整吗?