Motorola i88s manual Implementation Notes, Example using StreamConnection

Models: i88s

1 29
Download 29 pages 17.63 Kb
Page 20
Image 20

Motorola Inc.

i88s J2ME Developers’ Guide

3.Get the input stream using the openInputStream() method of InputConnection.

4.Read and write data onto those streams.

5.Close the port using the close() method of both the Connection and open Streams.

Once the connection has been established, simply use the normal methods of any input or output stream to read and write data. The openInputStream and openOutputStream methods of StreamConnection are similar to the methods of the socket StreamConnection.

Example using StreamConnection

Connector.open is used to open the serial port and a StreamConnection is returned. From the StreamConnection the InputStream and OutputStream are opened. It is used to read and write every character until the connection is closed(-1). If an exception is thrown the connection and stream are closed.

StreamConnection sc = null;

InputStream is = null;

OutputStream os = null;

/*

*Create the parameter String with options specified

*/

String parameter = "comm:0;baudrate=19200;parity=n;databits=8;stopbits=1;flowcontrol=n/n”;

try{

sc = (StreamConnection)Connector.open(parameter, Connector.READ_WRITE, false);

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

int ch;

while ((ch = is.read() ) != -1) { os.write(ch);

}

} finally {

if (sc != null) sc.close();

if(is != null) is.close();

if(os != null) os.close();

}

2.3Implementation Notes

As stated in the previous sections, the i88s phone supports a vast array of networking options. The networking options however are limited by both memory and bandwidth, which place hard restrictions on the applications. These limitations manifest themselves mainly in

Version 1.0 - Page 20

Page 20
Image 20
Motorola i88s manual Implementation Notes, Example using StreamConnection