How to set baud rate to 307200 on Linux?

后端 未结 6 2042
走了就别回头了
走了就别回头了 2020-11-28 10:36

Basically I\'m using the following code to set the baud rate of a serial port:

struct termios options;
tcgetattr(fd, &options);
cfsetispeed(&options,         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 11:26

    On many OSes, the enumerated values are numerically equal to the baud rate. So just skip the macro/enumeration and pass the baud rate you want, e.g.

    cfsetispeed(&options, 307200);
    

    Of course you should check the return code to make sure this trick actually worked, furthermore not all baud rates are supported by all UARTs.

    You can also try setting the options in struct serial_struct using the TIOCGSERIAL and TIOCSSERIAL ioctl codes.

提交回复
热议问题