1 Reply Latest reply: Aug 2, 2011 4:33 AM by 879623 RSS

    Serial port in j2me

    846958
      Hello

      I used the following code to open serial port on nokia N70 mobile

      import java.io.IOException;
      import java.io.InputStream;
      import java.io.OutputStream;
      import javax.microedition.io.CommConnection;
      import javax.microedition.io.Connector;
      import javax.microedition.lcdui.Alert;
      import javax.microedition.lcdui.Display;
      import javax.microedition.midlet.*;

      /**
      * @author mostafa
      */
      public class Serializer extends MIDlet {
      Connector con;
      OutputStream os = null;
      CommConnection cc = null;
      InputStream is = null;
      Alert alert;
      int i=0;

      public void startApp() {

      try {
      cc = (CommConnection) Connector.open("comm:com0;baudrate=19200");
      i=1;
      //int baudrate = cc.getBaudRate();


      is = cc.openInputStream();
      i=2;


      os = cc.openOutputStream();
      i=3;
      int ch = 0;
      while(ch!=10)
      os.write('k');
      i=4;
      cc.close();
      i=5;
      os.close();
      i=6;
      }
      catch (Exception ex) {
      String s= ex.getMessage();
      alert = new Alert("Problem");
      alert.setString(s+""+"i="+i);
      alert.setTimeout(alert.FOREVER);
      Display.getDisplay(this).setCurrent(alert);

      }

      }
      public void pauseApp() {
      }

      public void destroyApp(boolean unconditional) {
      }
      }


      And the output on the mobile screen was:
      java.lang.ClassNotFoundException: com/symbian/midp/io/protocol/comm/Protocol
      i=1
      (which means it throwed the exception during this command: cc = (CommConnection) Connector.open("comm:com0;baudrate=19200"); )

      Earlier, I have tried to use System.getProperty("microedition.commports") to know the available serial ports, but it gives me null always.


      Can any one tell me what is wrong?