问题
I have a processing program that is supposed to read the data from a serial port created by an arduino uno. I got the program to work perfectly in Processing but not in Eclipse. I added core.jar
serial.jar
and jssc.jar
to my java project's build path, but am still getting an error calling the port with Serial.list()[0]
.
I have seen similar questions on here, but none have helpful answers. I don't know if I'm missing something or need to import a different jar file to my build path.
import processing.core.PApplet;
import processing.serial.*;
public class Processing extends PApplet {
public Processing() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
PApplet.main("Processing");
}
Serial myPort;
String val;
public void setup() {
myPort = new Serial(this, Serial.list()[0], 9600);
}
public void draw() {
if ( myPort.available() > 0) {
val = myPort.readString();
}
if (val != null) {
println(val);
}
delay(250);
}
}
Error Message:
java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getSerialPortNames()[Ljava/lang/String;
at jssc.SerialNativeInterface.getSerialPortNames(Native Method)
at jssc.SerialPortList.getWindowsPortNames(SerialPortList.java:309)
at jssc.SerialPortList.getPortNames(SerialPortList.java:298)
at jssc.SerialPortList.getPortNames(SerialPortList.java:182)
at processing.serial.Serial.list(Unknown Source)
at Performance.Processing.setup(Processing.java:44)
at processing.core.PApplet.handleDraw(PApplet.java:2425)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
回答1:
You have added jssc.jar to the Java Build Path which is great, however jssc uses a native c++ library which you need to also reference:
- From the Java Build Path > Libraries section
- use the arrow to expand jssc.jar and select Native library location
- click Edit... on the right hand side and select the folder containing the native c++ library for your OS (in my case that's
macosx
right now)
Once you apply the changes, the link error will be satisfied.
来源:https://stackoverflow.com/questions/57183705/unsatisfiedlinkerror-using-serial-port-from-processing-in-eclipse