The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

controll parallel port using Java Comm API

Posted by rex22 on August 23, 2001 at 11:51 PM

/* 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 slight modification is 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






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us