/** * Construct {@link Javacomm} implementation for RXTX implementation. */ JavacommRxTxImpl() { CommPortIdentifier.getPortIdentifiers(); }
private void testNativeCode()throws UnsatisfiedLinkError { CommPortIdentifier.getPortIdentifiers(); }
private void testNativeCode()throws UnsatisfiedLinkError { CommPortIdentifier.getPortIdentifiers(); }
@SuppressWarnings("unchecked") private CommPortIdentifier findCommPortIdentifier(String name) { Enumeration<CommPortIdentifier> enumeration = CommPortIdentifier.getPortIdentifiers(); CommPortIdentifier port = null; while (enumeration.hasMoreElements()) { CommPortIdentifier identifier = enumeration.nextElement(); if (identifier.getName().equalsIgnoreCase(name)) { port = identifier; } } return port; }
@SuppressWarnings("unchecked") private CommPortIdentifier findCommPortIdentifier(String name) { Enumeration<CommPortIdentifier> enumeration = CommPortIdentifier.getPortIdentifiers(); CommPortIdentifier port = null; while (enumeration.hasMoreElements()) { CommPortIdentifier identifier = enumeration.nextElement(); if (identifier.getName().equalsIgnoreCase(name)) { port = identifier; } } return port; }
/** * Retrieves the list of available serial ports in the system. * * @return List of available serial ports. * * @see #listSerialPortsInfo() */ public static String[] listSerialPorts() { ArrayList<String> serialPorts = new ArrayList<String>(); @SuppressWarnings("unchecked") Enumeration<CommPortIdentifier> comPorts = CommPortIdentifier.getPortIdentifiers(); if (comPorts == null) return serialPorts.toArray(new String[serialPorts.size()]); while (comPorts.hasMoreElements()) { CommPortIdentifier identifier = (CommPortIdentifier)comPorts.nextElement(); if (identifier == null) continue; String strName = identifier.getName(); serialPorts.add(strName); } return serialPorts.toArray(new String[serialPorts.size()]); }
getPortIdentifiers(); index = CommPortIndex; while (index != null && !index.PortName.equals(s)) {
@Override public Stream<SerialPortIdentifier> getSerialPortIdentifiers() { @SuppressWarnings("unchecked") final Enumeration<CommPortIdentifier> ids = CommPortIdentifier.getPortIdentifiers(); return StreamSupport.stream(new SplitIteratorForEnumeration<>(ids), false) .filter(id -> id.getPortType() == CommPortIdentifier.PORT_SERIAL) .map(sid -> new SerialPortIdentifierImpl(sid)); }
@NotNull @Override public List<String> getSerialPortNames() { final List<String> result = new ArrayList<String>(); for ( final Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ) { final CommPortIdentifier id = (CommPortIdentifier)e.nextElement(); if ( id.getPortType() == CommPortIdentifier.PORT_SERIAL ) { result.add( id.getName() ); } } return result; }
/** * Get the serial port names on the host system. * * @return the serial ports names. */ public static String[] getSerialPortNames() { Enumeration<CommPortIdentifier> identifiers = CommPortIdentifier.getPortIdentifiers(); List<String> result = new ArrayList<String>(20); while (identifiers.hasMoreElements()) { CommPortIdentifier identifier = identifiers.nextElement(); if (identifier.getPortType() != CommPortIdentifier.PORT_SERIAL) { continue; } result.add(identifier.getName()); } String[] res = new String[result.size()]; return result.toArray(res); }
/** * Get serial port by name. * * @param name Serial port name. * * @return Port with given name; * {@code null} if the port was not found. */ @Nullable public CommPortIdentifier getPortByName( @NotNull final String name ) { CommPortIdentifier result = null; for ( final Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ) { final CommPortIdentifier id = (CommPortIdentifier)e.nextElement(); if ( ( id.getPortType() == CommPortIdentifier.PORT_SERIAL ) && name.equalsIgnoreCase( id.getName() ) ) { result = id; break; } } return result; }
@Override public Stream<SerialPortIdentifier> getSerialPortIdentifiers() { @SuppressWarnings("unchecked") final Enumeration<CommPortIdentifier> ids = CommPortIdentifier.getPortIdentifiers(); return StreamSupport.stream(new SplitIteratorForEnumeration<>(ids), false) .filter(id -> id.getPortType() == CommPortIdentifier.PORT_SERIAL) .map(sid -> new SerialPortIdentifierImpl(sid)); }
static void listPorts() { java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers(); while ( portEnum.hasMoreElements() ) { CommPortIdentifier portIdentifier = portEnum.nextElement(); System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()) ); } }
@SuppressWarnings("unchecked") public static Vector<String> getPortList(boolean showList) { Enumeration<CommPortIdentifier> portList; Vector<String> portVect = new Vector<String>(); portList = CommPortIdentifier.getPortIdentifiers(); CommPortIdentifier portId; while (portList.hasMoreElements()) { portId = portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { portVect.add(portId.getName()); } } if (showList) { System.out.println("Found the following ports:"); for (int i = 0; i < portVect.size(); i++) { System.out.println(portVect.elementAt(i)); } } return portVect; }
/** * Retrieves the list of available serial ports with their information. * * @return List of available serial ports with their information. * * @see #listSerialPorts() * @see SerialPortInfo */ public static ArrayList<SerialPortInfo> listSerialPortsInfo() { ArrayList<SerialPortInfo> ports = new ArrayList<SerialPortInfo>(); @SuppressWarnings("unchecked") Enumeration<CommPortIdentifier> comPorts = CommPortIdentifier.getPortIdentifiers(); if (comPorts == null) return ports; while (comPorts.hasMoreElements()) { CommPortIdentifier identifier = (CommPortIdentifier)comPorts.nextElement(); if (identifier == null) continue; ports.add(new SerialPortInfo(identifier.getName())); } return ports; }
/** * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used. */ public 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; }
/** * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used. */ public 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; }
/** * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used. */ public 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; }
Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); while (e.hasMoreElements()) { CommPortIdentifier id = (CommPortIdentifier) e.nextElement();
@Override public List<String> getPortIdentifiers() { List<String> portIdentifiers = new ArrayList<String>(); try { // get the comm port identifiers Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); while (e.hasMoreElements()) { CommPortIdentifier id = (CommPortIdentifier) e.nextElement(); LOGGER.debug("Process current CommPortIdentifier, name: {}, portType: {}", id.getName(), id.getPortType()); if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) { portIdentifiers.add(id.getName()); } else { LOGGER.debug("Skip port because no serial port, name: {}, portType: {}", id.getName(), id.getPortType()); } } } catch (UnsatisfiedLinkError ule) { LOGGER.warn("Get comm port identifiers failed.", ule); throw new InvalidLibraryException(ule.getMessage(), ule.getCause()); } catch (Error error) { LOGGER.warn("Get comm port identifiers failed.", error); throw new RuntimeException(error.getMessage(), error.getCause()); } return portIdentifiers; }