From 73513bbf6abf98a3068cc677d4c8e1b56ca8506b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 15 Aug 2010 19:56:17 +0200 Subject: [PATCH 1/1] make it robust re-open parallel port before receiving response and wait for first byte with short timeout --- scripts/evolis-command.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/evolis-command.pl b/scripts/evolis-command.pl index 6c63092..e8c065f 100755 --- a/scripts/evolis-command.pl +++ b/scripts/evolis-command.pl @@ -5,6 +5,7 @@ use strict; use POSIX; use Data::Dump qw(dump); +use Time::HiRes; my $dev = '/dev/usb/lp0'; my $debug = 1; @@ -26,12 +27,16 @@ while() { syswrite $parallel, $byte, 1; } + close($parallel); + sysopen( $parallel, $dev, O_RDWR | O_EXCL) || die "$dev: $!"; + my $response; + while ( ! sysread $parallel, $response, 1 ) { sleep 0.1 }; # read first char my $byte; while( sysread $parallel, $byte, 1 ) { + warn "#<< ",dump($byte),$/ if $debug; last if $byte eq "\x00"; $response .= $byte; - warn "#<< ",dump($byte),$/ if $debug; } close($parallel); -- 2.20.1