Hi,

I'm trying to read some bytes through the serial port. I am using the
following code


  int fd;
  int s_rc;
  fd_set rset;
  uint32_t count;
  uint8_t rd_data[16];
  struct timeval  tv;

  fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY);
  if (fd == -1)
    {
      fprintf(stderr, "ERROR: Cannot open /dev/ttyS1\n");
      return -1;
    }

  tv.tv_sec = 1;
  tv.tv_usec = 0;

  /* Add a file descriptor to the set */

  FD_ZERO(&rset);
  FD_SET(fd, &rset);

  do
    {
      s_rc = select(fd + 1, &rset, NULL, NULL, &tv);
      if(s_rc == -1)
        {
          if (errno != EINTR)
            {
              fprintf(stdout, "WARN: Non blocked signal was caught\n");
              break;
            }
        }
      else if (s_rc == 0)
        {
          fprintf(stdout, "WARN: select() timeout\n");
          errno = ETIMEDOUT;
        }
      else if (FD_ISSET(fd, &rset))
        {
          count = read(fd, rd_data, 10);
          fprintf(stdout, "INFO: %d bytes readed\n", count);
        }
      else
        {
          fprintf(stdout, "Something else happen\n");
        }
    }
  while (1);

For some reason the select() function is returning only with timeout. It's
not returning when new bytes arrive at serial. Am I doing something wrong?

Thanks

Daniel Pereira de Carvalho

Reply via email to