controlling parallel port using Java Comm API
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rex22_rex22
Posted On:   Monday, August 27, 2001 10:55 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 mod   More>>

/* 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?


This is the source code which obtain from
http://www.geocrawler.com/archives/3/196/1999/8/50/2586646/ and some slight
changes have been made

/* 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    <<Less
About | Sitemap | Contact