mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03: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:
@ -101,6 +101,32 @@ public class Serial implements SerialPortEventListener {
|
|||||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
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,
|
public Serial(String iname, int irate,
|
||||||
char iparity, int idatabits, float istopbits)
|
char iparity, int idatabits, float istopbits)
|
||||||
throws SerialException {
|
throws SerialException {
|
||||||
|
Reference in New Issue
Block a user