title: Input/Output error when getting termios attributes on ttyS0 serial port
body: <p>I am writing a simple program to open the serial port <code>/dev/ttyS0</code> which is visible in <code>/dev</code>.</p>
  
  <p>The code opens the serial port no problems on my PC at home but on my work machine I run into an error that returns "Input/Output Error". The error appears as a result of <code>tcgetattr</code> failing but I am unsure why as the serial port is visible. I added a verbose error printout via <code>libexplain</code> and it reported to me. </p>
  
  <blockquote>
    <p>tcgetattr(fildes = 3 "/dev/ttyS0", data = 0x7FFEEA8CEEB0) failed, Input/output error (5, EIO)</p>
  </blockquote>
  
  <p>I am not sure what other information is relevant that I can provide. It is an Arch Linux system with a 5.3.8 kernel.</p>
  
  <pre><code>const char *port_name = "/dev/ttyS0";
  
  int main(int argc, char *argv[])
  {
     int serial_fd, file_status;
      struct termios termSettings;
      struct sigaction act = { 0 };
  
      serial_fd = open(port_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
  
      if (serial_fd &lt; 0) {
          perror("Opening serial port failed");
          return -1;
      }
  
      if (tcgetattr(serial_fd, &amp;termSettings) &lt; 0) {
          perror("Getting terminal attributes failed");
          printf("Error reason: %s\n",  explain_tcgetattr(serial_fd, &amp;termSettings));
          goto error;
      }
     ...
  }
  </code></pre>
  
  <p>The complete source is <a href="https://github.com/alxhoff/C-code-snippets/blob/3b913fc0efcb84ff9597e8874218a149cfcfb75f/tty_serial/src/main.c" rel="nofollow noreferrer">here</a></p>