title: Can't set serial port configuration in Linux in C
body: <p>I have writen some Linux program to comunicate my device. I have "same" my program for Windows ("same" because of it's same logic).
  I'm using 8N2 data frame format @ 9600 bps, with neither software (XOn/XOff) nor hardware (RTS/CTS) flow control. I don't use DTR, DCD, RI, DSR pins of RS-232 9-pin D-sub. I use only RX and TX pins to communicate with my device.
  In Linux I have this part of code:</p>
  
  <pre><code> struct termios PortOpts, result;
   int fd; /* File descriptor for the port */
  
  /* Configure Port */
   tcgetattr(fd, &amp;PortOpts);
   // BaudRate - 9600
   cfsetispeed(&amp;PortOpts, B9600);
   cfsetospeed(&amp;PortOpts, B9600);
   // enable reciever and set local mode, frame format - 8N2, no H/W flow control
   PortOpts.c_cflag &amp;= (~(CLOCAL | CREAD | CSIZE | CSTOPB));
   PortOpts.c_cflag |= ((CLOCAL | CREAD | CS8 | CSTOPB) &amp; (~PARENB));
   PortOpts.c_cflag &amp;= (~CRTSCTS);
  // PortOpts.c_cflag &amp;= ~PARENB
  // PortOpts.c_cflag |= CSTOPB
  // PortOpts.c_cflag &amp;= ~CSIZE;
  // PortOpts.c_cflag |= CS8;
   // no parity check, no software flow control on input
   PortOpts.c_iflag |= IGNPAR;
   PortOpts.c_iflag &amp;= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY | INPCK);
   // raw data input mode
   PortOpts.c_lflag &amp;= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
   // raw data output
   PortOpts.c_oflag &amp;= ~OPOST;
   // setting timeouts
   PortOpts.c_cc[VMIN] = 1; // minimum number of chars to read in noncanonical (raw mode)
   PortOpts.c_cc[VTIME] = 5; // time in deciseconds to wait for data in noncanonical mode (raw mode)
  
   if (tcsetattr(fd, TCSANOW, &amp;PortOpts) ==  0) {
      tcgetattr(fd, &amp;result);
      if ( (result.c_cflag != PortOpts.c_cflag) ||
           (result.c_oflag != PortOpts.c_oflag) ||
           (result.c_iflag != PortOpts.c_iflag) ||
           (result.c_cc[VMIN] != PortOpts.c_cc[VMIN]) ||
           (result.c_cc[VTIME] != PortOpts.c_cc[VTIME]) ) {
          perror("While configuring port1");
          close(fd);
          return 1;
      }
   } else {
      perror("While configuring port2");
      close(fd);
      return 1;
   };
  </code></pre>
  
  <p>File descriptor 'fd' is for '/dev/ttyS0' device.
  I get that message: <strong>While configuring port2: Input/output error</strong>
  I have a laptop, though I don't have any serial ports except for USB. Is this a reason?
  I run program as 'root'.</p>
  
  <p>Sorry for my broken English.</p>