ch.aplu.util
Class LptPort

java.lang.Object
  extended by ch.aplu.util.LptPort

public class LptPort
extends java.lang.Object

Support to write to and read from the LPT port registers on a Windows operating system. Uses the Java Native Interface (JNI) and INPOUT32.DLL by Jan Axelsons. Circumvents Windows protection of I/O-ports on W2K, XP, W2003 OS by installing a driver on the fly (when opening the port). INPOUT32.DLL and JLPTPORT.DLL needed in file system path (distributed with Examples, Chap. 34).


Field Summary
static int ACKNOWLEDGE
          Bit value of Acknowledge line in status register of LPT port (at base address + 1).
static int AUTOLINEFEED
          Bit value of Auto Linefeed line in control register of LPT port (at base address + 2).
static int BUSY
          Bit value of Busy line in status register of LPT port (at base address + 1).
static int DATA0
          Bit value of bit 0 in data register of LPT port (at base address).
static int DATA1
          Bit value of bit 1 in data register of LPT port (at base address).
static int DATA2
          Bit value of bit 2 in data register of LPT port (at base address).
static int DATA3
          Bit value of bit 3 in data register of LPT port (at base address).
static int DATA4
          Bit value of bit 4 in data register of LPT port (at base address).
static int DATA5
          Bit value of bit 5 in data register of LPT port (at base address).
static int DATA6
          Bit value of bit 6 in data register of LPT port (at base address).
static int DATA7
          Bit value of bit 7 in data register of LPT port (at base address).
static int ERROR
          Bit value of Error line in status register of LPT port (at base address + 1).
static int INITRESET
          Bit value of Init/Reset line in control register of LPT port (at base address + 2).
static int PAPEREND
          Bit value of Paper End line in status register of LPT port (at base address + 1).
static int SELECT
          Bit value of Select line in status register of LPT port (at base address + 1).
static int SELECTIN
          Bit value of Select In line in control register of LPT port (at base address + 2).
static int STROBE
          Bit value of Strobe line in control register of LPT port (at base address + 2).
 
Constructor Summary
LptPort()
           
 
Method Summary
 void close()
          Close port Do nothing, if port is not open.
 boolean isOpen()
          Return true if port is open, false otherwise.
 int open(int address)
          Open LPT port at specified base address, e.g. 0x378.
 int readData()
          Return content of data port (at base address) in lower byte.
 int readStatus()
          Return content of status port (at base address + 1) in lower byte.
 int writeControl(int data)
          Write lower byte of data into control port (at base address + 2).
 int writeData(int data)
          Write lower byte of data into data port (at base address).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA0

public static final int DATA0
Bit value of bit 0 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA1

public static final int DATA1
Bit value of bit 1 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA2

public static final int DATA2
Bit value of bit 2 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA3

public static final int DATA3
Bit value of bit 3 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA4

public static final int DATA4
Bit value of bit 4 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA5

public static final int DATA5
Bit value of bit 5 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA6

public static final int DATA6
Bit value of bit 6 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

DATA7

public static final int DATA7
Bit value of bit 7 in data register of LPT port (at base address). Data may be written (to the external device) or read (from the external device).

See Also:
Constant Field Values

ERROR

public static final int ERROR
Bit value of Error line in status register of LPT port (at base address + 1). The external device informs the program about special conditions.

See Also:
Constant Field Values

SELECT

public static final int SELECT
Bit value of Select line in status register of LPT port (at base address + 1). The external device informs the program about special conditions.

See Also:
Constant Field Values

PAPEREND

public static final int PAPEREND
Bit value of Paper End line in status register of LPT port (at base address + 1). The external device informs the program about special conditions.

See Also:
Constant Field Values

ACKNOWLEDGE

public static final int ACKNOWLEDGE
Bit value of Acknowledge line in status register of LPT port (at base address + 1). The external device informs the program about special conditions.

See Also:
Constant Field Values

BUSY

public static final int BUSY
Bit value of Busy line in status register of LPT port (at base address + 1). The external device informs the program about special conditions.

See Also:
Constant Field Values

STROBE

public static final int STROBE
Bit value of Strobe line in control register of LPT port (at base address + 2). The program sends some special commands to the external device.

See Also:
Constant Field Values

AUTOLINEFEED

public static final int AUTOLINEFEED
Bit value of Auto Linefeed line in control register of LPT port (at base address + 2). The program sends some special commands to the external device.

See Also:
Constant Field Values

INITRESET

public static final int INITRESET
Bit value of Init/Reset line in control register of LPT port (at base address + 2). The program sends some special commands to the external device.

See Also:
Constant Field Values

SELECTIN

public static final int SELECTIN
Bit value of Select In line in control register of LPT port (at base address + 2). The program sends some special commands to the external device.

See Also:
Constant Field Values
Constructor Detail

LptPort

public LptPort()
Method Detail

open

public int open(int address)
Open LPT port at specified base address, e.g. 0x378. Return 0 if successful, -1 otherwise.


isOpen

public boolean isOpen()
Return true if port is open, false otherwise.


writeData

public int writeData(int data)
Write lower byte of data into data port (at base address). Upper byte is ignored. Return -1 if port is not open, 0 otherwise


writeControl

public int writeControl(int data)
Write lower byte of data into control port (at base address + 2). Upper byte is ignored. Return -1 if port is not open, 0 otherwise


readData

public int readData()
Return content of data port (at base address) in lower byte. Upper byte is 0. Return -1 if port is not open.


readStatus

public int readStatus()
Return content of status port (at base address + 1) in lower byte. Upper byte is 0. Return -1 if port is not open.


close

public void close()
Close port Do nothing, if port is not open.