Go Down

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

jcbconway

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{
       Preferences.init();
       System.out.println("Using port: " + Preferences.get("serial.port"));
       CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
               Preferences.get("serial.port"));

       SerialPort port = (SerialPort)portId.open("serial talk", 4000);
       input = port.getInputStream();
       output = port.getOutputStream();
       port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
               SerialPort.DATABITS_8,
               SerialPort.STOPBITS_1,
               SerialPort.PARITY_NONE);
       while(true){
           while(input.available()>0) {
               System.out.print((char)(input.read()));
           }
       }
   }
}


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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy