#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>

int main (void)
{
    struct termios tp;
    char *portstr="/dev/ttyS0";
    int port, count;
    char buf[512];

    port=open(portstr,O_NOCTTY|O_SYNC|O_RDWR);

    if (port==-1)
    {
	fprintf(stderr, "Could not open %s.\n", portstr);
	exit(1);
    }

    tcgetattr(port, &tp);
    cfmakeraw(&tp);
    cfsetispeed(&tp, B4800);
    tp.c_cflag|=CS8;
    tp.c_cflag|=CLOCAL;
    tp.c_cflag&=(~CRTSCTS);
    if (tcsetattr(port, TCSANOW, &tp))
    {
	fprintf(stderr, "Failed to configure port %s.\n", portstr);
	exit(1);
    }

    while(1)
    {
	count=read(port,buf,1);
	if (count==-1)
	    break;
//	printf("%c",buf[0]);
//	fflush(stdout);
	write(fileno(stdout),buf,1);
    }
}

