mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-06 01:08:25 +01:00
Speed up on serial port touch
This commit is contained in:
parent
5eef4ca79c
commit
a5404125f6
@ -102,17 +102,20 @@ public class Serial implements SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean touchPort(String iname, int irate) throws SerialException {
|
public static boolean touchPort(String iname, int irate) throws SerialException {
|
||||||
SerialPort port;
|
|
||||||
boolean result = false;
|
|
||||||
try {
|
try {
|
||||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||||||
while (portList.hasMoreElements()) {
|
while (portList.hasMoreElements()) {
|
||||||
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
|
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
|
||||||
if ((CommPortIdentifier.PORT_SERIAL == portId.getPortType()) && (portId.getName().equals(iname))) {
|
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.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||||||
|
// Sometime the port close takes a lot to complete, so we run it in a parallel thread
|
||||||
|
new Thread() {
|
||||||
|
public void run() {
|
||||||
port.close();
|
port.close();
|
||||||
result = true;
|
};
|
||||||
|
}.start();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PortInUseException e) {
|
} catch (PortInUseException e) {
|
||||||
@ -124,7 +127,7 @@ public class Serial implements SerialPortEventListener {
|
|||||||
I18n.format(_("Error touching serial port ''{0}''."), iname), e
|
I18n.format(_("Error touching serial port ''{0}''."), iname), e
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return result;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Serial(String iname, int irate,
|
public Serial(String iname, int irate,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user