Sunday, January 27, 2008

CPAN rocks

http://search.cpan.org/~scott/Device-ParallelPort-1.00/lib/Device/ParallelPort.pm

Found a module in CPAN for PERL. I'll be integrating this with Ajax calls from the website.

NAME ^

Device::ParallelPort - Parallel Port Driver for Perl
SYNOPSIS ^

my $port = Device::ParallelPort->new();
$port->set_bit(3,1);
print $port->get_bit(3) . "\n";
print ord($port->get_byte(0)) . "\n";
$port->set_byte(0, chr(255));

DESCRIPTION ^

A parallel port driver module. This module provides an API to all parallel ports, by providing the ability to write any number of drivers. Modules are available for linux (both directly and via parport), win32 and a simple script version.

NOTE - This actual module is a factory class only - it is used to automatically return the correct class and has not other intelligence / purpose.
DRIVER MODULES ^

NOTE - You MUST load one of the drivers for your operating system before this module will correctly work - they are in separate CPAN Modules.

L - Direct hardware access to a base address.
L - Linux access to /dev/parport drivers
L - Run a script with parameters
L - Pretending byte driver for testing
L - Pretending bit driver for testing
L - Windows 32 DLL access driver

DEVICE MODULES ^

L - An example that can talk to a printer
L - Simple JayCar electronics latched, addressable controller
L - SerialFlash of bits - useful for many driver chips

METHODS ^
new
CONSTRUCTOR ^

new ( DRIVER )

Creates a Device::ParallelPort.

METHODS ^

get_bit( BITNUMBER )

You can get any bit that is supported by this particular driver. Normally you can consider a printer driver having 3 bytes (that is 24 bits would you believe). Don't forget to start bits at 0. The driver will most likely croak if you ask for a bit out of range.
get_byte ( BYTENUMBER )

Bytes are some times more convenient to deal with, certainly they are in most drivers and therefore most Devices. As per get_bit most drivers only have access to 3 bytes (0 - 2).
set_bit ( BITNUMBER, VALUE )

Setting a bit is very handy method. This is the method I use above all others, in particular to turn on and off rellays.
set_byte ( BYTENUMBER, VALUE )

Bytes again. Don't forget that some devices don't allow you to write to some locations. For example the stock standard parallel controller does not allow you to write to the status entry. This is actually a ridiculous limitation as almost all parallel chips allow all three bytes to be inputs or outputs, however drivers such as linux parallel port does not allow you to write to the status byte.

NOTE - VALUE must be a single charachter - NOT an integer. Use chr(interger).
get_data ( )
set_data ( VALUE )
get_control ( )
set_control ( VALUE )
get_status ( )
set_status ( VALUE )

The normal parallel port is broken up into three bytes. The first is data, second is control and third is status. Therefore for this reason these three bytes are controlled by the above methods.

No comments: