tumoheat has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am trying to write to the parallel port pins from a Perl program running Ubuntu Linux, to light up led's on a bread board. I've already accomplished this on this same box using a C program, but I cannot get my code below to work. I believe the problem is with the line:
$parport = Device::ParallelPort->new('auto:0');

I've tried different variables between the ('') ticks, but nothing has worked. I use Perl on my web pages for forms, but this has me stumped. Any help would be appreciated. Code is below:

#!/usr/bin/perl require "subparseform.lib"; &Parse_Form; print "Set-cookie: cart_id=1234; user_id=123;\n"; print "Content-type: text/html\n\n"; use strict; use CGI; use Device::ParallelPort; # use Device::ParallelPort::drv; # use Device::ParallelPort::drv::linux # use Device::ParallelPort::drv::parport # Set up your parallel port object and tell it what driver to use. #my $parport = Device::ParallelPort->new('auto:0'); print "It works!!!";

Replies are listed 'Best First'.
Re: Accessing parallel ports
by roboticus (Chancellor) on Dec 11, 2010 at 23:23 UTC
Re: Accessing parallel ports
by GrandFather (Saint) on Dec 12, 2010 at 01:43 UTC

    You ask a question about parallel ports but show code that is mostly CGI oriented. Why is that? What are you actually trying to do and what is actually failing?

    It may help to focus on one problem at a time!

    True laziness is hard work
Re: Accessing parallel ports
by Marshall (Canon) on Dec 12, 2010 at 04:59 UTC
    As others have suggested, please take out the unnecssary CGI stuff. I looked at Device-ParallelPort-1.00 . It says (Driver) "Modules are available for linux (both directly and via parport), win32 and a simple script version.". It does not say anything about Ubuntu.

    I don't know how different Ubuntu and Linux are. This is low level device driver stuff and the "flavor" of Unix can make a considerable difference. What happened when you installed the Linux driver on Ubuntu? Device::ParallelPort::drv::linux or Device::ParallelPort::drv::parport ? I don't know for sure, but suspect that there was some problem with that.

    Device::ParallelPort is a front end to the appropriate driver (the ...drv::xxxx module) and won't work without a driver. There are a couple of "dummy drivers", drv::dummy_byte and drv::dummy_bit. Did you make any tests with one of those?

    I tried to figure out what "parport" is but didn't find much in a quick look. Sounds like it is something different than a regular device driver. I'd be curious to the C code/driver that you used, there may be a useful clue there. You can put it inbetween <readmore></readmore> tags so it doesn't clutter up things.

Re: Accessing parallel ports
by Khen1950fx (Canon) on Dec 12, 2010 at 08:32 UTC
    Device::ParallelPort::drv::linux is broken and won't make. I slimmed it down a little and tried this:
    #!/usr/bin/perl use strict; use warnings; use Device::ParallelPort; use Device::ParallelPort::drv::parport; my $parport = Device::ParallelPort->new; $parport->set_bit(3, 1); print $parport->get_bit(3), "\n", ord($parport->get_byte(0)), "\n", ord($parport->get_byte(1)), "\n", ord($parport->get_byte(2)), "\n";
      Thanks Khen1950fx,

      I actually got it to work using the code below. I changed auto:0 to auto:1 and that did it.

      require "subparseform.lib"; &Parse_Form; print "Set-cookie: cart_id=1234; user_id=123;\n"; print "Content-type: text/html\n\n"; use strict; use CGI; use Device::ParallelPort; # use Device::ParallelPort::drv::linux # Set up your parallel port object and tell it what driver to use. my $parport = Device::ParallelPort->new('auto:1'); # $parport->set_bit(0,1); # $parport->set_bit(1, 1); $parport->set_bit(2, 1); $parport->set_bit(3, 1); $parport->set_bit(4, 1); $parport->set_bit(5, 1); $parport->set_bit(6, 1); $parport->set_bit(7, 1);

      If I don't comment out the CGI lines I get an Internal Server Error, that's why I have them. Is there a serious problem with doing it this way?

        tumoheat:

        If you check your server logs, I bet it's complaining about permissions. If so, talk to your system administrator about getting permission to access the parallel port for your web server account.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

      Thanks Khen1950fx, I actually got it to work using the code below. I changed auto:0 to auto:1 and that did it. require "subparseform.lib"; &Parse_Form; print "Set-cookie: cart_id=1234; user_id=123;\n"; print "Content-type: text/html\n\n"; use strict; use CGI; use Device::ParallelPort; # use Device::ParallelPort::drv::linux # Set up your parallel port object and tell it what driver to use. my $parport = Device::ParallelPort->new('auto:1'); # $parport->set_bit(0,1); # $parport->set_bit(1, 1); $parport->set_bit(2, 1); $parport->set_bit(3, 1); $parport->set_bit(4, 1); $parport->set_bit(5, 1); $parport->set_bit(6, 1); $parport->set_bit(7, 1); If I comment out the CGI lines I get an Internal Server Error, that's why I have them. Is there a serious problem with doing it this way?
Re: Accessing parallel ports
by NiJo (Friar) on Dec 12, 2010 at 19:53 UTC
    I'd call it a major security flaw of your linux distribution if the default web server user has hardware access.

    But without error messages it is just guessing.