Hi everybody.

I'm trying to turn on (or off) some LEDs conected to the Parallel Port. The program opens the port correctly but for some reason, it only allows me to use the LPT.MODE.SPP, even though that according to my Device Manager, the LPT1 mode is ECP.

Besides that, the program works until the "getOutputStream().write(256);" , where it just stays there...no error, no returning to system, no nothing. I have to manually stop the building of the program. Another weird thing is that I've tried setting the OutputBufferSize to 256 but no matter what I do, it always stays at 1024.

What i'm supposed to do is turn on 8 LEDs connected to the port; but even that's strange: the LEDs ARE turned on. The second I plug the cable, the all get turned on...maybe I'm supposed to turn them off?

Here's the code:

import java.lang.*;
import java.io.*;
import javax.comm.*;
import java.util.*;
/**
*
* @author inzomniac
*/
public class ParallelPortTest 
{
static Enumeration portList;
static CommPortIdentifier portId;
ParallelPort parallelPort;
/** Creates a new instance of ParallelPortTest */
public ParallelPortTest() 
{
try 
{
parallelPort = (ParallelPort) portId.open("Parallel", 2000);
try 
{
parallelPort.setMode(ParallelPort.LPT_MODE_SPP);
parallelPort.getOutputStream().write(256);
System.out.println("Mode: " + parallelPort.getMode());
System.out.println(parallelPort.getOutputBufferSize());
}
catch (IOException ex) 
{
ex.printStackTrace();
}
catch (UnsupportedCommOperationException ex) 
{
ex.printStackTrace();
}
} 
catch (PortInUseException e) 
{
e.printStackTrace();
}
}
 
public static void main(String args[])
{
portList = CommPortIdentifier.getPortIdentifiers(); 
while (portList.hasMoreElements()) 
{
portId = (CommPortIdentifier) portList.nextElement();
System.out.println(portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) 
{
if (portId.getName().equals("LPT1")) 
{
ParallelPortTest ppt = new ParallelPortTest(); 
}
}
}
}
 
 
}

thanks in advance!

Just in case anyone's having the same kind of problem, I've found this:

"I've read some messages on here regarding the Java Communications API
and the problems some have had with writing to parallel ports. I also
was puzzled by why I couldn't get this to work and then finally
figured out something that worked for me so am sharing this.

First of all, I am using Linux, downloaded the RXTX software,
downloaded the Sun x86/Solaris drivers for the Comm API (yes you need
this even for Windows/Linux), and installed per the instructions.
There were a few snags but the instructions contain much of what you
need to get past these.

The main problem I had was with properly wiring the cable from the
parallel port to drive my external circuits. You definately need some
sort of buffer chips to provide the interface from/to the parallel
port and your external devices (i.e. motors, LEDs, etc) and of course
power that circuit with an external 5V supply. That wasn't the problem
for me though. I had my data lines from the parallel port connected to
drive the external device...but it wasn't working with the Java
Communications API.

After some more tinkering, the trick was to tie the parallel port
status lines 10 & 11 (Ack and Busy) to low/ground and lines 12, 13, &
15 (paper out, select, & error) to high/5V. This should be done
through the output of a buffer chip though. I also tied lines 18-25 to
low/ground.

With that, the Java Communications API worked like a charm. The OS and
driver software must cleary require that the status input lines be
broadcasting signals that indicate the external device is OK...and by
tying the status lines mentioned to the proper signal levels...it
looks as if the external device is OK (i.e. no errors, not busy, has
paper, etc).

Previously, I had the status lines all tied to ground or had them
floating. After looking at a parallel port spec, I figured out what
the status lines are signalling to the system.

I hope this helps some of you trying to do something similar.

Regards,

Paul"

from
http://www.velocityreviews.com/forums/t125882-java-parallel-port-programming-with-the-java-communications-api.html

And I also found this:

"Hello World! [IMG]http://www.velocityreviews.com/forums/images/smilies/icon_smile.gif[/IMG]

Im currently studying automation , and just started experimenting with java in automation....
i wonder if any of you out there have any experiences with this? to put it simple , all I need is a sourcecode how to set a single pin on the printerport "high" or "low". could someone help me with this code? or at least where to start? javax.comm
right? please! [IMG]http://www.velocityreviews.com/forums/images/smilies/icon_smile.gif[/IMG]

please msg me! :

Bjørn Tore"

to which this guy answered:

"The Java comm API does not give you this level of control of twiddling individual pins. It is designed for talking to a device on the port using the IEEE-1284 standard.
--
Dale King"

it kinda figures...

Well, we decided to write a C program that writes a "1" in hexadecimal and use Java's Runtime.exec() method to execute it.

Thanks to everyone who read the post.

Hope this helps in the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.