/** Close the serial port. */ public void delete() { // Close the serial port try { if (inputStream != null) inputStream.close(); outputStream.close(); } catch (IOException e) { } mbedSerialPort.removeEventListener(); mbedSerialPort.close(); mbedPort.close(); }
public void run() { try { join1.join(); join2.join(); // execution stops until both these thread finish } catch (InterruptedException e) { } try { thePort.close(); } catch (Exception e) { // the port's probably already been closed } }
/** * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently * being used. */ @SuppressWarnings({"rawtypes"}) private static HashSet<CommPortIdentifier> getAvailableSerialPorts() { HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>(); Enumeration thePorts = CommPortIdentifier.getPortIdentifiers(); while (thePorts.hasMoreElements()) { CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement(); switch (com.getPortType()) { case CommPortIdentifier.PORT_SERIAL: try { CommPort thePort = com.open("CommUtil", 50); thePort.close(); h.add(com); } catch (PortInUseException e) { System.out.println("Port, " + com.getName() + ", is in use."); } catch (Exception e) { System.err.println("Failed to open port " + com.getName()); e.printStackTrace(); } } } return h; }