Ayuda para MIDlet Comm Conections en una PocketPC Dell Axim x30

edparker
13 de Agosto del 2005
Hola a todos!!!

Alguien me podr铆a ayudar con un MIDlet J2ME que utiliza la clase CommConections y que env铆a datos por el puerto serial de una PocketPc Dell Axim x30.

El problema es que puedo escuchar el leer el puerto COM1 pero no puedo enviar datos.

El MIDlet que estoy programando, estoy tratando de que tenga estas caracter铆sticas:

baudrate: 9600
bitsperchar: 8
stopbits: 2
parity: ninguna

Este MIDlet me servir谩 de mucho ya que estoy haciendo el prototipo de control inal谩mbrico para el robot m贸vil Koala de k-team utilizando mi Dell Axim x30 y el MIDlet se enacarga de comunicarlos a travez de un cable serial rs232 par GPS's.

El MIDlet se ejecuata a la perfeci贸n enviando y recibiendo datos por el puerto COM1 de una PC comun y corriente utilizando el emulador de J2ME Wireless Toolkit, pero cuando lo ejecuto en mi Dell Axim solo recibe datos.


Gracias por su ayuda!!!

Hasta pronto!!!!

Les muestro el codigo del MIDlet:

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class Client implements Runnable, CommandListener {

private SocketMIDlet parent;
private Display display;
private Form f;
private StringItem si;
private TextField tf;
private boolean stop;

private Command sendCommand = new Command("Send", Command.ITEM, 1);

InputStream is;
OutputStream os;
SocketConnection sc;
Sender sender;
SenderComm senderComm; //env铆a datos por el puerto serial

public Client(SocketMIDlet m) {

parent = m;
display = Display.getDisplay(parent);
f = new Form("Socket Client");
si = new StringItem("Status:" , " ");
tf = new TextField("Send:", "", 30, TextField.ANY);
f.append(si);
f.append(tf);
f.addCommand(sendCommand);
f.setCommandListener(this);
display.setCurrent(f);
}

/**
* Start the client thread
*/
public void start() {
Thread t = new Thread(this);
t.start();
}

public void run() {
try {

//conecta puerto serial
CommConnection commConn = (CommConnection)Connector.open(
"comm:COM1;baudrate=9600;bitsperchar=8;stopbits=2;parity=none");
InputStream iStream = commConn.openInputStream();
OutputStream oStream = commConn.openOutputStream();

int ch=0;



sc = (SocketConnection) Connector.open("socket://localhost:1024");

si.setText("Connected to server");

is = sc.openInputStream();
os = sc.openOutputStream();

// Start the thread for sending messages - see Sender's main
// comment for explanation
sender = new Sender(os);

// envia datos por el puerto serial
senderComm = new SenderComm(oStream);


// Loop forever, receiving data
while (true) {
StringBuffer sb = new StringBuffer();
int c = 0;
while (((c = is.read()) != 'n') && (c != -1)) {
sb.append((char) c);
}

StringBuffer buf = new StringBuffer();
ch = 0;
while (ch != 'r') {
ch = iStream.read();
buf.append((char) ch);
}

// Display message to user
si.setText(sb.toString());
senderComm.send(sb.toString()); //envia datos por el puerto serial
si.setText(buf.toString());
}

} catch (ConnectionNotFoundException cnfe) {
Alert a = new Alert("Client", "Please run Server MIDlet first",
null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
a.setCommandListener(this);
display.setCurrent(a);
} catch (IOException ioe) {
if (!stop) {
ioe.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void commandAction(Command c, Displayable s) {
if (c == sendCommand && !parent.isPaused()) {
sender.send(tf.getString());
}
if (c == Alert.DISMISS_COMMAND) {
parent.notifyDestroyed();
parent.destroyApp(true);
}
}

/**
* Close all open streams
*/
public void stop() {
try {

stop = true;
sender.stop();

if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
if (sc != null) {
sc.close();
}
}
catch (IOException ioe) {
}
}

}



agvj2
13 de Agosto del 2005
Hola :
Me gustaria saber que utilizas para ejecutar MIDlet麓s en la PDA.

Muchas gracias