X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosSerial.java;h=b089c9c40c580beb7764135fb0c3ead7be9a374a;hb=dcd15032eec45f3fdd003050710ebd5b85052662;hp=5d4510b46679ff89cdf138ee47fc0f0e21426321;hpb=13eacb49de4312509c3a729a31dcda4d601f8a8b;p=fw%2Faltos diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 5d4510b4..b089c9c4 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -213,30 +213,38 @@ public class AltosSerial implements Runnable { public String get_reply(int timeout) throws InterruptedException { boolean can_cancel = true; - ++in_reply; + String reply = null; - if (SwingUtilities.isEventDispatchThread()) { - can_cancel = false; - System.out.printf("Uh-oh, reading serial device from swing thread\n"); - } - flush_output(); - if (remote && can_cancel) { - timeout = 500; - } - abort = false; - timeout_started = false; - for (;;) { - AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); - if (line != null) { - stop_timeout_dialog(); - --in_reply; - return line.line; + try { + ++in_reply; + + if (SwingUtilities.isEventDispatchThread()) { + can_cancel = false; + if (remote) + System.out.printf("Uh-oh, reading remote serial device from swing thread\n"); } - if (!remote || !can_cancel || check_timeout()) { - --in_reply; - return null; + flush_output(); + if (remote && can_cancel) { + timeout = 500; } + abort = false; + timeout_started = false; + for (;;) { + AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); + if (line != null) { + stop_timeout_dialog(); + reply = line.line; + break; + } + if (!remote || !can_cancel || check_timeout()) { + reply = null; + break; + } + } + } finally { + --in_reply; } + return reply; } public String get_reply() throws InterruptedException {