Pages: [1]   Go Down
Author Topic: Java RXTX help!  (Read 2477 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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:
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
Logged

Portland area, Oregon, USA
Offline Offline
Newbie
*
Karma: 2
Posts: 15
Was using PICBasic, now Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Portland area, Oregon, USA
Offline Offline
Newbie
*
Karma: 2
Posts: 15
Was using PICBasic, now Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: