Po prostu uruchamiałem kilka kodów, aby uzyskać listę dostępnych portów w moim komputerze cmputer i zwrócono mi wartość false, gdy mam 3 porty com, które są bezpłatne. Jak rozwiązać ten problem?Jak uzyskać listę dostępnych portów szeregowych w moim komputerze za pomocą Java?
Moi kody:
public static void main(String[] args) {
//SerialParameters params=new SerialParameters();
// System.out.println(CommPortIdentifier.PORT_SERIAL);
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
System.out.println(portList.hasMoreElements());
while(portList.hasMoreElements()){
System.out.println("Has more elements");
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
System.out.println(portId.getName());
}
else{
System.out.println(portId.getName());
}
}
}
wyjściowa: fałszywe