Programming Linux serial port, ttyS0

后端 未结 1 1418
刺人心
刺人心 2021-02-02 04:56

I\'m trying to learn how to program the ttyS0 serial port in Linux using C. I have another machine connected to my serial port sending alternating hex values of 5f and 6f about

1条回答
  •  粉色の甜心
    2021-02-02 05:03

    The following line will cause problems:

    options.c_cflag &= CSTOPB;
    

    It will reset all other bits of the c_cflag.

    If you want to use 1 stop bit, then use:

    options.c_cflag &= ~CSTOPB;
    

    If you want to use 2 stop bits, then use:

    options.c_cflag |= CSTOPB;
    

    EDIT:

    Also the following line cause problems:

    fcntl(fd, F_SETFL, 0);
    

    It will reset several important flags.

    0 讨论(0)
提交回复
热议问题