Step 2: Creating the Parallel Port Controlled Program.

As root you will want to compile the following C program. Normally you would not want to do anything as root directly, but this is an exception.

$ su
# gcc -o lptout lptout.c
# exit
lptout.c (you will need to create this file on the server)
The file is now attached that I used.
 * Simple parallel port output control program for Linux
 * Written and copyright by Tomi Engdahl 1998
 * (e-mail: tomi.engdahl@hut.fi)
 * The program output the data value to PC parallel port data pins
 * (default lpt1 I/O address 0x378). The data values are given as the
 * command line parameter to the program. The number can be
 * in decimal (0..255) or hexadecimal format (0x00..0xFF).

  /* See the attached file for the includes.
/* &#lt; replace with a < symbol and &#gt;  replace with a > symbol */
#include &#lt;stdio.h&#gt;
#include &#lt; stdlib.h&#gt;
#include &#lt60;unistd.h&#gt;
#include &#lt;sys/io.h&#gt;

#define base 0x378           /* printer port base address */

main(int argc, char **argv)
  int value;

  if (argc!=2)
    fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n"), exit(1);
  if (sscanf(argv[1],"%i",&value)!=1)
    fprintf(stderr, "Error: Parameter is not a number.\n"), exit(1);
  if ((value<0) || (value>255))
    fprintf(stderr, "Error: Invalid numeric value. The parameter number must be between 0 and 255\n"), exit(1);
  if (ioperm(base,1,1))
    fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);

  outb((unsigned char)value, base);

Update: I included the source file I used separately since  www.instructables.com wiped part of it.

Instructables seems to have removed the #includes in the code.<br><br>I guess the following are needed: just imagine the names within angle brackets...<br><br>#include stdio.h <br>#include stdlib.h <br>#include unistd.h <br>#include asm/io.h<br><br>
Thanx for catching that, I thought I had caught and fixed it. Anyway I did upload the lptout.c that I used and the original version. <br> <br>For some linux variants, you may want to use sys/io.h instead of asm/io.h.

About This Instructable




Bio: computoman.blogspot.com Bytesize articles instead of a trilogy in one post.
More by Computothought:Coffeepot meals Easy sun hat Easy cakes and pies. 
Add instructable to: