From: Keith Packard Date: Fri, 3 Sep 2010 08:30:33 +0000 (-0700) Subject: altosui: Allow 'connect to device' when already connected X-Git-Tag: debian/0.7+53+g59798c6~4 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=71191ecef3ba0e00d0f8a7cd1a24982bfa44ec72;hp=ba65e4aeb952a1cf49a77f1e24e235508fcea71f altosui: Allow 'connect to device' when already connected Opening another serial device involves shutting down the display thread (to reset its state) and spawning another one. Shutting down the display thread normally closes the serial device as a part of the process, and if this isn't done before the new serial device is opened, then the new serial device ends up getting closed too. Interrupting the display thread and waiting for it to stop before opening the new serial device solves the problem. Signed-off-by: Keith Packard --- diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e3f61303..e63a004c 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -441,6 +441,7 @@ public class AltosUI extends JFrame { if (device != null) { try { + stop_display(); serial_line.open(device); DeviceThread thread = new DeviceThread(serial_line); serial_line.set_channel(AltosPreferences.channel()); @@ -536,8 +537,12 @@ public class AltosUI extends JFrame { Thread display_thread; private void stop_display() { - if (display_thread != null && display_thread.isAlive()) + if (display_thread != null && display_thread.isAlive()) { display_thread.interrupt(); + try { + display_thread.join(); + } catch (InterruptedException ie) {} + } display_thread = null; }