我必须将数据发送到串口,javax.comm也包括在内但是它给出了错误 “抓到java.lang.UnsatisfiedLinkError:加载驱动程序gnu.io.RXTXCommDriver时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;)我正在加载驱动程序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) {}
}
}
}
}
}
答案 0 :(得分:1)
确保已设置串行库的库路径。试试这个
java -Djava.library.path=C:\java_comm\lib SimpleWrite
您似乎正在运行32位版本的Netbeans和(通过扩展)Java。因此,请确保您拥有相应的32位版本的rxtxserial,可以找到here