#include <fcntl.h>
#include <termios.h>
#include<sys/errno.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

main()

{
FILE *sfp;
int c;
struct termios i_set, n_set;

sfp=fopen("/dev/ttyS2","w");
switch ( (int) sfp)
    {
    case ENXIO: {printf("Port does not exist.\n");
                 return;}
    case EBUSY: {printf("Device busy.\n");
                 return;}
    case EINTR: {printf("Open Interrupted.\n");
                 return;}
    case NULL:  {printf("Could not open device.\n");
                 return;}
    }
tcgetattr(fileno(stdin),&i_set);
n_set = i_set;
n_set.c_lflag &= ~ICANON;
n_set.c_lflag &= ~ECHO;
n_set.c_cc[VMIN]=1;
n_set.c_cc[VTIME]=0;
if (tcsetattr(fileno(stdin),TCSANOW, &n_set) !=0)
    fprintf(stderr,"could not set attributes\n");

while ((c=getchar())!='Z')
    {
    fputc(c,sfp);   
    fflush(sfp);
    putchar(c);
    }
tcsetattr(fileno(stdin),TCSANOW,&i_set);
exit(0);
}
