| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Printer::EVOLIS::Parallel; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3930
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
835
|
use POSIX; |
|
|
1
|
|
|
|
|
7819
|
|
|
|
1
|
|
|
|
|
8
|
|
|
7
|
1
|
|
|
1
|
|
4811
|
use Data::Dump qw(dump); |
|
|
1
|
|
|
|
|
6082
|
|
|
|
1
|
|
|
|
|
520
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $debug = 0; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Printer::EVOLIS::Parallel - chat with parallel port printer |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 new |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $p = Printer::EVOLIS::Parallel->new( '/dev/usb/lp0' ); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
|
24
|
0
|
|
|
0
|
1
|
|
my ( $class, $port ) = @_; |
|
25
|
0
|
|
|
|
|
|
my $self = { port => $port }; |
|
26
|
0
|
|
|
|
|
|
bless $self, $class; |
|
27
|
0
|
|
|
|
|
|
return $self; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 command |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $response = $p->command( 'Rsn' ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub command { |
|
37
|
0
|
|
|
0
|
1
|
|
my ( $self, $send ) = @_; |
|
38
|
0
|
0
|
|
|
|
|
$send = "\e$send\r" unless $send =~ m/^\e/; |
|
39
|
0
|
|
|
|
|
|
$self->send( $send ); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub send { |
|
43
|
0
|
|
|
0
|
0
|
|
my ( $self, $send ) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $port = $self->{port}; |
|
46
|
0
|
0
|
|
|
|
|
die "no port $port" unless -e $port; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $parallel; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# XXX we need to reopen parallel port for each command |
|
51
|
0
|
0
|
|
|
|
|
sysopen( $parallel, $port, O_RDWR | O_EXCL) || die "$port: $!"; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
foreach my $byte ( split(//,$send) ) { |
|
54
|
0
|
0
|
|
|
|
|
warn "#>> ",dump($byte),$/ if $debug; |
|
55
|
0
|
|
|
|
|
|
syswrite $parallel, $byte, 1; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
close($parallel); |
|
59
|
|
|
|
|
|
|
# XXX and between send and receive |
|
60
|
0
|
0
|
|
|
|
|
sysopen( $parallel, $port, O_RDWR | O_EXCL) || die "$port: $!"; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $response; |
|
63
|
0
|
|
|
|
|
|
while ( ! sysread $parallel, $response, 1 ) { sleep 0.1 }; # XXX wait for 1st char |
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $byte; |
|
65
|
0
|
|
|
|
|
|
while( sysread $parallel, $byte, 1 ) { |
|
66
|
0
|
0
|
|
|
|
|
warn "#<< ",dump($byte),$/ if $debug; |
|
67
|
0
|
0
|
|
|
|
|
last if $byte eq "\x00"; |
|
68
|
0
|
|
|
|
|
|
$response .= $byte; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
0
|
|
|
|
|
|
close($parallel); |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $response; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |