Re: [PARPORT] inb (problems)

From: Steven Griffiths (
Date: Fri Apr 07 2000 - 04:13:40 EDT

  • Next message: Jochen Hoenicke: "Re: [PARPORT] Parallel Zip100 drive problems, more details..."

    AFAIK you can't read from the control ports - you only _write_ to the
    control ports and _read_ from the status ports. Although I seem to remember
    reading in the parport driver code that some hardware does allow this

    ----- Original Message -----
    From: "Samuel Ace Winchenbach" <>
    To: <>
    Sent: Friday, April 07, 2000 3:24 AM
    Subject: [PARPORT] inb (problems)

    Hello, I have been having troubles reading values from the control port
    (base + 2 == 0x37A) the following code sets all the pins on the control
    port high. I do this by "poking" the value 4 to 0x37A. Seeing the two
    least significant and the last bit are all inverted, to set the line high
    you poke a zero. bit 2 is non-inverted so to set the pin high, set the bit
    to 1 (which happens to be 4). Then I put it in an infinite loop... waiting
    for an external device to pull a pin low. Seeing that the control port has
    read/write access I should be able to tell when something pulls the line
    low. Can anyone help me with this?

    Thank you.

    #include <unistd.h>
    #include <sys/io.h>
    #include <stdlib.h>
    #include <stdio.h>

    #define BASE_PORT 0x378

    int main(int argc, char * argv[])
      file://Give Permissons
      ioperm(BASE_PORT + 2,1,1);

      file://Set BASE_PORT + 2 to 0100 = 0x4 (I,N,I,I)
      outb(0x4,BASE_PORT + 2);

      file://Set up i and last state. These two will be compared
      file://to determine if the bits have changed.
      int i;
      int laststate = inb(BASE_PORT + 2)&0xF;

      file://display that everything is set... and the current
      file://value of the port.
      printf("\nReady: %d\n", laststate);

      file://infinite loop.
        file://get the 4 least signifigant bits of 0x37A
        i = inb(BASE_PORT + 2)&0xF;

        file://If all the bits are being pulled low ...
        if (i == 11)
          file://close permissions...
          ioperm(BASE_PORT + 2,1,0);
          file://and exit.
          return (0);
        file://determine if anything has changed.
        if (i != laststate)
          printf("Something has changed!");
        if ((i & 1) != (laststate & 1))
          printf("\nBit 0 changed!\n");
        if ((i & 2) != (laststate & 2))
          printf("\nBit 1 changed!\n");
        if ((i & 4) != (laststate & 4))
          printf("\nBit 2 changed!\n");
        if ((i & 8) != (laststate & 8))
          printf("\nBit 3 changed!\n");

        file://set last state equal to i.
        laststate = i;

    // Samuel Ace Winchenbach
    // University of Maine
    // Electrical Engineering
    // (207) 571-7535

    -- To unsubscribe, send mail to: --
    -- with the single word "unsubscribe" in the body of the message. --

    -- To unsubscribe, send mail to: --
    -- with the single word "unsubscribe" in the body of the message. --

    This archive was generated by hypermail 2b29 : Fri Apr 07 2000 - 04:10:00 EDT