我一直在使用 JSSC 连接器进行串行连接,但出现了下一个异常:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no libjssc in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at jssc.SerialNativeInterface.<clinit>(SerialNativeInterface.java:34)
at jssc.SerialPort.<init>(SerialPort.java:93)
at cl.raien.jssc.SerialExample.main(SerialExample.java:22)
编码:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jssc.SerialPort;
import jssc.SerialPortException;
public class SerialExample {
static Logger log = LoggerFactory.getLogger(SerialExample.class);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
log.info(System.getProperty("java.library.path"));
SerialPort serialPort = new SerialPort("ttyUSB0");
try {
System.out.println("Port opened: " + serialPort.openPort());
System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("Hello World!!!".getBytes()));
System.out.println("Port closed: " + serialPort.closePort());
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
}
我正在使用 ubuntu 12.10 86x_64 和 de jssc 安装$HOME/.jssc/linux/libjSSC-0.9_x86_64.so
在 Eclipse 中,我在jssc.jar的Native Library Location中设置为首先指向该目录。然后,我将该文件放在项目根文件夹中,如scream3r.org 所说。最后,我将文件名更改为libjssc和libjssc.so。
提前致谢!!