import java.util.*;
import gnu.io.*;
-/*
-
-If you're on a mac and you get the error below, you need to create
-/var/lock and make it writable.
-
-Exception in thread "main" gnu.io.PortInUseException: No such file or directory in open
-at gnu.io.RXTXPort.open(Native Method)
-at gnu.io.RXTXPort.<init>(RXTXPort.java:84)
-at com.megacz.eltron.Eltron.detectPort(Eltron.java:26)
-at com.megacz.eltron.Eltron.print(Eltron.java:37)
-at com.megacz.eltron.Eltron.main(Eltron.java:14)
-
-
- */
-
/** code to control an Eltron */
public class Eltron {
}
public static SerialPort detectPort() throws Exception {
+ if (System.getProperty("os.name").toLowerCase().indexOf("mac")==-1)
+ return detectPort_();
+ try {
+ return detectPort_();
+ } catch (gnu.io.PortInUseException e) {
+ if (e.toString().indexOf("No such file or directory in open") != -1) {
+ System.err.println("Please make sure that /var/lock/ exists and is writable");
+ }
+ throw e;
+ }
+
+ }
+ public static SerialPort detectPort_() throws Exception {
Enumeration e = CommPortIdentifier.getPortIdentifiers();
while(e.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
return ret;
}
}
- SerialPort ret = new RXTXPort("/dev/ttyS0");
+ SerialPort ret = new RXTXPort("/dev/ttyUSB0");
Log.info(Eltron.class, "returning " + ret);
return ret;
}
// you'll need to run this once at 9600 to tell the built-in eeprom to switch to 38,400kbps
//sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
-
sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
-
OutputStream out = sp.getOutputStream();
InputStream in = sp.getInputStream();
int count = 0;
pw.println("P1");
pw.flush();
+ System.out.println("done printing.");
}
-
}