#!/usr/bin/perl
use warnings;
use strict;
use Device::SerialPort;
use Data::Dump qw(dump);
use Time::HiRes qw(time);

my $read_len = 255;

$|=1;

my $s = new Device::SerialPort( '/dev/ttyUSB0' ) || die $!;
$s->baudrate(2400);
$s->databits(8);
$s->parity('none');
$s->stopbits(1);
$s->handshake('none');
$s->read_char_time(2);
$s->read_const_time(3);

#$s->write('o');

my $t = time();

while (1) {
	my ($len, $string) = $s->read($read_len);
	my $ts = time();

	if ( $len > 0 ) {
		my $hex = unpack('H*',$string);
		$hex =~ s/(..)/$1 /g;
		#printf "%s %2d  %s\n", time(), $len, $hex;
		printf "%8.4f %0.4f %2d  %s\n", $ts, $ts - $t, $len, $hex;
		$t = time();
	}
}

$s->close;
