gpt4 book ai didi

Java串口配置gnu.io.rxtx.properties窗口

转载 作者:行者123 更新时间:2023-12-02 08:14:10 26 4
gpt4 key购买 nike

我正在尝试运行此函数,并得到带有文本的配置 gnu.io.rxtx.properties 窗口:尚未检测到 gnu.io.rxtx.properties。

没有一致的方法来检测此操作系统上的端口。在进行正确的端口枚举之前,有必要指示哪些端口在此系统上有效。请检查在此系统上有效的端口,然后选择“保存”。当我单击命令窗口上的“保存”时,会出现文本:

C:\Program Files\Java\jre7\lib\gnu.io.rxtx.SerialPorts

但程序仍然无法运行。

   public void connect(String serial){
this.serialPort = null;
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serial);
if (portIdentifier.isCurrentlyOwned()) {
System.out.println("Port in use!");
} else {
System.out.println(portIdentifier.getName());

this.serialPort = (SerialPort) portIdentifier.open(
"ListPortClass", 300);
int b = this.serialPort.getBaudRate();
System.out.println(Integer.toString(b));
this.serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
// serialPort.setInputBufferSize(65536);
// serialPort.setOutputBufferSize(4096);

System.out.println("Opened " + portIdentifier.getName());

OutputStream mOutputToPort = this.serialPort.getOutputStream();
InputStream mInputFromPort = this.serialPort.getInputStream();
this.OutputToPort = mOutputToPort;
this.InputFromPort = mInputFromPort;
this.connected = true;
}
} catch (IOException ex) {
System.out.println("IOException : " + ex.getMessage());
} catch (UnsupportedCommOperationException ex) {
System.out.println("UnsupportedCommOperationException : " + ex.getMessage());
} catch (NoSuchPortException ex) {
System.out.println("NoSuchPortException : " + ex.getMessage());
} catch (PortInUseException ex) {
System.out.println("PortInUseException : " + ex.getMessage());}
}

最佳答案

我在 Linux 上也遇到过同样的错误,结果是权限问题。将用户帐户添加到“uucp”组后(如 http://rxtx.qbang.org 中所述),请确保注销并重新登录系统。

关于Java串口配置gnu.io.rxtx.properties窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20554601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com