@Override public String getName() { final String name = id.getName(); return name != null ? name : ""; }
@Override public String getName() { final String name = id.getName(); return name != null ? name : ""; }
final CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM1"); System.err.println(portId.getName());
public void list() { Enumeration ports = CommPortIdentifier.getPortIdentifiers(); while(ports.hasMoreElements()){ CommPortIdentifier port = (CommPortIdentifier) ports.nextElement(); System.out.println(port.getName()); } } public static void main(String[] args) { new ListAvailablePorts().list(); }
public class TestComunication { public ArrayList<String> getPortIdentifiers() { Enumeration portEnum = CommPortIdentifier.getPortIdentifiers(); ArrayList<String> ports = new ArrayList<String>(); while (portEnum.hasMoreElements()) { CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement(); ports.add(currPortId.getName()); } return ports; } }
Enumeration portList = CommPortIdentifier.getPortIdentifiers();//this line was false System.out.println(portList.hasMoreElements()); while(portList.hasMoreElements()){ System.out.println("Has more elements"); CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println(portId.getName()); } else{ System.out.println(portId.getName()); } }
@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") Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers(); while (portEnum.hasMoreElements()) { CommPortIdentifier currPortId = portEnum.nextElement(); System.out.println(currPortId.getName() + " - " + currPortId.getCurrentOwner()); }
public static List<String> getSerialPorts(){ List<String> vp=new ArrayList<String>(); Enumeration portList=CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { CommPortIdentifier portId=(CommPortIdentifier)portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { vp.add(portId.getName()); } } return vp; }
List<String> list = new ArrayList<>(); Enumeration thePorts = CommPortIdentifier.getPortIdentifiers(); while (thePorts.hasMoreElements()) { CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement(); switch (com.getPortType()) { case CommPortIdentifier.PORT_SERIAL: list.add(com.getName()); } }
public List<String> getAvailablePorts() { List<String> list = new ArrayList<String>(); Enumeration portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { list.add(portId.getName()); } } return list; }
@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; }
private void initComponents() { List<String> COM = new ArrayList<String>(); Enumeration portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) { System.out.println("No COM ports found"); } else { COM.add(portId.getName()); } } selectedComPort = new JComboBox(COM.toArray(new String[COM.size()])); .... }
public static String selectSerialPort() { ArrayList<String> possibilities = new ArrayList<String>(); possibilities.add("Emulator"); for (CommPortIdentifier commportidentifier : getAvailableSerialPorts()) { possibilities.add(commportidentifier.getName()); } int startPosition = 0; if (possibilities.size() > 1) { startPosition = 1; } return (String) JOptionPane.showInputDialog( null, "JArduino", "Select serial port", JOptionPane.PLAIN_MESSAGE, null, possibilities.toArray(), possibilities.toArray()[startPosition]); }
public static void main(String args[]) { Enumeration ports = CommPortIdentifier.getPortIdentifiers(); while (ports.hasMoreElements()) { CommPortIdentifier port = (CommPortIdentifier) ports.nextElement(); String type; switch (port.getPortType()) { case CommPortIdentifier.PORT_PARALLEL: type = "Parallel"; break; case CommPortIdentifier.PORT_SERIAL: type = "Serial"; break; default: /// Shouldn't happen type = "Unknown"; break; } System.out.println(port.getName() + ": " + type); } }
public static String selectSerialPort() { ArrayList<String> possibilities = new ArrayList<String>(); //possibilities.add("Emulator"); for (CommPortIdentifier commportidentifier : getAvailableSerialPorts()) { possibilities.add(commportidentifier.getName()); } int startPosition = 0; if (possibilities.size() > 1) { startPosition = 1; } return (String) JOptionPane.showInputDialog( null, "BLED112", "Select serial port", JOptionPane.PLAIN_MESSAGE, null, possibilities.toArray(), possibilities.toArray()[startPosition]); }
public static String selectSerialPort() { ArrayList<String> possibilities = new ArrayList<String>(); //possibilities.add("Emulator"); for (CommPortIdentifier commportidentifier : getAvailableSerialPorts()) { possibilities.add(commportidentifier.getName()); } int startPosition = 0; if (possibilities.size() > 1) { startPosition = 1; } return (String) JOptionPane.showInputDialog( null, "BLED112", "Select serial port", JOptionPane.PLAIN_MESSAGE, null, possibilities.toArray(), possibilities.toArray()[startPosition]); }
@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); }
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()) ); } }