Parallel Port + Java Communication API



  • Hallo.
    Ich hab gerade ein kleines Prog begonnen das die Verbindung zum einem Parallel Port herstellt und nun will ich einfach die Zustände der Pins ändern, irgenwie scheint das aber nicht zu funzen.

    Hier mal der bissherige Quellcode:

    import java.io.OutputStream;
    import java.io.IOException;
    import java.util.Enumeration;
    
    import javax.comm.CommPort;
    import javax.comm.CommPortIdentifier;
    import javax.comm.ParallelPort;
    import javax.comm.NoSuchPortException;
    import javax.comm.PortInUseException;
    import javax.comm.UnsupportedCommOperationException;
    
    public class TryParallel
    {
      public static void main(String[] args)
      { CommPortIdentifier portID;
        Enumeration portList;
        ParallelPort paraPort=null;
        OutputStream out=null;
        boolean found=false;
    
        portList=CommPortIdentifier.getPortIdentifiers();
    
        while(portList.hasMoreElements()&&found==false)
        { portID=(CommPortIdentifier)portList.nextElement();
          if(portID.getPortType()==CommPortIdentifier.PORT_PARALLEL)
          { try
            { paraPort=(ParallelPort)portID.open("TryParallel", 2000);
              out=paraPort.getOutputStream();
              paraPort.setMode(ParallelPort.LPT_MODE_SPP);
              paraPort.enableReceiveThreshold(1);
              paraPort.setOutputBufferSize(1);
              found=true;
            }
            catch(PortInUseException e)
            { System.out.println("PortInUseException has been thrown");
              paraPort.close();          
              System.exit(1);
            }
            catch(IOException e)
            { System.out.println("IOException has been thrown");
              paraPort.close();
              System.exit(1);
            }
            catch(UnsupportedCommOperationException e)
            { System.out.println("UnsupportedCommOperationException has been thrown");
              paraPort.close();
              System.exit(1);
            }
          }
        }
    
        if(found==false)
        { System.exit(1);
        }
    
        System.out.println("Parallel Port initialised successfully");
    
        try
        { out.write(34);
        }
        catch(IOException e)
        { System.out.println("IOException has been thrown");
        }
    
        paraPort.close();
        System.exit(0);
      }
    }
    

    Beim letzten Try/Catch block ganz unten versuche ich mit out.write(34) die Werte dieses Ports zu ändern. Das Problem ist, dass er aus dieser Methode nicht mehr rauskommt. Ich hab derzeit in meiner Schaltung aber kein Handshaking oder sowas, sondern zeige die Zustände der einzelnen Ausgänge nur mit ein paar Leuchtdioden an.

    Was könnte man da machen?


Anmelden zum Antworten