Go Down

Topic: Java RXTX help! (Read 4458 times) previous topic - next topic


Ok, i have my java rxtx program, and im having problems, i dont know what is wrong. i installed the RXTX stuff, and im getting errors.
Code: [Select]

package serial;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;

public class Main {
   static InputStream input;
   static OutputStream output;

   public static void main(String[] args) throws Exception{
       System.out.println("Using port: " + Preferences.get("serial.port"));
       CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(

       SerialPort port = (SerialPort)portId.open("serial talk", 4000);
       input = port.getInputStream();
       output = port.getOutputStream();
           while(input.available()>0) {

preferences.init() comes in and error and this is the error code it gives me when i try to run the program.
Code: [Select]

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
       at serial.Main.main(Main.java:13)
Java Result: 1

but, if i delete it, (the preferences.init()) this is the output i get is...
Code: [Select]

Using port: null
Stable Library
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Exception in thread "main" gnu.io.NoSuchPortException
       at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:218)
       at serial.Main.main(Main.java:15)
Java Result: 1

Brad Needham

It sounds like you're having similar problems to what others have had using the Preferences object in the Silveira Neto tutorial.

See http://silveiraneto.net/2009/03/01/arduino-and-java/#comment-4322 for one solution: removing the Preferences references completely.

Brad Needham

I should be clearer:

The "Using port: null" indicates the problem: that Preferences.get("serial.port") is returning null - that is, you haven't set a preference for the serial port to use.  When CommPortIdentifier.getPortIdentifier() is called with null as the port of interest, it gives you the NoSuchPortException.

Go Up