【发布时间】:2011-11-30 12:26:03
【问题描述】:
我正在尝试在 centos 上设置串行端口,但无法使其工作。这是我遇到问题的代码。
tcgetattr(idComDev[i], &options); // get current settings
printw("default baudrate is %d ", cfgetispeed(&options));
cfsetispeed(&options, B115200); // set baud rate
cfsetospeed(&options, B115200); // set baud rate
tcsetattr(idComDev[i], TCSANOW, &options);// save the settings
printw("Seg %d = COM%hd at %d Baudrate",i,CommNo[i], cfgetispeed(&options));
输出是:Default baud rate is 4098 Seg0 = COM1 at 4098 Baudrate。
为什么是 4098?我在任何地方都找不到这个波特率。
如果我将波特率设置为 1800,则表示为 10。如果将其设置为 9600,则表示为 13。
我做了一些研究,发现硬件无法支持这么高的波特率,但我在同一台计算机上有一个 Java 程序与我尝试连接的同一设备进行通信。所以我知道这不可能。
有谁知道发生了什么以及如何解决它?
【问题讨论】:
-
@phresnel 这是波特率,如果你看这里easysw.com/~mike/serial/serial.html 那么你会看到使用termios时所有的波特率都以B开头
-
我明白了,我担心您可能正在使用允许二进制文字的编译器扩展。
标签: c++ linux serial-port centos baud-rate