串口不接受波特率
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
B115200
是一个宏,并扩展为0x1002
。这是两个位的组合:0x1000 表示它是非标准速率(正如您所发现的),0x2 是第二个非标准速率(B57600
是0x1001
,第一个非标准利率)。B115200
is a macro, and expands to0x1002
. 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
is0x1001
, the first non-standard rate).