I am trying to communicate with a Parallel Port via the package jnpout32reg (http://www.hytherion.com/beattidp/comput/pport.htm), a Java implementation of inpout32 (http://www.highrez.co.uk/downloads/inpout32/). I have tested inpout32 with a Parallel Port Tester (download. cnet. com/Parallel-Port-Tester/3000-2086_4-75940249.html), which seems to work perfectly. However, the java implementation does not seem to work.
package ioTest_reg;
import hardware.jnpout32.*;
public class ioTestReg
{
static short datum;
static short Addr;
static pPort lpt;
static void write()
{
datum = 0x001;
// Notify the console
System.out.println("Write to Port: " + Integer.toHexString(Addr) +
" with data = " + Integer.toHexString(datum));
//Write to the port
long start = System.currentTimeMillis();
long stop = System.currentTimeMillis();
while (stop-start < 10000){
lpt.output((short)0x001);
stop = System.currentTimeMillis();
}
System.out.println("Finished");
}
static void do_read_range()
{
// Try to read 0x378..0x37F, LPT1:
for (Addr=0x378; (Addr<0x380); Addr++) {
//Read from the port
datum = (short) lpt.input(Addr);
// Notify the console
System.out.println("Port: " + Integer.toHexString(Addr) +
" = " + Integer.toHexString(datum));
}
}
public static void main( String args[] )
{
lpt = new pPort();
Addr=0x378;
datum=0x01;
write();
// Try to read 0x378..0x37F, LPT1:
do_read_range();
}
}
The connection with the port is made and I can read from the ports (Port 378 returns 78, 379 returns 79 etc...). However, I cannot write output. No error is given, but nothing happens on the receiving side (as opposed to with the Parallel Port Tester).
When I use jnpout32pkg (a different version of jnpout32reg) instead, I get the following error (even though I installed everything similarly):
Exception in thread "main" java.lang.UnsatisfiedLinkError: ioTest_pkg.jnpout32.ioPort.Out32(SS)V
What am I doing wrong, and what is the difference between pkg and reg?
With some great help from Alexander Heimel (http://csflab.nin.knaw.nl/protocols/parallel-port-in-matlab) and Douglas Beattie (http://www.hytherion.com/beattidp/comput/pport.htm) I finally managed to find a workaround.
Python has no problem with inpout32 (or inpoutx64, depending on the version you use), so I wrote the following script.
If you only want to send a pulse (i.e. set it back to 0 immediately afterwards), use
sleep(0.002)
, followed byp.Out32(address,0)
. Following, you execute this script via Java, which is done with the following code:In which address is the parallel port address (0x378), and num is the to-be-written value.