|
|
java.lang.Object | +--ParallelPort
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 Windows, therefore
this class works only on Windows systems (if you would be interested in a linux version send
me an email, and I'll get to work on it).
Read the installation instructions.
| 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 |
private int portBase
| Constructor Detail |
public ParallelPort(int portBase)
| Method Detail |
public int read()
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
public void write(int oneByte)
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
public static int readOneByte(int address)
public static void writeOneByte(int address,
int oneByte)