/* * Code cribbed from RXTX example */ public static void closePort(SerialPort serialPort) { if (serialPort != null) { serialPort.notifyOnDataAvailable(false); serialPort.removeEventListener(); if (inputStream != null) { try { inputStream.close(); inputStream = null; } catch (IOException e) { } } if (outputStream != null) { try { outputStream.close(); outputStream = null; } catch (IOException e) { } } serialPort.close(); serialPort = null; } }
public void ClosePort() { if (portOpened) { if (serialPort != null) { try { // Close the I/O streams. out.close(); in.close(); // Close the port. serialPort.removeEventListener(); serialPort.close(); } catch (IOException e) { // Don't care } } ClearLog(); portOpened = false; portConfirmed = false; previewPane.setConnected(false); UpdateMenuBar(); } }