Java program ini untuk Windows 2000/XP, sebelumnya download dulu:
http://www.geocities.com/Juanga69/parport/parport-win32.zip
setting partport
1.copy partport.dll
\jdk\bin
\WINDOWS\system32\
2.copy userport.sys
\WINDOWS\system32\drivers\
3.jalankan userport.exe
klik update/start
package parport;
public class ParallelPort {
/** The port base address (e.g. 0×378 is base address for LPT1) */
private int portBase;
/** To cunstruct a ParallelPort object,
* you need the port base address
*/
public ParallelPort (int portBase)
{
this.portBase = portBase;
}
/** Reads one byte from the STATUS pins of the parallel port.
*
* The byte read contains 5 valid bits, corresponing 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 0×379).
*
* 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.
*/
public int read ()
{
return ParallelPort.readOneByte (this.portBase+1);
}
/** Writes one byte to the DATA pins of 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 0×378).
*
* 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
*/
public void write (int oneByte)
{
ParallelPort.writeOneByte (this.portBase, oneByte);
}
/** Reads one byte from the specified address.
* (normally the address is the STATUS pins of the port)
*/
public static native int readOneByte (int address);
/** Writes one byte to the specified address
* (normally the address is the DATA pins of the port)
*/
public static native void writeOneByte (int address, int oneByte);
static
{
System.loadLibrary(“parport”);
}
}
—————————————————————————–
—————————————————————————–
import parport.ParallelPort;
import java.util.*;
class SetPortFun {
public static void main ( String []args ) {
int aByte,irand;
Random ranNum;
ParallelPort lpt1;
lpt1 = new ParallelPort(0×378); // 0×378 is normally the base address for the LPT1 port
ranNum=new Random();
while (true) {
aByte=ranNum.nextInt(256);
lpt1.write(0); //clear prev display
lpt1.write(aByte); // write random byte to the port’s DATA pins
System.out.println(“Pattern “+aByte);
try {
Thread.sleep(500); //sleep 500msec
}
catch (Exception e) {}
}
}
}