use Device::SerialPort;

my $port=Device::SerialPort->new("/dev/tts/1");
my $STALL_DEFAULT=10;
my $timeout=$STALL_DEFAULT;

$port->read_char_time(0);
$port->read_const_time(1000);

my $chars=0;
my $buffer="";
while($timeout>0){
	my ($count,$saw)=$port->read(1024);
	if($count>0){
		$chars+=$count;
		$buffer.=$saw;
		print "Printing what I saw!\n";
		my $time=((localtime)[5]+1900).((localtime)[4]+1).(localtime)[3].(localtime)[2].(localtime)[1];	
		open(DATA_FILE, ">>$time.txt");
		print DATA_FILE $saw;
		close (DATA_FILE);
		print $time;
		print $saw;
		last;
		}
	else{
		$timeout--;
	}
}
if($timeout==0){
	die "Waited $STALL_DEFAULT seconds and never saw what I Wanted\n";
}
		

