termios.h中的波特率限制是多少?

时间:2015-08-18 17:52:55

标签: global-variables termios baud-rate

这是我用来与微控制器连接的串行程序的快速代码片段。代码已经过验证可以工作但我想添加全局定义以使代码更加模块化。显示的摘录有效,直到我将'cfsetispeed'中的'B1000000'替换为全局'BAUDRATE'。

// Globals
struct termios tty;
char BAUDRATE = B1000000;     // 1,000,000

// All of the other details omitted ( int main (), etc. )
cfsetospeed (&tty, BAUDRATE);
cfsetispeed (&tty, B1000000);

因此我想到了两个问题:

1)我读到Termios只允许选择波特率,the max listed是230,400。怎么允许1,000,000?

2)为什么cfsetispeed()不允许将全局字符定义作为参数?

1 个答案:

答案 0 :(得分:0)

  1. Termios接受波特率作为一个标志,但man7页面或linux.die.net上没有列出other baud rates available to the speed_t structure in termbits.h (linked code for kernel v3.11),范围从460800到4000000.

  2. cfsetispeed接受波特率为speed_t类型。 speed_t是typedef'是" unsigned int"的类型对象。在termbits.h中,它比你传入的字符更大(32位对8位)。