0
我正在Eclipse中使用Java通信API。這是我的示例程序來獲取所有可用的端口進行通信,但程序退出,因爲CommPortIdentifier.getPortIdentifiers()
不返回任何內容。 Enumeration enu_ports
爲空並且程序退出。如何通過Java通信API使用Eclipse Indigo
步驟我都做:
- 我已經連我的智能料斗中的主機。
- 認沽win32com.dll文件system32文件夾下,也加入Eclipse項目
- 添加javax.comm.properties文件中Eclipse項目
- 新增com.jar到構建路徑我的系統是32位和操作系統是Windows 7
如果任何步驟不正確,請提供使用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();
}
}
jawi謝謝你的答覆我使用java comm api而不是RXTX –
最初的JavaComm API比較舊,不再支持,你可能想研究一些替代品,比如RXTX? – jawi
除此之外:您是否將本地庫(DLL)添加到您的項目中?有關如何做到這一點的詳細信息,請參閱http://stackoverflow.com/questions/957700/how-to-set-the-java-library-path-from-eclipse ... – jawi