Выберите время ожидания API на скорости 9600 бод - PullRequest
0 голосов
/ 02 февраля 2019

Я читаю данные из последовательного / UART со скоростью 9600 бод (моя скорость 115200 бод работает нормально)

Я написал приведенный ниже код, но API выбора каждый раз дает время ожидания, онотребует таймаута более 2 секунд, что не желательно.Поскольку у меня есть 2048 байт данных, поэтому в течение 100 мс я смог бы получить некоторые данные, но я думаю, что select API не получает прерывания, даже если в Rx-буфере последовательного порта есть некоторые данные для обработки.

ПРИМЕЧАНИЕ:тот же кусок кода работает нормально на beaglebone black, а не на intel atom-3900 / Ядро используется linux-intel 4.9.

Код:

int main(void)
{
  int   ret;
  char  buf[1280];
  fd_set m_Inputs;  // fd_set for the select call for com input
  int   m_maxFD;   // max FD for select() call.

  struct timeval tv;
  /*Open Serial port in non blocking mode*/
  int fd1;
  fd1 = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK);

  /* get the termios structure */
  struct termios options;

  tcgetattr(fd1, &options);  // Get the current options for the port...

  // Set the baud rates...
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);

  // Enable the receiver and set local mode...
  options.c_cflag |= (CLOCAL | CREAD | CS8);
  options.c_cflag &= ~PARENB;  // ignore parity
  options.c_cflag &= ~CSTOPB;  // 1 stop bit (2 if set)
  options.c_cflag &= ~CSIZE;   // clear the size bits
  options.c_cflag &= ~CRTSCTS; //No hard flow control
  options.c_cflag &= ~HUPCL;   //Hang Up on last Close
  options.c_cflag |= CS8;      // reset the size to 8 bits / char
  options.c_cc[VMIN]=1;
  options.c_cc[VTIME] = 1;
  options.c_oflag = 0;
  options.c_lflag = 0;       //ICANON;
  // Set the new options for the port...
  tcsetattr(fd1, TCSANOW, &options);

  cout << endl << "FD1 = " << fd1 << endl;

  while (1)
  {

        fd_set rfds;  // fd_set for the select call for com input

        FD_ZERO(&rfds);
        FD_SET(fd1, &rfds);

        tv.tv_sec = 0;
        tv.tv_usec = 100000;

        ret = select(fd1 + 1, &rfds, NULL, NULL, &tv);

        if (ret > 0)
        {
          ret = read(fd1, buf, 127);
          buf[ret] = '\0';
          cout << buf;

        }else{

            cout << "Time OUT" << endl;
            break;
        }
    }

  return 0;

}
...