ParallelPort outputStream

Status
Für weitere Antworten geschlossen.

Hans

Registered +
Registriert
März 2007
Beiträge
52
Weiß jemand wie man an den Befehl outputstream.write() ein Byte mit 8 Bit schicken kann? ich würde gerne 10001000 schicken, weiß aber nicht wie.
Ich haben es mit dem outputstream.write(int b) befehl versucht, doch bekomm ich da immer eine IOException.

P.S.: Ich benutzte RXTX 1.2.7 und steuere damit einen roboter an.
 
Das müsste so funktionieren, poste mal bitte den relevanten code und die fehlermeldung, dann kann man dir vielleicht ne klarere Antwort geben...
 
Code:
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.ParallelPort;
import gnu.io.PortInUseException;

import java.io.IOException;
import java.io.OutputStream;

import sun.io.CharToByteConverter;

public class ParallelCommunicationb1 {

private static OutputStream outputStream;;
private static ParallelPort parallelPort;
private static CommPortIdentifier port;

// CONSTANTS
public static final String PARALLEL_PORT = "LPT1";

public static final String[] PORT_TYPE = { "Serial Port", "Parallel 
Port" };

// these commands are specific for my printer around the text
private static String printerCodes = "D";

public static void main(String[] args) {

System.out.println("Started test....");

try {
// get the parallel port connected to the 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();

char[] charArray = printerCodes.toCharArray();
byte[] byteArray = CharToByteConverter.getConverter("UTF8")
.convertAll(charArray);
byteArray[0]=-120; /dies sollte 10001000 geben

System.out.println("Write...");
outputStream.write(byteArray);
System.out.println("Flush...");
outputStream.flush();
System.out.println("Close...");
outputStream.close();

} 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 (UnsupportedCommOperationException usce) {
* System.out.println("\nPrinter Port LPT1 fail to write :
* UnsupportedCommException.\nException:\n" + usce + "\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");
}
}
}
Dabei kommt aber nichts bei meinem Roboter an.
Edit: Also nur die eine 1, es kommt als 0001000 an.
 
Also zunächst mal ist, wieso nimmst du -120 als initialisierungs wert? Würde es nicht auch mit 136 gehen? ;) Ich weiß nicht ob es daran liegen kann, aber nur sone idee.. An sonsten würd ich es denk ich auch so machen... Sagtest du nicht du bekommst ne Exception?
 
Ne, die Exception kommt wenn ich
Code:
outputStream.write(136);
oder
Code:
outputStream.write(-120);
benutzte.
Wenn ich als wert bei dem obengenannten code 136 einfüge bekomm ich beim compilieren den Error "possible loss of precision".

Edit:P.S.: ich benutzte BlueJ zum Programmieren...

Niemadn weiß es? Dann werd ic wohl einen Bug-Report schreiben...

Edit: war nen Hardwareproblem :( der paralle Port ist im arsch :( naja, wer wohl einen anderen Pc nehmen...
 
und ich kann hier dann wohl dicht machen!?

und bitte in zukunft keine doppelposts, sonst gibt's punkte!!! :rot:

~ C L O S E D ~
 
Status
Für weitere Antworten geschlossen.

Ähnliche Themen

H
Antworten
4
Aufrufe
1K
S4m F1sh3r
S
Antworten
18
Aufrufe
5K
Eightb@ll
E
Zurück
Oben Unten