簡體   English   中英

CommPortIdentifier.getPortIdentifiers為空

[英]CommPortIdentifier.getPortIdentifiers is empty

我正在構建一個使用Java Communication API javax.comm通過串行端口進行通信的簡單應用程序。

這是我寫的java main方法中的一些代碼:

CommPortIdentifier cpi = null;
        Enumeration e = CommPortIdentifier.getPortIdentifiers();
        while (e.hasMoreElements()) {
            try {
                cpi = (CommPortIdentifier) e.nextElement();
            } catch (NoSuchElementException n) {

            }
            System.out.println(cpi.getName());
        }

枚舉e始終為空,即使我在運行時連接到COM 4端口。

另外,運行此代碼:

portRead = CommPortIdentifier.getPortIdentifier("COM8");

導致拋出NoSuchPortException

我想我已正確完成安裝部分並將屬性文件win32com.dll文件放在正確的位置。

你知道問題是什么嗎?

謝謝

請記住,您需要將所有解壓縮的文件從javax.comm.zip添加到jre

win32com.dll - jre / bin

comm.jar - jre / lib / ext

java.comm.properties - jre / lib (添加后我發現已解決的異常問題)

確保win32com.dll(javax.com附帶)位於jre \\ bin目錄中。 確保javax.comm.properties(javax.com附帶)位於jdk \\ lib目錄中。

這適用於我(我安裝了x86 jdk)並按照步驟操作

您的問題是Windows無法將正確的PORT傳遞給您的JAVA程序。

您必須通過以下鏈接在正確的位置復制正確的文件。

http://kishor15389.blogspot.com/2011/05/how-to-install-java-communications.html

找到您的設備正在工作的端口(嘗試使用power shell或hyper terminal查找所有com端口嘗試鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM