stop reading from parallel port on null
[Printer-EVOLIS.git] / scripts / evolis-command.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use POSIX;
7 use Data::Dump qw(dump);
8
9 my $dev = '/dev/usb/lp0';
10 my $debug = 1;
11
12 my $parallel;
13
14 $|=1;
15 print "command> ";
16 while(<STDIN>) {
17         chomp;
18
19         my $send = "\e$_\r";
20
21         # XXX we need to reopen parallel port for each command
22         sysopen( my $parallel, $dev, O_RDWR | O_EXCL) || die "$dev: $!";
23
24         foreach my $byte ( split(//,$send) ) {
25                 warn "#>> ",dump($byte),$/ if $debug;
26                 syswrite $parallel, $byte, 1;
27         }
28
29         my $response;
30         my $byte;
31         while( sysread $parallel, $byte, 1 ) {
32                 last if $byte eq "\x00";
33                 $response .= $byte;
34                 warn "#<< ",dump($byte),$/ if $debug;
35         }
36         close($parallel);
37
38         print "<answer ",dump($response),"\ncommand> ";
39
40 }
41