| 1 | package Printer::EVOLIS::Parallel; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use POSIX; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Data::Dump qw(dump); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | 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 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 24 | 0 | 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 | 0 | ▶ | sub command { | ||||||||
|
Subroutine
command: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 37 | 0 | my ( $self, $send ) = @_; | |||||||||
| 38 | 0 | ▶ | $send = "\e$send\r" unless $send =~ m/^\e/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | $self->send( $send ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub send { | ||||||||
|
Subroutine
send: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||
| 43 | 0 | my ( $self, $send ) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $port = $self->{port}; | |||||||||
| 46 | 0 | ▶ | die "no port $port" unless -e $port; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | my $parallel; | |||||||||
| 49 | |||||||||||
| 50 | # XXX we need to reopen parallel port for each command | ||||||||||
| 51 | 0 | ▶ | sysopen( $parallel, $port, O_RDWR | O_EXCL) || die "$port: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 0 | foreach my $byte ( split(//,$send) ) { | |||||||||
| 54 | 0 | ▶ | warn "#>> ",dump($byte),$/ if $debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | syswrite $parallel, $byte, 1; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | close($parallel); | |||||||||
| 59 | # XXX and between send and receive | ||||||||||
| 60 | 0 | ▶ | sysopen( $parallel, $port, O_RDWR | O_EXCL) || die "$port: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | my $response; | |||||||||
| 63 | 0 | ▶ | while ( ! sysread $parallel, $response, 1 ) { sleep 0.1 }; # XXX wait for 1st char | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | my $byte; | |||||||||
| 65 | 0 | ▶ | while( sysread $parallel, $byte, 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | warn "#<< ",dump($byte),$/ if $debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | ▶ | last if $byte eq "\x00"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | $response .= $byte; | |||||||||
| 69 | } | ||||||||||
| 70 | 0 | close($parallel); | |||||||||
| 71 | |||||||||||
| 72 | 0 | return $response; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | 1; | |||||||||