From a5404125f684bb0f837d61676c6212b74f2b111b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 28 Feb 2012 18:28:34 +0100 Subject: [PATCH] Speed up on serial port touch --- app/src/processing/app/Serial.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/Serial.java b/app/src/processing/app/Serial.java index 14c0933c0..0bab1a655 100755 --- a/app/src/processing/app/Serial.java +++ b/app/src/processing/app/Serial.java @@ -102,17 +102,20 @@ public class Serial implements SerialPortEventListener { } public static boolean touchPort(String iname, int irate) throws SerialException { - SerialPort port; - boolean result = false; try { Enumeration portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement(); if ((CommPortIdentifier.PORT_SERIAL == portId.getPortType()) && (portId.getName().equals(iname))) { - port = (SerialPort) portId.open("tap", 2000); + final SerialPort port = (SerialPort) portId.open("tap", 2000); port.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); - port.close(); - result = true; + // Sometime the port close takes a lot to complete, so we run it in a parallel thread + new Thread() { + public void run() { + port.close(); + }; + }.start(); + return true; } } } catch (PortInUseException e) { @@ -124,7 +127,7 @@ public class Serial implements SerialPortEventListener { I18n.format(_("Error touching serial port ''{0}''."), iname), e ); } - return result; + return false; } public Serial(String iname, int irate,