diff options
| author | Keith Packard <keithp@keithp.com> | 2010-04-04 16:32:04 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2010-04-04 16:32:04 -0700 | 
| commit | 0e7abc9fedec568b431c983d3df1b0b29f4f10e3 (patch) | |
| tree | 9a1f99601256b8e3a2f57d3592555456c931a623 /ao-tools/altosui/AltosSerial.java | |
| parent | 3d34c488c5b71020d86f83156fd821fd860bf214 (diff) | |
Use RXTX for serial comm. Add logdir preference saving
Diffstat (limited to 'ao-tools/altosui/AltosSerial.java')
| -rw-r--r-- | ao-tools/altosui/AltosSerial.java | 34 | 
1 files changed, 27 insertions, 7 deletions
diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 9537f190..305222dc 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -26,6 +26,7 @@ import java.io.*;  import java.util.concurrent.LinkedBlockingQueue;  import java.util.LinkedList;  import java.util.Iterator; +import gnu.io.*;  import altosui.AltosSerialMonitor;  /* @@ -34,7 +35,7 @@ import altosui.AltosSerialMonitor;   * threads.   */  class AltosSerialReader implements Runnable { -	FileInputStream	serial_in; +	InputStream	serial_in;  	LinkedBlockingQueue<String> monitor_queue;  	LinkedBlockingQueue<String> reply_queue;  	Thread input_thread; @@ -109,6 +110,12 @@ class AltosSerialReader implements Runnable {  		input_thread = new Thread(this);  		input_thread.start();  	} +	public void open(CommPort c) throws IOException { +		close(); +		serial_in = c.getInputStream(); +		input_thread = new Thread(this); +		input_thread.start(); +	}  	public AltosSerialReader () {  		serial_in = null;  		input_thread = null; @@ -120,7 +127,7 @@ class AltosSerialReader implements Runnable {  }  public class AltosSerial implements Runnable { -	FileOutputStream serial_out = null; +	OutputStream serial_out = null;  	Thread monitor_thread = null;  	AltosSerialReader reader = null;  	LinkedList<AltosSerialMonitor> callbacks; @@ -188,11 +195,19 @@ public class AltosSerial implements Runnable {  	public void open(File serial_name) throws FileNotFoundException {  		reader.open(serial_name);  		serial_out = new FileOutputStream(serial_name); -		try { -			serial_out.write('?'); -			serial_out.write('\r'); -		} catch (IOException e) { -		} +	} + +	public void open(CommPort comm_port) throws IOException { +		reader.open(comm_port); +		serial_out = comm_port.getOutputStream(); +	} + +	public void connect(String port_name) throws IOException, NoSuchPortException, PortInUseException { +		System.out.printf("Opening serial port %s\n", port_name); +		CommPort comm_port = new RXTXPort(port_name); +//		CommPortIdentifier port_identifier = CommPortIdentifier.getPortIdentifier(port_name); +//		CommPort comm_port = port_identifier.open("Altos", 1000); +		open(comm_port);  	}  	void init() { @@ -208,4 +223,9 @@ public class AltosSerial implements Runnable {  		init();  		open(serial_name);  	} + +	public AltosSerial(CommPort comm_port) throws IOException { +		init(); +		open(comm_port); +	}  }  | 
