#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <termios.h>
/* Main program. */
int main(int argc, char **argv)
{
 int fd;
 int status;
 int set_bits = 0;

 /* Open monitor device. */
 if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
  fprintf(stderr, "ar-2: %s: %s\n",
          argv[1], sys_errlist[errno]);
  exit(1);
 }
  
 int x = 0;
 for (  x = 0; x < 100; x++ ) {
      if (set_bits) {
          set_bits = 0 ;
      } else {
          set_bits = 6 ;
      }
     ioctl(fd, TIOCMSET, &set_bits);
     ioctl(fd, TIOCMGET, &status);
     if (status & TIOCM_DTR)
         puts("TIOCM_DTR is set");
     else
        puts("TIOCM_DTR is not set");
     if (status & TIOCM_RTS)
        puts("TIOCM_RTS is set");
     else
        puts("TIOCM_RTS is not set");

     printf("%i",x),
     puts(" ------------------------");
     sleep(2);
 }  

 close(fd);
}
