Here is my code, for some reason, never enter inside the while.
Even if my CR200X(the ASC1 connection print something).
package hello;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.midlet.*;
import com.siemens.icm.io.*;
public class Core implements Runnable {
private int ch;
private Thread _thread = new Thread( this, "core" );
private boolean _loop;
private ATCommand _ATC;
public InputStream in;
public OutputStream out;
CommConnection con;
public void start(ATCommand atCommand) {
_loop = true;
_ATC = atCommand;
_thread.start();
}
public void stop() throws InterruptedException {
_loop = false;
_thread.join();
}
public void run() {
while (_loop) {
try {
System.out.println("Running core...");
/*this.teste(_ATC);*/
con = (CommConnection) Connector.open("comm:COM1;baudrate=115200;blocking=off;autocts=off;autorts=off");
in = con.openInputStream();
StringBuffer sb;
sb = new StringBuffer();
System.out.println("Before the loop");
while((ch = in.read()) != -1)
{
sb.append((char) ch);
System.out.println("In loop:" + ch);
}
System.out.println("After");
in.close();
con.close();
Thread.sleep(60000);
}
catch (Exception ex) {
System.err.println("Exception " + ex.getClass() + " : " +
ex.getMessage());
}
}
}
public void teste(ATCommand atCommand) {
System.out.println("Running test...");
try {
String response = "";
String phone = "04799318285";
String message = "Oioioioi!";
response = atCommand.send("AT+CMGF=1\r");
System.out.println(response);
response = "";
synchronized (atCommand) {
response = atCommand.send("AT+CMGS=04799318285,\r");
if (response.indexOf('>') >= 0) {
try {
Thread.sleep(2000);
}
catch (InterruptedException ex) {
}
response = atCommand.send(message + "\032" + "\r");
System.out.println("entrou no if:"+ response);
}
else {
System.out.println("entrou no else");
}
}
String URL, cc;
/*
URL = "comm:COM0;baudrate=115200;bitsperchar=8;stopbits=1;parity=none;blocking=off;autocts=off;autorts=off";
cc = (CommConnection) Connector.open(URL, Connector.READ_WRITE);
sb = new StringBuffer();
int ch;
doPause(20); //waiting for the stick (break between found 3 and displaying the addresses)
is = cc.openInputStream();
while((ch = is.read()) != -1)
{
sb.append((char) ch);
}
is.close();
cc.close();
*/
} catch (ATCommandFailedException ex) {
ex.printStackTrace();
} catch (IllegalStateException ex) {
ex.printStackTrace();
} catch (IllegalArgumentException ex) {
ex.printStackTrace();