#!/usr/bin/perl

use strict;
use warnings;

use Device::SerialPort;

die("Usage: $0 /dev/ttyS0\n") unless $#ARGV == 0;

my ($devicepath) = @ARGV;

my $port = new Device::SerialPort($devicepath);
die "Couldn't open serial port" if ! defined $port;

$port->baudrate(2400);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
$port->handshake("none");
$port->rts_active(0);
$port->dtr_active(1);

#$port->read_char_time(5);     # wait 5ms per character
$port->read_const_time(200);   # 0.2 second per unfulfilled "read" call
$| = 1; # autoflush STDOUT
while(1) {
	my ($nin, $in) = $port->read(255);
	print $in;
}

$port->close;

