[Rxtx] [PARALLELPORT] read parallel port status

Andre-John Mas ajmas at sympatico.ca
Tue Sep 19 10:31:13 MDT 2006


Looking at the source, the line referenced by the error:

/home/bob/foo/tar/rxtx-2.1-7/build/../src/ParallelImp.c(517)

corresponds to the call to YACK(), for the context:

#if defined(WIN32)
  if(!ReadFile( (HANDLE)fd, buffer + bytes, left, (DWORD *)&ret, NULL )){
      YACK();
      ret = -1;
  }

The function YACK() is defined in win32termios.h. I am not sure
exactly what a 'bad function' is, but I wonder why the function
is defined using a macro, rather than just plain C?

Andre


> I downloaded rxtx-2.1-7-bins-r2.zip from the site. I copied
> RXTXcomm.jar, rxtxParallel.dll and rxtxSerial.dll into the same
> directory of SimpleRead.class. To have a device behind the parallelPort
> I have plug a parallel IOmega ZIP 100Mo.
> Then I launched 'java -cp RXTXcomm.jar;. SimpleRead' and I have this
> error for each parallelPort.getInputStream().read() :
> ---------------------------------------------------
> ERROR : java.io.IOException: Fonction incorrecte.
>  in readByte
> Error 0x1
> at /home/bob/foo/tar/rxtx-2.1-7/build/../src/ParallelImp.c(517):
> Fonction incorrecte.
> ---------------------------------------------------
> Here is the class I tested :
> ------------------------------------------------------------------------------
> /*
>  * @(#)SimpleRead.java	1.12 98/06/25 SMI
>  * 
>  * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
>  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
>  * 
>  * Sun grants you ("Licensee") a non-exclusive, royalty free, license
>  * to use, modify and redistribute this software in source and binary
>  * code form, provided that i) this copyright notice and license appear
>  * on all copies of the software; and ii) Licensee does not utilize the
>  * software in a manner which is disparaging to Sun.
>  * 
>  * This software is provided "AS IS," without a warranty of any kind.
>  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
>  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
>  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
>  * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
>  * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
>  * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
>  * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
>  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
>  * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
>  * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
>  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
>  * 
>  * This software is not designed or intended for use in on-line control
>  * of aircraft, air traffic, aircraft navigation or aircraft
>  * communications; or in the design, construction, operation or
>  * maintenance of any nuclear facility. Licensee represents and
>  * warrants that it will not use or redistribute the Software for such
>  * purposes.
>  */
> import java.io.*;
> import java.util.*;
> import gnu.io.*;
> 
> public class SimpleRead implements Runnable, ParallelPortEventListener {
>     static CommPortIdentifier portId;
>     static Enumeration	      portList;
>     InputStream		      inputStream;
>     ParallelPort		      parallelPort;
>     Thread		      readThread;
> 
>     /**
>      * Method declaration
>      *
>      *
>      * @param args
>      *
>      * @see
>      */
>     public static void main(String[] args) {
>     boolean		      portFound = false;
>     String		      defaultPort = "LPT1";
> 
>  	if (args.length > 0) {
> 	    defaultPort = args[0];
> 	} 
>    
> 	portList = CommPortIdentifier.getPortIdentifiers();
> 
> 	while (portList.hasMoreElements()) {
> 	    portId = (CommPortIdentifier) portList.nextElement();
> 	    if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
> 		if (portId.getName().equals(defaultPort)) {
> 		    System.out.println("Found port: "+defaultPort);
> 		    portFound = true;
> 		    SimpleRead reader = new SimpleRead();
> 		} 
> 	    } 
> 	} 
> 	if (!portFound) {
> 	    System.out.println("port " + defaultPort + " not found.");
> 	} 
>  	
>     } 
> 
>     public SimpleRead() {
> 	try {
> 	    parallelPort = (ParallelPort) portId.open("SimpleReadApp", 2000);
> 	} catch (PortInUseException e) {}
> 
> 	try {
> 	    inputStream = parallelPort.getInputStream();
> 	} catch (IOException e) {}
> 
> 	/*try {
> 	    parallelPort.addEventListener(this);
> 	} catch (TooManyListenersException e) {}*/
> 
> 	readThread = new Thread(this);
> 
> 	readThread.start();
>     }
> 
>     public void run() {
> 	try{
> 		InputStream is = this.parallelPort.getInputStream();
> 		while(true){
> 			try{
> 				System.out.println("=>"+is.read());
> 			}
> 			catch(Exception e){
> 				System.out.println("ERROR : "+e);
> 			}
> 		}
> 	}
> 	catch(Exception e){
> 		System.out.println("ERREUR : "+e);
> 	}
>     } 
> 
>     /**
>      * Method declaration
>      *
>      *
>      * @param event
>      *
>      * @see
>      */
>     public void parallelEvent(ParallelPortEvent event) {
>     } 
> 
> }
> ---------------------------------------------------------------------------------------
> 
> Le lundi 18 septembre 2006 à 22:07 -0600, Trent Jarvi a écrit :
> > On Mon, 18 Sep 2006, yves pielusenet wrote:
> > 
> > >
> > > Hello,
> > > I was using the Parport library to read parallel port status.
> > > http://www.geocities.com/Juanga69/parport/
> > > I did something like parport.read() which gives me a byte.
> > > I use this to get a printer status.
> > > I don't want to use parport anymore since it doesn't work with XP
> > > without the Userport programme.
> > >
> > > How can I do this with rxtx ? I want to read all parallel status pin
> > > from my programme.
> > >
> > > I'm searching but I can't find any exemple :(
> > >
> > > thanks in advance :)
> > >
> > >
> > 
> > Which version of rxtx are you trying?  There appears to e support for the 
> > things you want.  The parallel support is much less mature than the serial 
> > support but has worked for people.
> > 
> >          public abstract boolean isPaperOut();
> >          public abstract boolean isPrinterBusy();
> >          public abstract boolean isPrinterError();
> >          public abstract boolean isPrinterSelected();
> >          public abstract boolean isPrinterTimedOut();
> > 
> > These are what you are after, right?
> > 
> > The read error looks like maybe a bad native lib?  We do very little 
> > testing on those.  If it is current rxtx, we can take a look.
> > 
> > --
> > Trent Jarvi
> > tjarvi at qbang.org
> > _______________________________________________
> > Rxtx mailing list
> > Rxtx at qbang.org
> > http://mailman.qbang.org/mailman/listinfo/rxtx
> > 
> 
> _______________________________________________
> Rxtx mailing list
> Rxtx at qbang.org
> http://mailman.qbang.org/mailman/listinfo/rxtx
> 





More information about the Rxtx mailing list