Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

control parallel port using Java Comm API

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic