I made an arduino and java application, so that the java app, can communicate with the arduino through the serial port. I try to open the arduino and write to it, in order to get a response, to see if it is the arduino. My arduino code is:
Java Code:
//Setup message bytes

int pin = 30;

void setup() {
  Serial.begin(9600);
  pinMode(pin,OUTPUT);
}

void loop() {           
       //Detect Command type
       if(Serial.read()==(byte)1)
       Serial.write("arduino");
       if(Serial.read()==(byte)49)
       digitalWrite(pin,HIGH);
       if(Serial.read()==(byte)48)
       digitalWrite(pin,LOW);
  }
java code:
Java Code:
//SerialPort[] ArrayCom = null;
        SerialPort port =new SerialPort("/dev/ttyACM"+i);
         //SerialPort port=new SerialPort("/dev/tty/ACM0");
        port=new SerialPort(port.getPortName().concat(""+i));
        try{
        port.openPort();        
        port.writeByte((byte)1);
        }catch(Exception e){i+=1;}
        if(port.readString()=="arduino"){
            port.writeByte((byte)49);
            try{
            a.setText(port.getPortName().concat(""+i));}
            catch(Exception e){System.out.println("no se pudo escribir");}
when I try to open the port and write to the arduino, I get this error:
Java Code:
jssc.SerialPortException: Port name - /dev/ttyACM00; Method name - readString(); Exception type - Port not opened.
	at jssc.SerialPort.checkPortOpened(SerialPort.java:878)
	at jssc.SerialPort.readString(SerialPort.java:712)
	at protechhn.battery.monitor.serial.port(serial.java:28)
	at protechhn.battery.monitor.Barra.run(Barra.java:88)
can someone please tell me how to fix it?
I'm using JSSC library, for the serial communication in java.
I'm trying to make this work under lubuntu and ubuntu like linux distros.
Thanks.