parport.ParallelPort Documentation

parport
Class ParallelPort

java.lang.Object
  |
  +--ParallelPort

public class ParallelPort
extends java.lang.Object
Read and write bytes through parallel printer ports. For example:
  import parport.ParallelPort;

  class SimpleIO {
    public static void main ( String []args )
    {
      ParallelPort lpt1 = new ParallelPort(0x378); // 0x378 is normally the base address for the LPT1 port
      int aByte;
      aByte = lpt1.read(); // read a byte from the port's STATUS pins
      System.out.println("Input from parallel port: " + aByte);
      aByte = aByte >> 2; // a simple and irrelevant operation
      lpt1.write(aByte); // write a byte to the port's DATA pins
      System.out.println("Output to port: " + aByte);
    }
  }
This class defines two native methods that are implemented in Visual C++ 6.0 for the Windows version and plain old C for the Linux version.

See Also:
Java Native Interface, Interfacing the Parallel Port

Field Summary
 int portBase
          The parallel port's base address
 
Constructor Summary
ParallelPort(int portBase)
          Create an interface to a parallel port using its base address
 
Method Summary
 int read()
          Read one byte from the STATUS pins of this parallel port object.
static int readOneByte(int address)
          Reads one byte from the specified address.
 void write(int oneByte)
           Write one byte to the DATA pins of this parallel port object.
static void writeOneByte(int address, int oneByte)
          Writes one byte to the specified address.

Field Detail

portBase

private int portBase
The parallel port's base address
Constructor Detail

ParallelPort

public ParallelPort(int portBase)
Create an interface to a parallel port using its base address

Parameters:
portBase - The parallel port's base address.
Method Detail

read

public int read()
Read one byte from the STATUS address of a parallel port. The byte read contains 5 valid bits, corresponding to 5 pins of input from the STATUS pins of the parallel port (the STATUS is located at "portBase + 1", e.g. the STATUS address for LPT1 is 0x379).

This diagram shows the content of the byte:
        Bit | Pin # | Printer Status  | Inverted
       -----+-------+-----------------+-----------
         7  |  ~11  | Busy            |   Yes
         6  |   10  | Acknowledge     |
         5  |   12  | Out of paper    |
         4  |   13  | Selected        |
         3  |   15  | I/O error       |
Note that Pin 11 is inverted, this means that "Hi" input on pin
means 0 on bit 7, "Low" input on pin means 1 on bit 7.

Returns:
The byte read from the STATUS pins of the port.

write

public void write(int oneByte)
Write one byte to the DATA address of a parallel port. The byte is written to the DATA pins of the port. The DATA pins are located at the base address of the port (e.g. DATA address for LPT1 is 0x378).

This diagram shows how the byte is written:
         Bit | Pin # | Printer DATA
        -----+-------+--------------
          7  |   9   |   DATA 7
          6  |   8   |   DATA 6
          5  |   7   |   DATA 5
          4  |   6   |   DATA 4
          3  |   5   |   DATA 3
          2  |   4   |   DATA 2
          1  |   3   |   DATA 1
          0  |   2   |   DATA 0
Parameters:
oneByte - the byte to write to the DATA pins.

readOneByte

public static int readOneByte(int address)
Reads one byte from any address on your PC's I/O memory
Parameters:
address - the address to read from. Normally it is the STATUS address of a parallel port.
Returns:
The byte read from the specified address.

writeOneByte

public static void writeOneByte(int address,
                                int oneByte)
Writes one byte to any address on your PC's I/O memory
Parameters:
address - The address to write at. Normally it is the DATA address of a parallel port.
oneByte - The byte to write.
 
Submit a bug or feature - Version 1.4.1 of Java Platform API Specification
This software is distributed "as is". It is Freeware. Any use of this software is by the users own risk.