1

I have to continue the development of a specific java embedded project which talks to some serial external devices.

Previous development was done using Windows and now I try to run it using Ubuntu. I have some port issue when using this code:

    String comport = Gateway.config.getHardwareRevision() <= 1 ? "com0" : "com1";

    String ports = System.getProperty("microedition.commports");
    log.log("---available PORTS: " + ports);

    serial = (CommConnection) Connector .open("comm:" + comport + ";blocking=on;baudrate=" + BAUD_RATES[baudrate]
                    + ";autocts=off;autorts=off");
    inStream = serial.openInputStream();

    outStream = serial.openOutputStream();

Basically I connect my usb to serial cable, noticed that Ubuntu is assigning to it port /dev/ttyUSB0 so I change code to:

    `String comport = Gateway.config.getHardwareRevision() <= 1 ? "/dev/ttyUSB0" : "com1";`

because hw revision is <=1 so it should load this port. Unfortunately after many tries I still receive:

Could not find serial port /dev/ttyUSB0
java.io.IOException: gnu.io.NoSuchPortException
    at javax.microedition.io.SerialConnection.open(SerialConnection.java:57)
    at javax.microedition.io.SerialConnection.<init>(SerialConnection.java:19)
    at javax.microedition.io.Connector.open(Connector.java:43)
    at javax.microedition.io.Connector.open(Connector.java:13)

I read something that I have to use RXTX if developing with Linux but I can't believe that I should rewrite java code just because I change my dev environment.

Do you have any ideas to make this work without refactoring?

Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162
  • Permission problem, maybe? – fge Mar 10 '14 at 09:24
  • Try and `strace` the program, see what it says when you attempt to open the device – fge Mar 10 '14 at 09:32
  • `gnu.io.NoSuchPortException` seems to happen with RXTX as well: http://stackoverflow.com/questions/9628988/ubuntu-rxtx-does-not-recognize-usb-serial-device (potential solutions to permission problem here) / http://stackoverflow.com/questions/9717477/java-rxtxcomm-lib-to-connect-to-dev-ttyacm0 – zapl Mar 10 '14 at 09:36

0 Answers0