Header Sep

Java Tips, Tricks & Code

My Rating Score
Login to rate page

April 2007

Serial port connection using Java ME for P990, M600 and W950

Creating a serial port connection using Java ME, CommConnection, is supported by the Sony Ericsson K610 and K800 mobile phone series (Java Platform 7) and the UIQ 3 phones P990, M600, W950.

This article describes how to make the CommConnection on Sony Ericsson's UIQ 3 phones. Refer to the Java ME Developers' Guidelines for how this can be done on non-Symbian OS phones>>

For this example to work, the USB drivers must be installed on the PC. They are included in the PC Suite which is available for download here>>

Now connect the USB cable to the UIQ 3-based phone and start the HyperTerminal. Start >> Programs >> accessories >> accessibility >> HyperTerminal or Start >> Run "hypertrm"

The HyperTerminal must be connected to the Debug Port. Check the Device Manager for the correct port number. Control Panel >> System >> Hardware >> Device Manager >> Ports

Now it's time to start the MIDlet on the phone. The MIDlet can be started before the PC makes the connection to the phone.

To check if serial connection is supported, the Class.forName(…) method can be used.

Class.forName("javax.microedition.io.CommConnection");

To check which com ports are available for the MIDlet, the system property "microedition.commports" can be used.

System.getProperty("microedition.commports"));

Make sure to use the USB3 port for the connection.

And to make the connection between the phone and the PC, we can use the code:

try{
 CommConnection conn = (CommConnection)Connector.open("comm:USB3");
 os = conn.openOutputStream();
 os.write("Hello from MIDlet!!\r\n".getBytes());
    os.flush();

    InputStream is = conn.openInputStream();
    int i;
    do{
        i = is.read();
        System.out.println(i);
    }while(i != -1);

}catch(Exception e){
    e.printStackTrace();
}

More information:

My Rating Score
Login to rate page