[英]How to use Eclipse Indigo with Java communication API
我正在Eclipse中使用Java通信API。 這是我的示例程序,用於獲取所有可用的端口進行通信,但由於CommPortIdentifier.getPortIdentifiers()
不返回任何內容,因此該程序退出。 Enumeration enu_ports
為null,程序退出。
我已完成的步驟:
如果任何步驟不正確,請提供將Eclipse Indigo與Java通信API結合使用的步驟。
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
class GetAvailableComPorts {
public static void getComPorts(){
String port_type;
Enumeration enu_ports = CommPortIdentifier.getPortIdentifiers();
while (enu_ports.hasMoreElements()) {
CommPortIdentifier port_identifier = (CommPortIdentifier) enu_ports.nextElement();
switch(port_identifier.getPortType()){
case CommPortIdentifier.PORT_SERIAL:
port_type = "Serial";
break;
case CommPortIdentifier.PORT_PARALLEL:
port_type = "Parallel";
break;
default:
port_type = "Unknown";
break;
}
System.out.println("Port : "+port_identifier.getName() +" Port type : "+port_type);
}
}
public static void main(String[] args) {
getComPorts();
}
}
問題肯定與Eclipse無關。 您正在使用什么串行庫? 似乎不是RXTX。 您是否嘗試過其他庫,例如PureJavacomm或NrJavaSerial ? 這樣可以解決您的問題嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.