@Override public void stopPolling() { if (_comPort != null && _usable && _isQuestionSupported) { ((SerialPort) _comPort).removeEventListener(); _comPort.close(); } }
/** * @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; }