我希望通过Linux上的串口与具有非标准波特率的设备进行通信termios.h.
我尝试了这篇文章中的"波特率别名"方法,但是当我执行我的C程序(我把它命名为"testprogram")时,Linux说"testprogram sets custom speed on ttyS0. This is deprecated."
我在Google上进行了一些搜索,似乎还有另一种(更新的?)方法将波特率更改为非标准值:在http://sourceware.org/ml/libc-help/2009-06 /msg00016.html笔者说,c_flag中struct termios必须进行OR操作BOTHER (=CBAUDEX | B0).使用这种方法,波特率直接设置在c_ispeed和 - 的c_ospeed成员中struct termios.但是,我不知道如何在我的C程序中使用此方法.就像作者所说,BOTHER当我包含时没有定义/可用termios.h,那么应该采取什么方式来设置波特率?
如何在不更改内核的情况下将波特率设置为非标准值?
基本上我使用以下代码来设置串口的波特率:
struct termios options;
tcgetattr(fd, &options);
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
tcsetattr(fd, TCSANOW, &options);
Run Code Online (Sandbox Code Playgroud)
这非常有效.但是我知道我必须使用波特率为307200的设备进行通信.我该如何设置?cfsetispeed(&options, B307200);不起作用,没有B307200定义.
我尝试使用MOXA Uport 1150(实际上是USB转串口转换器)和英特尔主板的标准串口.我不知道后者的确切类型,setserial只是将其报告为16550A.