Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Collapse
Brand Logo

ModalAI Forum

  1. ModalAI Support Forum
  2. VOXL Compute & Autopilot
  3. Flight Core
  4. Serial read is blocking

Serial read is blocking

Scheduled Pinned Locked Moved Flight Core
2 Posts 2 Posters 719 Views 2 Watching
  • 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 Offline
    Andrew KeefeA Offline
    Andrew Keefe
    wrote on last edited by Andrew Keefe
    #1

    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
    0
    • modaltbM Offline
      modaltbM Offline
      modaltb
      ModalAI Team
      wrote on last edited by
      #2

      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:

      Link Preview Image
      px4-firmware/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp at modalai-1.11 · modalai/px4-firmware

      PX4 Autopilot Software. Contribute to modalai/px4-firmware development by creating an account on GitHub.

      favicon

      GitHub (github.com)

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

      Link Preview Image
      px4-firmware/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp at modalai-1.11 · modalai/px4-firmware

      PX4 Autopilot Software. Contribute to modalai/px4-firmware development by creating an account on GitHub.

      favicon

      GitHub (github.com)

      1 Reply Last reply
      0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      ModalAI
      Categories Recent Tags ModalAI.com Docs
      © 2026 ModalAI® · Accelerating autonomy for smaller, smarter, safer drones · Powered by NodeBB
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups