gpt4 book ai didi

java - 使用java加载串口共享库出错

转载 作者:行者123 更新时间:2023-12-01 13:26:32 26 4
gpt4 key购买 nike

我必须将数据发送到串口,javax.comm也包含在内,但它给出了错误“在加载驱动程序 gnu.io.RXTXCommDriver 时捕获 java.lang.UnsatisfiedLinkError:java.library.path 中没有 rxtxSerial加载 SolarisSerial 时出错:java.lang.UnsatisfiedLinkError:java.library.path 中没有 SolarisSerialParallel捕获 java.lang.UnsatisfiedLinkError: com.sun.comm.SolarisDriver.readRegistrySerial(Ljava/util/Vector;Ljava/lang/String;)I 在加载驱动程序 com.sun.comm.SolarisDriver 时捕获”

我访问了stackoverflow中所有与串口数据读写相关的问题,但没有找到任何解决方案

请你帮帮我

代码如下:

package serial;
import java.io.*;
import java.util.*;
import javax.comm.SerialPort;
import javax.comm.CommPortIdentifier;
import javax.comm.UnsupportedCommOperationException;
import javax.comm.PortInUseException;

public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;

public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM6")) {
//if (portId.getName().equals("/dev/term/a")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
}
}
}

}

最佳答案

确保串口库的库路径已设置。试试这个

java -Djava.library.path=C:\java_comm\lib SimpleWrite 

您似乎正在运行 32 位版本的 Netbeans 和(扩展)Java。因此确保你有对应的32位版本的rxtxserial,可以找到here

关于java - 使用java加载串口共享库出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21790982/

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