#!/usr/bin/perl

print "Starting...\n";
`stty speed 1200 cs8 cread clocal cstopb -parenb -crtscts inlcr icrnl -ixon> /dev/ttyS0`;

open(SERIN, "/dev/ttyS0");
open(SEROUT, ">/dev/ttyS0");
print("Entering loop\n");
$|=1;
#$/="";
select(SERIN); $|=1; select(STDOUT);
select(SEROUT); $|=1; select(STDOUT);
while(1){
#	print SEROUT "Testing!\r";
#	print ".";
#	read(SERIN, $inbuf, 1);
#	print "_ $inbuf _";
	vec($rin, fileno(SERIN), 1) = 1;
	while(select($rin, $win, $win, .1)){
		read(SERIN, $inbuf, 1);
		print ":$inbuf: ", ord($inbuf), "\n";
		select(undef, undef, undef, .02);
		print SEROUT $inbuf unless ord($inbuf) >121;
		print SEROUT "You pressed the letter q!\n\r" if($inbuf eq "q");
	}
}