dump data from serial level convertor board
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 12 Oct 2016 16:21:15 +0000 (18:21 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 12 Oct 2016 16:21:15 +0000 (18:21 +0200)
serial.pl [new file with mode: 0755]

diff --git a/serial.pl b/serial.pl
new file mode 100755 (executable)
index 0000000..e72c99a
--- /dev/null
+++ b/serial.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Device::SerialPort;
+use Data::Dump qw(dump);
+
+$|=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');
+
+while (1) {
+       my ($len, $string) = $s->read(255);
+
+       if ( $len > 0 ) {
+               my $hex = unpack('H*',$string);
+               $hex =~ s/(..)/$1 /g;
+               print time(), " $len $hex\n";
+       }
+}
+
+$s->close;