• Post Reply Bookmark Topic Watch Topic
  • New Topic

control parallel port using Java Comm API

 
rex22
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/* Currently, I am working on controlling IBM Parallel Port using */
/* Java Communication API. And i faced a few problems and wish */
/* can get help as soon as possible. All helps are highly appreciated. */
DOSone.writeByte(0x90); ------- Statement 1
When the LED attached with parallel port are connected with the computer, Data Pin 3,4,5,6,7,8
are lighted. Although i tried to change to different values, same results are obtained.
May I know why this happened? and any solution?
System.out.println("You have come here."); ------Statement 2
After the LED is lighted, the Java program does not return back to DOS mode and print out
the above sentence. Can i make hypotheses that Java are platform independent, that's why
there is no way to return to Windows Dos mode? Or any solution available?
The source code is obtained from http://www.geocrawler.com/archives/3/196/1999/8/50/2586646/ and some modification has been done.
/* modified by cclee */
/* date: 23.08.2001 */
/* Platform : Windows 98 & JDK1.2 */
import javax.comm.*;
import javax.comm.ParallelPort;
import java.util.*;
import java.lang.*;
import java.io.*;
public class TestApp
{
static CommPortIdentifier CPIone;
static Enumeration Eone;
static ParallelPort Pone;
static OutputStream OSone;
static DataOutputStream DOSone;
public static void main (String arg[])
{
Eone=CommPortIdentifier.getPortIdentifiers();
while(Eone.hasMoreElements())
{
CPIone=(CommPortIdentifier)Eone.nextElement();
if((CPIone.getPortType()==CommPortIdentifier.PORT_PARALLEL)&&((CPIone.getName()).compareTo("LPT1")==0))
{
try
{
Pone=(ParallelPort)CPIone.open("TestApp",3000);
}catch(PortInUseException e){}
System.out.println(CPIone.getCurrentOwner());

System.out.println(Pone.getMode());
System.out.println(CPIone.getPortType());
try
{
Pone.setMode(1);
}catch(UnsupportedCommOperationException e)
{
System.out.println("Unsupported byte mode.");
}
System.out.println("unidirectional");
}
}
try
{
OSone=Pone.getOutputStream();
DOSone = new DataOutputStream(OSone);

/*where to send the data to the printer port */
DOSone.writeByte(0x90); ------- Statement 1
System.out.println("You have come here."); ------Statement 2
}
catch(IOException e)
{
System.out.println("You are in IOexception");
e.printStackTrace();
}
}
}

Below are the circuit that i used for my testing


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!