From 695dba4e37ccca9a2dc06e1656699a13406002c1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Dec 2019 16:59:40 -0800 Subject: [PATCH] altosuilib: Wait for Windows to get ready with new device Windows appears to report the new device path long before the path is actually usable. Stick some long delays trying to open the device before giving up. Signed-off-by: Keith Packard --- altosuilib/AltosFlashUI.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/altosuilib/AltosFlashUI.java b/altosuilib/AltosFlashUI.java index 37ab9661..7186e91b 100644 --- a/altosuilib/AltosFlashUI.java +++ b/altosuilib/AltosFlashUI.java @@ -481,12 +481,24 @@ public class AltosFlashUI public void run () { try { AltosLink link = null; + boolean new_device = false; for (;;) { System.out.printf("Attempting to open %s\n", device.toShortString()); - link = new AltosSerial(device); + for (int i = 0; i < 20; i++) { + link = new AltosSerial(device); + if (link != null) + break; + + if (!new_device) + break; + + System.out.printf("Waiting for device to become ready\n"); + + Thread.sleep(1000); + } if (link == null) throw new IOException(String.format("%s: open failed", device.toShortString())); @@ -536,6 +548,7 @@ public class AltosFlashUI if (!matched) { System.out.printf("Identified new device %s\n", d.toShortString()); device = (AltosUSBDevice) d; + new_device = true; break; } } -- 2.30.2