X-Git-Url: http://git.megacz.com/?p=eltron.git;a=blobdiff_plain;f=src%2Fcom%2Fmegacz%2Feltron%2FEltron.java;h=c5ba4cf07241166f95ba067765b133d869ee9a21;hp=d59e73c6725bcb2187d250924d5328b0c497d639;hb=HEAD;hpb=22d759461933b2d513843d7fdf4a8d8f50ea5667 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."); } - }