I want to scan available com port using Java. I used the following code using Comm library but its not working
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
int i = 0;
String[] r = new String[10];
while (portEnum.hasMoreElements()){
CommPortIdentifier portIdentifier = portEnum.nextElement();
r[i] = portIdentifier.getName();
i++;
}
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(r));
portEnum.hasMoreElements()
returns false
every time.
I don't have the old fashioned RS232
port on my computer I'm using a USB to RS232
converter that I tested with putty.
I just want to scan available ports so I don't mind using others libraries.
ANSWER: I Used the code in comments bellows and its worked
import jssc.SerialPortList;
public class Main {
public static void main(String[] args) {
String[] portNames = SerialPortList.getPortNames();
for(int i = 0; i < portNames.length; i++){
System.out.println(portNames[i]);
}
}
}