java 当端口存在时获取 javax.comm.NoSuchPortException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11983764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:09:42  来源:igfitidea点击:

getting a javax.comm.NoSuchPortException when the port exist

javaserial-port

提问by Shantanu Banerjee

Hello I have seen this Why am I getting a Java NoSuchPortException when the port exists?post but It's not very clear to me!!

您好,我已经看到了为什么当端口存在时我会收到 Java NoSuchPortException?帖子,但对我来说不是很清楚!!

In device manager it shows COM3 is exist and I can connect it through putty, but this piece of code is getting this error/exception.

在设备管理器中,它显示 COM3 存在,我可以通过腻子连接它,但是这段代码出现了这个错误/异常。

try {
       portId = CommPortIdentifier.getPortIdentifier("COM3");
    } catch (NoSuchPortException ex) {
       System.out.println(ex);
    }

try {
     serialPort = (SerialPort)portId.open("S2CFrameWork", 5000);
    } catch (PortInUseException e) {
        System.out.println(e);
    }

this simple code thrown a javax.comm.NoSuchPortException, I have also tried this with using Enumeration to get the list of avilable port but still it shows exception. Can anyone solve this issue?

这个简单的代码抛出了一个 javax.comm.NoSuchPortException,我也尝试过使用枚举来获取可用端口列表,但它仍然显示异常。任何人都可以解决这个问题吗?

回答by Shantanu Banerjee

comm.jar should be placed in:

comm.jar 应该放在:

%JAVA_HOME%/lib

%JAVA_HOME%/jre/lib/ext

win32com.dll should be placed in:

win32com.dll 应该放在:

%JAVA_HOME%/bin

%JAVA_HOME%/jre/bin

%windir%System32

javax.comm.properties should be placed in:

javax.comm.properties 应该放在:

%JAVA_HOME%/lib

%JAVA_HOME%/jre/lib