Reputation: 1290
I'm trying to write data on to my Arduino Uno and also receive the date from it.
I'm using NetBeans on Windows 8.1, and the library "RXTXcomm.jar" in order to do that.
My code is this and my Arduino is on COM3, and it throws an error on the line 25 and 80 :
ERROR
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:83)
at arduino.test.pkg3.ArduinoTest3.initialize(ArduinoTest3.java:25)
at arduino.test.pkg3.ArduinoTest3.main(ArduinoTest3.java:80)
The Code :
01: package arduino.test.pkg3;
02:
03: import java.io.BufferedReader;
04: import java.io.InputStreamReader;
05: import java.io.OutputStream;
06: import gnu.io.CommPortIdentifier;
07: import gnu.io.SerialPort;
08: import gnu.io.SerialPortEvent;
09: import gnu.io.SerialPortEventListener;
10: import java.util.Enumeration;
11:
12: public class ArduinoTest3 implements SerialPortEventListener {
13:
14: SerialPort serialPort;
15: private static final String PORT_NAMES[] = {"COM3"};
16: private BufferedReader input;
17: private OutputStream output;
18: private static final int TIME_OUT = 2000;
19: private static final int DATA_RATE = 9600;
20:
21: public void initialize(){
22: System.setProperty("gnu.io.rxtx.SerialPorts", "COM3");
23:
24: CommPortIdentifier portId = null;
25: Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
while(portEnum.hasMoreElements()){
CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
for(String portName : PORT_NAMES){
if(currPortId.getName().equals(portName)){
portId = currPortId;
break;
}
}
}
if(portId == null){
System.out.println("Could not find COM port.");
return;
}
try{
serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
serialPort.setSerialPortParams(DATA_RATE,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
output = serialPort.getOutputStream();
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
}catch(Exception e){
System.err.println(e.toString());
}
}
public synchronized void close(){
if(serialPort != null){
serialPort.removeEventListener();
serialPort.close();
}
}
public synchronized void serialEvent(SerialPortEvent oEvent){
if(oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE){
try{
String inputLine=input.readLine();
System.out.println(inputLine);
}catch (Exception e){
System.err.println(e.toString());
}
}
}
public static void main(String[] args) throws Exception{
ArduinoTest3 main = new ArduinoTest3();
80 : main.initialize();
Thread t=new Thread(){
public void run(){
try{Thread.sleep(1000000);}catch(InterruptedException ie) {}
}
};
t.start();
System.out.println("Started");
}
}
Hope you guys find an answer :)
Upvotes: 1
Views: 2096
Reputation: 1290
I solved the problem.....
I should also make the 'RXTXcomm.jar' library talk to a 'dll' file called 'rxtxSerial.dll'. But after i added that 'dll' file, i'v got a different error, but the problem this time was from the 'dll' file itself, so after a lot of researching, I found the full 'dll' file (http://jlog.org/rxtx-win.html) and the tutorial on (https://www.youtube.com/watch?v=43Vdpz1YmdU)and it worked :) .
Hope someone will find my experience useful.
Upvotes: 1