Clearing the serial port's buffer

后端 未结 3 609
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 07:31

This is what my function looks like to open the serial port (using Ubuntu 12.04):

int open_port(void)
{
  int fd; /* File descriptor for the port */

  fd =          


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 07:53

    The cause of this problem lies in using a USB serial port. If you use a regular serial port, you will not have this problem.

    Most USB serial port drivers don't support flushing properly, probably because there's no way of knowing if there's still data in the internal shift register, FIFO or in the USB subsystem.

    See also Greg's reply to a similar problem reported earlier here.

    Your sleep may cure the problem, but it's only a work-around. Unfortunately there is no solution other than using a regular serial port.

提交回复
热议问题