| 1 | package Device::ParallelPort; | ||||||||||||
| 2 | 1 | ▶ | use vars qw/$AUTOLOAD $VERSION/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | $VERSION = "1.00"; | |||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | =head1 NAME | ||||||||||||
| 7 | |||||||||||||
| 8 | Device::ParallelPort - Parallel Port Driver for Perl | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||
| 11 | |||||||||||||
| 12 | my $port = Device::ParallelPort->new(); | ||||||||||||
| 13 | $port->set_bit(3,1); | ||||||||||||
| 14 | print $port->get_bit(3) . "\n"; | ||||||||||||
| 15 | print ord($port->get_byte(0)) . "\n"; | ||||||||||||
| 16 | $port->set_byte(0, chr(255)); | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||
| 19 | |||||||||||||
| 20 | A parallel port driver module. This module provides an API to all parallel ports, by | ||||||||||||
| 21 | providing the ability to write any number of drivers. Modules are available for linux | ||||||||||||
| 22 | (both directly and via parport), win32 and a simple script version. | ||||||||||||
| 23 | |||||||||||||
| 24 | NOTE - This actual module is a factory class only - it is used to automatically | ||||||||||||
| 25 | return the correct class and has not other intelligence / purpose. | ||||||||||||
| 26 | |||||||||||||
| 27 | =head1 DRIVER MODULES | ||||||||||||
| 28 | |||||||||||||
| 29 | NOTE - You MUST load one of the drivers for your operating system before this | ||||||||||||
| 30 | module will correctly work - they are in separate CPAN Modules. | ||||||||||||
| 31 | |||||||||||||
| 32 | L<Device::ParallelPort::drv::linux> - Direct hardware access to a base address. | ||||||||||||
| 33 | L<Device::ParallelPort::drv::parport> - Linux access to /dev/parport drivers | ||||||||||||
| 34 | L<Device::ParallelPort::drv::script> - Run a script with parameters | ||||||||||||
| 35 | L<Device::ParallelPort::drv::dummy_byte> - Pretending byte driver for testing | ||||||||||||
| 36 | L<Device::ParallelPort::drv::dummy_bit> - Pretending bit driver for testing | ||||||||||||
| 37 | L<Device::ParallelPort::drv::win32> - Windows 32 DLL access driver | ||||||||||||
| 38 | |||||||||||||
| 39 | =head1 DEVICE MODULES | ||||||||||||
| 40 | |||||||||||||
| 41 | L<Device::ParallelPort::Printer> - An example that can talk to a printer | ||||||||||||
| 42 | L<Device::ParallelPort::JayCar> - Simple JayCar electronics latched, addressable controller | ||||||||||||
| 43 | L<Device::ParallelPort::SerialFlash> - SerialFlash of bits - useful for many driver chips | ||||||||||||
| 44 | |||||||||||||
| 45 | =head1 METHODS | ||||||||||||
| 46 | |||||||||||||
| 47 | =head2 new | ||||||||||||
| 48 | |||||||||||||
| 49 | =head1 CONSTRUCTOR | ||||||||||||
| 50 | |||||||||||||
| 51 | =over 4 | ||||||||||||
| 52 | |||||||||||||
| 53 | =item new ( DRIVER ) | ||||||||||||
| 54 | |||||||||||||
| 55 | Creates a C<Device::ParallelPort>. | ||||||||||||
| 56 | |||||||||||||
| 57 | =back | ||||||||||||
| 58 | |||||||||||||
| 59 | =head1 METHODS | ||||||||||||
| 60 | |||||||||||||
| 61 | =over 4 | ||||||||||||
| 62 | |||||||||||||
| 63 | =item get_bit( BITNUMBER ) | ||||||||||||
| 64 | |||||||||||||
| 65 | You can get any bit that is supported by this particular driver. Normally you | ||||||||||||
| 66 | can consider a printer driver having 3 bytes (that is 24 bits would you | ||||||||||||
| 67 | believe). Don't forget to start bits at 0. The driver will most likely croak if | ||||||||||||
| 68 | you ask for a bit out of range. | ||||||||||||
| 69 | |||||||||||||
| 70 | =item get_byte ( BYTENUMBER ) | ||||||||||||
| 71 | |||||||||||||
| 72 | Bytes are some times more convenient to deal with, certainly they are in most | ||||||||||||
| 73 | drivers and therefore most Devices. As per get_bit most drivers only have | ||||||||||||
| 74 | access to 3 bytes (0 - 2). | ||||||||||||
| 75 | |||||||||||||
| 76 | =item set_bit ( BITNUMBER, VALUE ) | ||||||||||||
| 77 | |||||||||||||
| 78 | Setting a bit is very handy method. This is the method I use above all others, | ||||||||||||
| 79 | in particular to turn on and off rellays. | ||||||||||||
| 80 | |||||||||||||
| 81 | =item set_byte ( BYTENUMBER, VALUE ) | ||||||||||||
| 82 | |||||||||||||
| 83 | Bytes again. Don't forget that some devices don't allow you to write to some | ||||||||||||
| 84 | locations. For example the stock standard parallel controller does not allow | ||||||||||||
| 85 | you to write to the status entry. This is actually a ridiculous limitation as | ||||||||||||
| 86 | almost all parallel chips allow all three bytes to be inputs or outputs, | ||||||||||||
| 87 | however drivers such as linux parallel port does not allow you to write to the | ||||||||||||
| 88 | status byte. | ||||||||||||
| 89 | |||||||||||||
| 90 | NOTE - VALUE must be a single charachter - NOT an integer. Use chr(interger). | ||||||||||||
| 91 | |||||||||||||
| 92 | =item get_data ( ) | ||||||||||||
| 93 | |||||||||||||
| 94 | =item set_data ( VALUE ) | ||||||||||||
| 95 | |||||||||||||
| 96 | =item get_control ( ) | ||||||||||||
| 97 | |||||||||||||
| 98 | =item set_control ( VALUE ) | ||||||||||||
| 99 | |||||||||||||
| 100 | =item get_status ( ) | ||||||||||||
| 101 | |||||||||||||
| 102 | =item set_status ( VALUE ) | ||||||||||||
| 103 | |||||||||||||
| 104 | The normal parallel port is broken up into three bytes. The first is data, | ||||||||||||
| 105 | second is control and third is status. Therefore for this reason these three | ||||||||||||
| 106 | bytes are controlled by the above methods. | ||||||||||||
| 107 | |||||||||||||
| 108 | =back | ||||||||||||
| 109 | |||||||||||||
| 110 | =head1 LIMITATIONS | ||||||||||||
| 111 | |||||||||||||
| 112 | Lots... This is not a fast driver. It is designed to give you simple access to | ||||||||||||
| 113 | a very old device, the parallel chip. Don't, whatever you do, use this for | ||||||||||||
| 114 | drivers that need fast access. | ||||||||||||
| 115 | |||||||||||||
| 116 | =head1 DISCUSSIONS | ||||||||||||
| 117 | |||||||||||||
| 118 | =head2 Hardware | ||||||||||||
| 119 | |||||||||||||
| 120 | Following is the standard hardware table, so that you can find the correct pins | ||||||||||||
| 121 | and information. Note also the Inverted flag. | ||||||||||||
| 122 | |||||||||||||
| 123 | A number of real projects have been produced using Device::ParallelPort. For | ||||||||||||
| 124 | futher information see L<http://linux.dd.com.au/quest/os-perl/parallelport/> | ||||||||||||
| 125 | |||||||||||||
| 126 | Pin No (DB25) - Signal name - Direction - Register - bit - Inverted | ||||||||||||
| 127 | |||||||||||||
| 128 | 1 - nStrobe - Out - Control-0 - Yes | ||||||||||||
| 129 | |||||||||||||
| 130 | 2 - Data0 - In/Out - Data-0 - No | ||||||||||||
| 131 | |||||||||||||
| 132 | 3 - Data1 - In/Out - Data-1 - No | ||||||||||||
| 133 | |||||||||||||
| 134 | 4 - Data2 - In/Out - Data-2 - No | ||||||||||||
| 135 | |||||||||||||
| 136 | 5 - Data3 - In/Out - Data-3 - No | ||||||||||||
| 137 | |||||||||||||
| 138 | 6 - Data4 - In/Out - Data-4 - No | ||||||||||||
| 139 | |||||||||||||
| 140 | 7 - Data5 - In/Out - Data-5 - No | ||||||||||||
| 141 | |||||||||||||
| 142 | 8 - Data6 - In/Out - Data-6 - No | ||||||||||||
| 143 | |||||||||||||
| 144 | 9 - Data7 - In/Out - Data-7 - No | ||||||||||||
| 145 | |||||||||||||
| 146 | 1 - 0 nAck - In - Status-6 - No | ||||||||||||
| 147 | |||||||||||||
| 148 | 1 - 1 Busy - In - Status-7 - Yes | ||||||||||||
| 149 | |||||||||||||
| 150 | 1 - 2 Paper-Out - In - Status-5 - No | ||||||||||||
| 151 | |||||||||||||
| 152 | 1 - 3 Select - In - Status-4 - No | ||||||||||||
| 153 | |||||||||||||
| 154 | 1 - 4 Linefeed - Out - Control-1 - Yes | ||||||||||||
| 155 | |||||||||||||
| 156 | 1 - 5 nError - In - Status-3 - No | ||||||||||||
| 157 | |||||||||||||
| 158 | 1 - 6 nInitialize - Out - Control-2 - No | ||||||||||||
| 159 | |||||||||||||
| 160 | 1 - 7 nSelect-Printer - Out - Control-3 - Yes | ||||||||||||
| 161 | |||||||||||||
| 162 | 18-25 - Ground | ||||||||||||
| 163 | |||||||||||||
| 164 | =head1 BUGS | ||||||||||||
| 165 | |||||||||||||
| 166 | Not known yet. Windows support is new so expect some. | ||||||||||||
| 167 | |||||||||||||
| 168 | =head1 TODO | ||||||||||||
| 169 | |||||||||||||
| 170 | Refer to TODO list with packages and code. | ||||||||||||
| 171 | |||||||||||||
| 172 | =head1 HISTORY | ||||||||||||
| 173 | |||||||||||||
| 174 | History here covers central Device::ParallelPort and not the specific drivers, | ||||||||||||
| 175 | see them individually. For full history see Changes in the package. | ||||||||||||
| 176 | |||||||||||||
| 177 | =over | ||||||||||||
| 178 | |||||||||||||
| 179 | =item 0.04 - First release | ||||||||||||
| 180 | |||||||||||||
| 181 | Basic first release. Worked for Linux ROOT and Linux parport drivers only. | ||||||||||||
| 182 | Windows work only in early pre-alpha testing. | ||||||||||||
| 183 | |||||||||||||
| 184 | =item 1.00 - First stable release | ||||||||||||
| 185 | |||||||||||||
| 186 | Stable - I beleive it is stable, but this is only on my own testing and | ||||||||||||
| 187 | machines. Lots of imporvements to documentation, auto load modules etc. | ||||||||||||
| 188 | Improved use of perl. In particular this is the first release of Windows and a | ||||||||||||
| 189 | fully working auto driver. | ||||||||||||
| 190 | |||||||||||||
| 191 | =back | ||||||||||||
| 192 | |||||||||||||
| 193 | =head1 COPYRIGHT | ||||||||||||
| 194 | |||||||||||||
| 195 | Copyright (c) 2002,2003,2004 Scott Penrose. All rights reserved. | ||||||||||||
| 196 | This program is free software; you can redistribute it and/or modify | ||||||||||||
| 197 | it under the same terms as Perl itself. | ||||||||||||
| 198 | |||||||||||||
| 199 | =head1 AUTHOR | ||||||||||||
| 200 | |||||||||||||
| 201 | Scott Penrose L<scottp@dd.com.au>, L<http://linux.dd.com.au/> | ||||||||||||
| 202 | |||||||||||||
| 203 | =head1 SEE ALSO | ||||||||||||
| 204 | |||||||||||||
| 205 | L<Device::ParallelPort::drv> for developing a driver. | ||||||||||||
| 206 | |||||||||||||
| 207 | =cut | ||||||||||||
| 208 | |||||||||||||
| 209 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||
| 210 | 2 | my ($class, $drvstr, @params) = @_; | |||||||||||
| 211 | 2 | my $this = undef; | |||||||||||
| 212 | 2 | my ($drv, $str) = split(/:/, $drvstr, 2); | |||||||||||
| 213 | 2 | ▶ | $drv ||= "auto"; | ||||||||||
|
Condition50%1/2
$drv ||= "auto"
MC/DC0%0/1
$drv ||= "auto"
$drv
Truth table50%1/2
A
A= $drv
| |||||||||||||
| 214 | 2 | ▶ | $str ||= "0"; | ||||||||||
|
Condition50%1/2
$str ||= 0
MC/DC0%0/1
$str ||= 0
$str
Truth table50%1/2
A
A= $str
| |||||||||||||
| 215 | 1 | ▶ | eval qq{ | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 216 | use Device::ParallelPort::drv::$drv; | ||||||||||||
| 217 | \$this = Device::ParallelPort::drv::$drv->new(\$str, \@params); | ||||||||||||
| 218 | }; | ||||||||||||
| 219 | 2 | ▶ | croak "Device::ParallelPort unabel to create driver $drv (see Device::ParallelPort::drv::auto for further information) - $@" if ($@); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 220 | 2 | return $this; | |||||||||||
| 221 | } | ||||||||||||
| 222 | |||||||||||||
| 223 | 1 | 1; | |||||||||||