From 5d96988de34ffe025d42532ebc86afe158b9a59f Mon Sep 17 00:00:00 2001 From: hedgecrw85 Date: Wed, 3 Jan 2018 15:01:05 -0600 Subject: [PATCH] Allow safety sleep to take effect before the su request in Android. --- src/main/java/com/fazecast/jSerialComm/SerialPort.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPort.java b/src/main/java/com/fazecast/jSerialComm/SerialPort.java index 7824d9b..3598629 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPort.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPort.java @@ -351,6 +351,10 @@ public final class SerialPort if (isOpened) return true; + // Force a sleep to ensure that the port does not become unusable due to rapid closing/opening on the part of the user + if (safetySleepTime > 0) + try { Thread.sleep(safetySleepTime); } catch (Exception e) { e.printStackTrace(); } + // If this is an Android root application, we must explicitly allow serial port access to the library if (isAndroid) { @@ -382,10 +386,6 @@ public final class SerialPort } } - // Force a sleep to ensure that the port does not become unusable due to rapid closing/opening on the part of the user - if (safetySleepTime > 0) - try { Thread.sleep(safetySleepTime); } catch (Exception e) { e.printStackTrace(); } - if ((portHandle = openPortNative()) > 0) { inputStream = new SerialPortInputStream();