#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 = 6;

 /* 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 < 100000; x++ ) {
     ioctl(fd, TIOCMSET, &set_bits);
     ioctl(fd, TIOCMGET, &status);

      if (status & TIOCM_CTS)
        puts("TIOCM_CTS is set, Beam shining");
     else
        puts("TIOCM_CTS is not set, Beam broken-------------------------------");
 }  

 close(fd);
}
