mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
added static touchPort() method to Serial class.
Used by Leonardo to quickly tap the comm port to initiate a reset without the potential problems of doing a full Serial object construct/dispose with all listeners, etc.
This commit is contained in:
parent
25a4fe8607
commit
5c53796cec
@ -101,6 +101,32 @@ public class Serial implements SerialPortEventListener {
|
||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
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);
|
||||
port.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||||
port.close();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
} catch (PortInUseException e) {
|
||||
throw new SerialException(
|
||||
I18n.format(_("Serial port ''{0}'' already in use. Try quiting any programs that may be using it."), iname)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new SerialException(
|
||||
I18n.format(_("Error touching serial port ''{0}''."), iname), e
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Serial(String iname, int irate,
|
||||
char iparity, int idatabits, float istopbits)
|
||||
throws SerialException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user