How to send a bit to the parallel port on Linux

It will be nice idea To do a network monitoring  project with LEDs, the fastest way is to use a Perl module called Device::ParallelPort, this module provides an API to all parallel ports. Device::ParallelPort has a number of drivers for multiple operating systems that includes a direct access module for Linux and the Linux ParPort driver. Work almost on  windows and FresBSD.

In python, there are a  module named pyparallel, and in c in userspace we may use Unix Standard and System Input/Output routines.

Here a simple example that make all LEDS connected to parallel port blinking 5 times.

  #include <stdio.h>
  #include <unistd.h>     /* For sleep(), ioperm(), inb() and outb(). */
  #include <sys/io.h>     /* Perhaps asm/io.h on other systems. */

  /* Address of the first parallel port. found in BIOS settings. */
  #define kDATA_REG (0x0378)          /* Base address = data register. */
  #define kSTAT_REG (DATA_REG + 1)    /* Status register. */
  #define kCONT_REG (DATA_REG + 2)    /* Control register. */

  int main()
      int i;

      if (ioperm(kDATA_REG, 1, 1))    /* Get permission to access this port. */
          printf("ioperm(%x) failed.\nYou must be root to execute!\n", kDATA_REG);
          return 1;

      /* Assume port is already in output mode (bit 5 in control register). */
      for (i = 0; i < 5; i++)        /* Let the LED(s) blink. */
          outb(255, kDATA_REG);       /* All 8 datalines high. */
          outb(0, kDATA_REG);         /* All 8 datalines low.  */

      return 0;

Author: Ali MEZGANI

My name is MEZGANI Ali. I was born back in 1978 in Rabat Morocco. My interests are Debian Linux , programming , science and music.

2 thoughts on “How to send a bit to the parallel port on Linux”

  1. I really miss that parallel port, my computer doesn’t have one 🙂
    Reminds me of some routines i wrote under windows for it. ( can be easly ported under linux, if only i could find the source files 😀 )
    Here is what it looked like:

    Maybe you could clear the permission when you are done, and why not fix that warning message:
    ali.c:20: warning: don’t make assumptions !


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s