Java ME Developer Guide

Chapter 28 - CommConnection Interface

plementing profile. The security model will be applied on the invocation of the ￿￿￿￿

￿￿￿￿￿￿￿￿￿￿￿ ￿￿ method with a valid serial port connection string. Should the applic- ation not be granted access to the serial port through the profile authorization scheme, a ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿ will be thrown from the ￿￿￿￿￿￿￿￿￿￿￿￿￿￿

￿￿method. The security model will be applied during execution, specifically when the methods ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿ ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿ ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿

￿￿￿ ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿ are invoked.

Code Sample 13 shows the implementation of CommConnection:

Sample of a CommConnection accessing a simple loopback program

CommConnection cc = (CommConnection) Connector.open("comm:com0;baudrate=19200");

int baudrate = cc.getBaudRate(); InputStream is = cc.openInputStream(); OutputStream os = cc.openOutputStream(); int ch = 0;

while(ch != 'Z') { os.write(ch); ch = is.read(); ch++;

}

is.close();

os.close();

cc.close();

Sample of a CommConnection discovering available comm Ports

String port1;

String ports = System.getProperty("microedition.commports"); int comma = ports.indexOf(',');

if (comma > 0) {

//Parse the first port from the available ports list. port1 = ports.substring(0, comma);

}else {

//Only one serial port available.

port1 =ports;

}

Code Sample 13 CommConnection implementation

DRAFT - Subject to Change [186/201]

Page 186
Image 186
Motorola maxx V6 manual Draft Subject to Change 186/201, Sample of a CommConnection discovering available comm Ports