
Hello! ! ! I have a problem with my MIDlet J2ME that uses the interfaz Comm Connections to communicate my Dell Axim x30 with a GPS using a serial cable RS232.
Exactly the problem that I have is that if I can open up and to listen the port COM1, I receive messages of the GPS but I cannot send messages to the GPS.
Characteristics of the MIDlet:
baudrate: 9600
bitsperchar: 8
stopbits: 2
parity: none
Thank you!!! :approve:
I use Netbeans Mobility Pack, the MIDlet is executed perfectly and receives messages using the emulator of J2ME Wireless Toolkit, but when executing it in my Dell Axim x30 it doesn't work equally.
Next I present them the code source:
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.Vector;
import java.io.InputStream;
import java.io.OutputStream;
public class CommMIDlet extends MIDlet implements Runnable, CommandListener{
private Display display;
private Form f;
private TextField tf;
private StringItem si;
private ChoiceGroup cg;
private boolean isPaused;
private Command openCommand = new Command("Open", Command.ITEM, 1);
private Command sendCommand = new Command("Send", Command.ITEM, 1);
private Sender sender;
public CommMIDlet() {
display = Display.getDisplay(this);
f = new Form("Port Selection");
cg = new ChoiceGroup("Please select port",
Choice.EXCLUSIVE, availablePorts(), null);
f.append(cg);
f.addCommand(openCommand);
f.setCommandListener(this);
display.setCurrent(f);
}
public boolean isPaused() {
return isPaused;
}
public void startApp() {
isPaused = false;
}
public void pauseApp() {
isPaused = true;
}
public void destroyApp(boolean unconditional) {
}
private String[] availablePorts() {
Vector vect = new Vector();
String ports = System.getProperty("microedition.commports");
int start = 0;
int end = 0;
while ((end = ports.indexOf(',', start)) != -1) {
vect.addElement(ports.substring(start, end).trim());
start = end + 1;
ports = ports.substring(start);
}
vect.addElement(ports);
String[] retVal = new String[vect.size()];
for (int i = 0; i < retVal.length; i++) {
retVal[i] = (String) vect.elementAt(i);
}
return retVal;
}
public void commandAction(Command c, Displayable s) {
if (isPaused()) {
return;
}
if (c == openCommand) {
new Thread(this).start();
}
if (c == sendCommand) {
sender.send(tf.getString());
}
}
public void run() {
try {
f = new Form("COMM Client");
si = new StringItem("Received:" , " ");
tf = new TextField("Send:", "", 30, TextField.ANY);
f.append(si);
f.append(tf);
f.addCommand(sendCommand);
f.setCommandListener(this);
display.setCurrent(f);
String name = cg.getString(cg.getSelectedIndex());
CommConnection commConn = (CommConnection)Connector.open(
"comm:" + name + ";baudrate=9600;bitsperchar=8;stopbits=2;parity=no ne"); InputStream iStream = commConn.openInputStream();
OutputStream oStream = commConn.openOutputStream();
sender = new Sender(oStream);
int ch = 0;
while (true) {
StringBuffer buf = new StringBuffer();
ch = 0;
while (ch != '\r') {
ch = iStream.read();
buf.append((char) ch);
}
si.setText(buf.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}