From: Adam Megacz Date: Mon, 17 Jan 2011 23:26:43 +0000 (-0800) Subject: better error reporting on MacOSX, remember to System.exit(0) X-Git-Url: http://git.megacz.com/?p=eltron.git;a=commitdiff_plain;h=refs%2Fheads%2Fmaster better error reporting on MacOSX, remember to System.exit(0) --- diff --git a/src/com/megacz/eltron/Eltron.java b/src/com/megacz/eltron/Eltron.java index d59e73c..c5ba4cf 100644 --- a/src/com/megacz/eltron/Eltron.java +++ b/src/com/megacz/eltron/Eltron.java @@ -6,21 +6,6 @@ import java.io.*; 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.(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 { @@ -33,6 +18,19 @@ 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(); @@ -43,7 +41,7 @@ public class Eltron { return ret; } } - SerialPort ret = new RXTXPort("/dev/ttyS0"); + SerialPort ret = new RXTXPort("/dev/ttyUSB0"); Log.info(Eltron.class, "returning " + ret); return ret; } @@ -54,10 +52,8 @@ public class Eltron { // 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; @@ -132,6 +128,6 @@ public class Eltron { pw.println("P1"); pw.flush(); + System.out.println("done printing."); } - } diff --git a/src/com/megacz/eltron/MailingLabel.java b/src/com/megacz/eltron/MailingLabel.java index 641abd7..575fbf8 100644 --- a/src/com/megacz/eltron/MailingLabel.java +++ b/src/com/megacz/eltron/MailingLabel.java @@ -40,6 +40,9 @@ public class MailingLabel { for(int y=0; y