RXTX not working in ubuntu

Finally managed to read from rxtx on Windows, but now I just can't get it to work on Ubuntu. I get rxtx libs using apt-get, but when I run the application I don’t see anything, I tried a couple of -catch attempts and I don’t even get an exception, and since debugging Ubuntu is not possible at the moment, I can’t pinpoint the problem. (Ubuntu - 12.04 64 bit).

import gnu.io.*;
import java.io.*;
import javax.swing.JOptionPane;

public class ReadComPort {

    public static void main(String[] s) {
        readcomport();
    }

    public static String readcomport() {
        String value = null;

        try {
            // CommPortIdentifier portIdentifier = CommPortIdentifier
            // .getPortIdentifier("COM1");

            // String comportidentifier = "COM1"; //*win
            String comportidentifier = "/dev/ttyS0";

            CommPortIdentifier portIdentifier = null;
            portIdentifier = CommPortIdentifier.getPortIdentifier(comportidentifier);

            if (portIdentifier.isCurrentlyOwned()) {
                JOptionPane.showMessageDialog(null, "port in use");
            } else {

                SerialPort serialPort = (SerialPort) portIdentifier.open("ReadComPort", 500);
                JOptionPane.showMessageDialog(null, serialPort.getBaudRate());

                serialPort.setSerialPortParams(serialPort.getBaudRate(), SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
                // serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);
                serialPort.setDTR(true);
                serialPort.setRTS(true);

                InputStream mInputFromPort = serialPort.getInputStream();

                Thread.sleep(500);
                byte mBytesIn[] = new byte[32];
                mInputFromPort.read(mBytesIn);

                value = new String(mBytesIn);

                mInputFromPort.close();
                serialPort.close();
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Exception : " + ex.getMessage());

        }

        return value;

    }
}
+3
source share
2 answers

Check if the configuration file is javax.comm.propertiesin the classpath. Because of this, I had endless problems with RXTX - it just fails.

+1
source

I had the same problem yesterday and I found this :

String serialPortID = "/dev/ttyAMA0";
System.setProperty("gnu.io.rxtx.SerialPorts", serialPortID);

Thath, gnu.io.rxtx.SerialPorts, , .

+1

All Articles