Computing.Net > Forums > Programming > Control parallel port using java

Control parallel port using java

Reply to Message Icon

Original Message
Name: coolzombee
Date: March 21, 2004 at 18:11:36 Pacific
Subject: Control parallel port using java
OS: Win XP
CPU/Ram: P4/128
Comment:

I'm trying to write to the parallel port to control the lighting up of LEDs. By using Parport i can read and write byte to the port. However, i could not control the LEDs base on what i have written to the port. Plz help...


Report Offensive Message For Removal


Response Number 1
Name: coolzombee
Date: March 21, 2004 at 18:22:27 Pacific
Subject: Control parallel port using java
Reply: (edit)

This is the java codes i have written to read and write to parallel port.

import parport.ParallelPort;

class ProIO {
public static void main ( String []args )
{
ParallelPort lpt1 = new ParallelPort(0x378);
int aByte;
aByte = lpt1.readOneByte(0x378);
System.out.println("Input from parallel port: " + aByte);
lpt1.write(255);
System.out.println("Output to port: " + lpt1.readOneByte(0x378));
}
}

But the codes could not control Led


Report Offensive Follow Up For Removal

Response Number 2
Name: JackG
Date: March 22, 2004 at 00:26:32 Pacific
Subject: Control parallel port using java
Reply: (edit)

Not sure what you are trying to do there (never bothered to learn Java so I may not understand your code correctly). But all your code seems able to do (other than display some messages with the port read bits) is write all eight data bits high on the parallel printer port interface (lpt1:write(255);).

Now what that does (or you expect it to do) depends on how the "LEDs" are connected. You gave no clue, so there no way to determine what that command will do. But from the parallel port adapters point of view that command will: Set the output of the Open Collector outputs "high" which will allow them to float "open" to a state if an external current source pulls them to that state.

Now if you had done a (lpt1.write(0);) the result from the parallel port adapters point of view would be: Set the output of the Open Collector outputs "low" which will pull their output line to "ground" reference and sink up to 24ma of current to the ground reference (before burning out).

So to understand what is wrong, we need to understand how you have the LEDs hooked up in relation to your external current source. Note that the parallel interface only provides a "ground" reference pin and Open Collector outputs that can pull the data lines to the "ground" reference. It at no point can provide a current source (voltage) for operating devices such as LEDs. For example if you connected a resistor and LED in series between one of the data pins and the ground pin, it would do nothing, regardless of what your program did.

If however, you had a suitable current source (battery) with its negative side connected to the "ground" pin through a suitable low value resistor to prevent damage should there be a short, and a LED in series with a suitable resistor to limit the current to a maximum of 24ma or much less, with one end connected to a port pin and the other connected to the current source rail (positive side of battery), then when a ONE or high bit is written to the parallel port the LED would be OFF, and when a ZERO or low bit is written to the parallel port the LED, having a current sink, would come on.

There are of course other ways to wire this with Open Collector outputs, so how it works depends on the exact hardware design of your LEDs and associated resistors and current source.



Report Offensive Follow Up For Removal

Response Number 3
Name: coolzombee
Date: March 23, 2004 at 19:39:32 Pacific
Subject: Control parallel port using java
Reply: (edit)

Thanks for the advice.


Report Offensive Follow Up For Removal

Response Number 4
Name: coolzombee
Date: March 24, 2004 at 23:54:36 Pacific
Subject: Control parallel port using java
Reply: (edit)

May i know if i can connec a circuit device directly to the parallel port? For instance a LED, will it lit up upon receiving a logic high at the pins?


Report Offensive Follow Up For Removal

Response Number 5
Name: JackG
Date: March 25, 2004 at 23:51:35 Pacific
Subject: Control parallel port using java
Reply: (edit)

No, it can provide no current to power the LED. The LED is also a diode, so the direction it is connected to the external power source is important. If you use a battery, a resistor and a diode, you should be able to touch the three together and have the diode/LED light up. Then making sure the negative side of the circuit (and a resistor) is connected to a ground pin, and the positive side of the battery and the LED are connected to the parallel port data pin, it should work, if your java code is actually able to communicate with the parallel port hardware.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Control parallel port using java 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge