Motorola Inc. | i88s J2ME Developers’ Guide |
Although serial port access is integrated into the Generic Connection Framework, the URL parameters passed in deviates from the other networking protocols. The optional parameters, such as baud rate, parity, etc are appended to the base parameter of “comm.:0”. Optional parameters are listed below along with the default values when not explicitly specified:
Table 2-2: Connection Optional Parameters
Parameter | Syntax | Options | Default |
baudrate | baudrate = x | [300,1200,2400,4800,9600,19200,38400,57600,115200] | 19200 |
databits | databits = x | [8,7] | 8 |
stopbits | stopbits = x | 1 | 1 |
parity with | parity = x | [n,o,e,s,m] n=none, o = odd, e=even, s=space, m=mark | n |
mapping |
|
|
|
Flow | flowcontrol = | [n, s, h] / [n, s, h] n=none, s=software,h=hardware | N/n |
control | outflow/inflow |
|
|
Note - The following combinations of properties are not supported.
7 databits with none parity
8 databits with mark parity
8 databits with space parity
8 databits with odd parity
8 databits with even parity.
IOException will be thrown while trying to use any of the unsupported combinations in Connector.open().
All properties must be semicolon separated. If all properties are not passed, the remaining properties will be taken as default values. The order of properties in the argument does not matter.
name = "comm:0;baudrate=38400;"
Here, the flow control, parity, data bits and stop bits will use the default values.
For mode and timeout refer to the CLDC API specification for the Connector class. Note – The timeout period for Comm Port is 10000ms ~ 10 sec.
Communicating on a Port
The open method of the Connector class returns a StreamConnection object for the serial port. StreamConnection has methods for obtaining input and output streams from a port. The base interface, Connection, has a method to close the port. (Refer to the class hierarchy from StreamConnection from J2ME CLDC API specification).
There are five basic steps to communicating with a port:
1.Open the port using the open() method of Connector. If the port is available, this returns a StreamConnection object for Comm port. Otherwise, an IOException is thrown.
2.Get the output stream using the openOutputStream() method of OutputConnection.
Version 1.0 - Page 19