Device::ParallelPort::drv::script - Call a script to do your hardware actions


Device-ParallelPort documentation Contained in the Device-ParallelPort distribution.

Index


Code Index:

NAME

Top

Device::ParallelPort::drv::script - Call a script to do your hardware actions

DESCRIPTION

Top

This basic drive allows you to write a completely seperate piece of code to control the bits, and still allow the usual interface. This is fairly pointeless interface by itself but does allow for testing and unusal circumstances.

Really there is not much point in this module, however it was useful at one time to me, and therefore may be to others.

CAPABILITIES

Top

Operating System

Totally depends on the scripts available... but this code is independent.

Special Requirements

Anything special about the scripts, eg: root/not etc. If the script requires root access then so does this system (unless you are using unix setuid)

Script parameters

The script has the following substituted before execution automatically. Things like port should be included in the parameter automatically.

        {offset}        Which byte to set, from 0
        {byte}          What is the byte to set

HOW IT WORKS

Top

LIMITATIONS

Top

This system can only write a byte to the output script, it uses the previouslly set values to return the current state of the output.

If you want to set the base port address, that is up to you in the script. For example your script could be along the lines of

	myscript 0x378 {offset} {byte}

COPYRIGHT

Top

AUTHOR

Top

Scott Penrose scottp@dd.com.au, http://linux.dd.com.au/

SEE ALSO

Top

Device::ParallelPort


Device-ParallelPort documentation Contained in the Device-ParallelPort distribution.

package Device::ParallelPort::drv::script;
use strict;
use Carp;

use base qw/Device::ParallelPort::drv/;

sub init {
        my ($this, $str, @params) = @_;
        $this->{DATA}{SCRIPT} = $str;
        my ($script, $rest) = split(/ /, $str, 2);
        unless (-x $script) {
                croak "Must provide a script as the parameter, $script not executable";
        }
        $this->{BYTES} = [];
}

sub INFO {
        return {
                'os' => 'any',
                'type' => 'byte',
        };
}

sub set_byte {
        my ($this, $byte, $val) = @_;

        # Get the script and the byte
        my $script = $this->{DATA}{SCRIPT};
        $this->{BYTES}[$byte] = $val;

        # Set the values
        $script =~ s/{offset}/$byte/g;
        $script =~ s/{byte}/$val/g;

        # Execute
        print STDERR "Script exec - $script\n" if ($this->{DEBUG});
        system($script);
}

sub get_byte {
        my ($this, $byte) = @_;
        return $this->{BYTES}[$byte];
}

1;