import java.util.*;
import java.awt.*;
import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_3.*;
import org.altusmetrum.altosuilib_1.*;
import libaltosJNI.*;
public void flush_output() {
super.flush_output();
if (altos != null) {
- if (libaltos.altos_flush(altos) != 0) {
- libaltos.altos_close(altos);
- altos = null;
- abort_reply();
- }
+ if (libaltos.altos_flush(altos) != 0)
+ close_serial();
}
}
SwingUtilities.invokeLater(r);
}
+ private void close_serial() {
+ synchronized (devices_opened) {
+ devices_opened.remove(device.getPath());
+ }
+ if (altos != null) {
+ libaltos.altos_free(altos);
+ altos = null;
+ }
+ abort_reply();
+ }
+
public void close() {
if (remote) {
try {
if (in_reply != 0)
System.out.printf("Uh-oh. Closing active serial device\n");
- if (altos != null) {
- libaltos.altos_close(altos);
- }
+ close_serial();
+
if (input_thread != null) {
try {
input_thread.interrupt();
input_thread.join();
- } catch (InterruptedException e) {
+ } catch (InterruptedException ie) {
}
input_thread = null;
}
- if (altos != null) {
- libaltos.altos_free(altos);
- altos = null;
- }
- synchronized (devices_opened) {
- devices_opened.remove(device.getPath());
- }
if (debug)
System.out.printf("Closing %s\n", device.getPath());
}
private void putc(char c) {
if (altos != null)
- if (libaltos.altos_putchar(altos, c) != 0) {
- libaltos.altos_close(altos);
- altos = null;
- abort_reply();
- }
+ if (libaltos.altos_putchar(altos, c) != 0)
+ close_serial();
+ }
+
+ public void putchar(byte c) {
+ if (altos != null) {
+ if (debug)
+ System.out.printf(" %02x", (int) c & 0xff);
+ if (libaltos.altos_putchar(altos, (char) c) != 0)
+ close_serial();
+ }
}
public void print(String data) {