2016-04-05 15 views
2

Derzeit versuche ich über Java mit einem parallelen Port zu kommunizieren, aber das hat sich als problematisch erwiesen. Ich mache gerade eine Gehirnforschung mit EEG und ich möchte einfache "Ereignismarker" an das EEG-System senden, was über Parallel Port geschehen muss. Ich habe sowohl javax.comm und RXTX verwendet, aber aus irgendeinem Grund kann ich es nicht schaffen, Ausgabe auf den Port zu schreiben. Der Test-Code lautet wie folgt:Parallel Port Kommunikation Rxtx oder javax.comm

import gnu.io.*; // RXTX 
// import javax.comm.*; // javax.comm 

public class PrlCom { 
private String msg= "1"; 

private OutputStream outputStream; 
private InputStream inputStream; 

private ParallelPort parallelPort; // can be both Rxtx or javax.comm 
private CommPortIdentifier port; 

// CONSTANTS 
public final String PARALLEL_PORT = "LPT1"; 
public final String[] PORT_TYPE = { "Serial Port", "Parallel Port" }; 

public static void main(String[] args) { 
    new PrlCom(); 
} 
public PrlCom(){ 
    openParPort(); 
} 

public void openParPort() { 
    try { 
     // get the parallel port connected to the EEG-system (used to be printer) 
     port = CommPortIdentifier.getPortIdentifier(PARALLEL_PORT); 

     System.out.println("\nport.portType = " + port.getPortType()); 
     System.out.println("port type = " + PORT_TYPE[port.getPortType() - 1]); 
     System.out.println("port.name = " + port.getName()); 

     // open the parallel port -- open(App name, timeout) 
     parallelPort = (ParallelPort) port.open("CommTest", 50); 
     outputStream = parallelPort.getOutputStream(); 
     inputStream = parallelPort.getInputStream(); 

     System.out.println("Write..."); 
     outputStream.write(toBytes(msg.toCharArray())); 
     System.out.println("Flush..."); 
     outputStream.flush(); 
    } catch (NoSuchPortException nspe) { 
     System.out.println("\nPrinter Port LPT1 not found : " + "NoSuchPortException.\nException:\n" + nspe + "\n"); 
    } catch (PortInUseException piue) { 
     System.out.println("\nPrinter Port LPT1 is in use : " + "PortInUseException.\nException:\n" + piue + "\n"); 
    } catch (IOException ioe) { 
     System.out.println("\nPrinter Port LPT1 failed to write : " + "IOException.\nException:\n" + ioe + "\n"); 
    } catch (Exception e) { 
     System.out.println("\nFailed to open Printer Port LPT1 with exeception : " + e + "\n"); 
    } finally { 
     if (port != null && port.isCurrentlyOwned()) { 
      parallelPort.close(); 
     } 

     System.out.println("Closed all resources.\n"); 
    } 
} 

ich die ToBytes bekam() Funktion von Converting char[] to byte[]. Ich habe auch direkt spam.getBytes() ausprobiert, was keinen Unterschied machte.

Nach dem Ausführen dieses Codes mit dem javax.comm-Paket wird der parallele Anschluss nicht erkannt. Wenn ich den Code mit RXTX (gnu.io) starte, bekomme ich eine IOException. Die gesamte Druckausgabe ist dann wie folgt

Stable Library 
========================================= 
Native lib Version = RXTX-2.1-7 
Java lib Version = RXTX-2.1-7 

port.portType = 2 
port type = Parallel Port 
port.name = LPT1 
Output stream opened 
Write... 

Printer Port LPT1 failed to write : IOException. 
Exception: 
java.io.IOException: The device is not connected. 
    in writeByte 

Closed all resources. 

Mit Rxtx kann der Code also eine Verbindung mit dem Parallel Port herstellen. Es ist jedoch nicht möglich, ein Byte in den Ausgabestream zu schreiben. Kann mir bitte jemand sagen, wie man das löst?

Ich habe in vielen der anderen Themen gelesen, wie veraltet ein paralleler Port ist und dass ich USB verwenden sollte. Ich arbeite jedoch mit einem EEG-System (BioSemi ActiveTwo mit ActiView-Software), um Gehirnaktivität zu messen, und leider habe ich nicht die Möglichkeit, dies zu ändern. Ein Parallelport-USB-Konverter ist ebenfalls keine Option. (Seltsamerweise, dass etwas so technologisch fortgeschritten ist, benutzt solche veraltete Hardware).

Vielen Dank!

Antwort