title: Disable DTR with <termios.h> for Arduino
body: <p>I'm trying to communicate with an Arduino over serial port.</p>
  
  <p>It works, but the DTR line is (probably) toggled at start, so the Arduino resets (it has DTR wired to hardware reset pin).</p>
  
  <p>Here's my code:</p>
  
  <pre><code>// Without this it won't work
  #define _POSIX_SOURCE
  #define _GNU_SOURCE
  
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;termios.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char const *argv[])
  {
      struct termios toptions;
      int fd = open("/dev/ttyUSB0", O_RDWR | O_NONBLOCK );
  
      int iflags = TIOCM_DTR;
      ioctl(fd, TIOCMBIC, &amp;iflags); // turn off DTR
  
      speed_t brate = B9600;
      cfsetispeed(&amp;toptions, brate);
      cfsetospeed(&amp;toptions, brate);
  
      toptions.c_cflag &amp;= ~PARENB;
      toptions.c_cflag &amp;= ~CSTOPB;
      toptions.c_cflag &amp;= ~CSIZE;
      toptions.c_cflag |= CS8;
      toptions.c_cflag &amp;= ~CRTSCTS;
      toptions.c_cflag |= CREAD | CLOCAL;
      toptions.c_iflag &amp;= ~(IXON | IXOFF | IXANY);
      toptions.c_lflag &amp;= ~(ICANON | ECHO | ECHOE | ISIG);
      toptions.c_oflag &amp;= ~OPOST;
      toptions.c_cc[VMIN]  = 0;
      toptions.c_cc[VTIME] = 0;
      tcsetattr(fd, TCSANOW, &amp;toptions);
      tcsetattr(fd, TCSAFLUSH, &amp;toptions);
  
      // talk with arduino
  }
  </code></pre>
  
  <p>You can see I tried something at</p>
  
  <pre><code>int iflags = TIOCM_DTR;
  ioctl(fd, TIOCMBIC, &amp;iflags); // turn off DTR
  </code></pre>
  
  <p>but it has no effect.</p>
  
  <p>How can I disable the DTR line control altogether?</p>
  
  <p>ps. I don't understand all the flags being set, it's pieced together from something I found online</p>