串口不接受波特率

发布于 2024-12-07 23:00:23 字数 735 浏览 1 评论 0原文

我正在尝试在 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));

输出为:默认波特率为 4098 Seg0 = COM1,波特率为 4098

为什么是4098?我在任何地方都找不到这个波特率。

如果我将波特率设置为 1800,它会显示为 10。如果我将其设置为 9600,它会显示为 13。

我做了一些研究,发现硬件显然无法支持这么高的波特率,但我有一个同一台计算机上的 Java 程序与我尝试连接的同一设备进行通信。所以我知道情况不可能如此。

有谁知道发生了什么事以及如何解决它?

I am trying to setup a serial port on centos but can't get it to work. this is the code that I'm having trouble with.

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));

The out put from this is: Default baud rate is 4098 Seg0 = COM1 at 4098 Baudrate.

Why is it at 4098? I can't find this baudrate anywhere.

If I set the baud rate to 1800 it says it is at 10. If I set it to 9600 it says it is at 13.

I have done some research and found that suposidly the hardware cannot support this high a baud rate but I have a Java program on the same computer commutating with the same device that I am trying to connect to. So I know this cannot be that case.

Does anyone know what is going on and how to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2024-12-14 23:00:23

B115200 是一个宏,并扩展为0x1002。这是两个位的组合:0x1000 表示它是非标准速率(正如您所发现的),0x2 是第二个非标准速率(B576000x1001,第一个非标准利率)。

B115200 is a macro, and expands to 0x1002. That's a combination of two bits: 0x1000 signals that it's a non-standard rate (as you discovered) and 0x2 is the second non-standard rate (B57600 is 0x1001, the first non-standard rate).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文