Clearing the serial port's buffer

后端 未结 3 604
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  执念已碎
    2020-12-13 08:08

    I think I figured it out. For some reason, I need to add a delay before flushing. These two lines added before returning fd seem to have done the trick:

      sleep(2); //required to make flush work, for some reason
      tcflush(fd,TCIOFLUSH);
    

提交回复
热议问题