Effacer le tampon du port série

C'est ce que ma fonction ressemble à ouvrir le port série (Ubuntu 12.04):

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

  fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);

  if (fd == -1)
  {
   //Could not open the port.          
   perror("open_port: Unable to open /dev/ttyUSB0 - ");
  }
  else
    fcntl(fd, F_SETFL, 0);

  struct termios options;

  tcgetattr(fd, &options); 
  //setting baud rates and stuff
  cfsetispeed(&options, B19200);
  cfsetospeed(&options, B19200);
  options.c_cflag |= (CLOCAL | CREAD);
  tcsetattr(fd, TCSANOW, &options);

  tcsetattr(fd, TCSAFLUSH, &options);

  options.c_cflag &= ~PARENB;//next 4 lines setting 8N1
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  //options.c_cflag &= ~CNEW_RTSCTS;

  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw input

  options.c_iflag &= ~(IXON | IXOFF | IXANY); //disable software flow control

  return (fd);
}

Quel est le problème, c'est que lorsque j'exécute ce programme et si mon périphérique série était déjà branché, la mémoire tampon a un contenu en elle. J'ai besoin d'un moyen d'effacer la mémoire tampon avant que je commence la lecture à partir d'elle. J'ai pensé à l'aide de tcsetattr(fd, TCSAFLUSH, &options); permettrait de résoudre ce problème, par rinçage à l'OI tampons avant d'initialiser le port, mais pas de chance. Toute idée?

source d'informationauteur capcom | 2012-10-22