ModalAI Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Serial read is blocking

    Flight Core
    2
    2
    213
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Andrew KeefeA
      Andrew Keefe
      last edited by Andrew Keefe

      I'm running a serial connection to a sensor wired as simplex. The code runs fine when the sensor is there. I wanted to turn the LED yellow if the serial read times out and returns no data, but the read function is blocking. It just sits there indefinitely.

      I am playing around with

      char buff = {0};
      int fd;

      fd = open("/dev/ttyS1", O_RDONLY | O_NOCTTY | O_NONBLOCK);
      struct termios config;
      tcgetattr(fd, &config);
      config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL |INLCR | PARMRK | INPCK | ISTRIP | IXON);
      config.c_oflag = 0;
      config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
      config.c_cflag &= ~(CSIZE | PARENB);
      config.c_cflag |= CS8;
      config.c_cc[VMIN] = 0;
      config.c_cc[VTIME] = 10;
      cfsetispeed(&config, B57600);
      cfsetospeed(&config, B57600);
      tcflush(fd, TCIOFLUSH);
      tcsetattr(fd, TCSANOW, &config)

      ret = read(fd, &buff, 1);
      if (ret<=0) {
      status_yellow();
      }

      1 Reply Last reply Reply Quote 0
      • modaltbM
        modaltb ModalAI Team
        last edited by

        Hi @Andrew-Keefe,

        I'm not positive on this one. I have an example of using UART for an ESC here, and I remember having to be careful what task was opening the UART port:

        https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp#L736

        Here's opening of the port (note: this is beta level code)

        https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp#L48

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB | Contributors