Sun Microsystems V2.0 Welding System User Manual


 
29
Configuring USART parameters
The URL for USART access can uniquely be extended with additional parameters to configure the
USART if required. For example:
InputStream inputStream = Connector.openInputStream(
"serial://usart?baudrate=57600&databits=7&parity=even&stopbits=1.5");
databits may be 5, 6, 7 or 8, parity can be none, even, odd, space or mark, and stop bits can be 1, 1.5
or 2. You need specified only those options you wish to change. Because a call of this nature will
disrupt any ongoing communications, this kind of call can only be made while there are no existing
output or input streams connected to
"serial://usart"
.
As we said above,
System.out
and
System.err
are by default connected to
"serial://"
and by
implication to
"serial://usart"
. Thus, if it is required to adjust the USART settings in the fashion
shown above, then
System.out
and
System.err
must be diverted like this:
Isolate currentIsolate = Isolate.currentIsolate();
currentIsolate.clearOut();
currentIsolate.clearErr();
currentIsolate.addOut("serial://usb"); // not required but useful for development
currentIsolate.addErr("serial://usb"); // not required but useful for development
OutputStream serialOutput = Connector.openOutputStream("serial://usart?baudrate=9600");
Note that none of this is required if the default settings for the USART are acceptable (these are
baudrate=115,200, databits=8, parity=none, stopbits=1).
Limitations on the use of the USART
When the Sun SPOT boots it will send some characters over the USART using the default settings
unless USB is connected and in use by a host application. These characters are necessary to allow
the SPOT to talk to the SPOT Client program (the program that underpins many of the ant
commands) via a RS232 connection. Your application should take steps to ignore these characters.
USART input uses a 512 byte input ring buffer, loaded using an interrupt handler. There is no
protection for overflow of the ring buffer. It is up to the application to ensure that data is read
quickly enough, given the baud rate and rate of transmission.
Transmission is not interrupt driven: each transmit request is a synchronous call to VM native code.
Whilst transmitting the SPOT cannot do anything else, so it is wise to use the highest baud rate
compatible with reliable reception.
The radio communication library
About the radio stack
The classes for the radio stack above the Mac layer are in
multihoplib_rt.jar
, and the
corresponding sources can be found in
multihoplib_source.jar
.
J2ME uses a Generic Connection Framework (GCF) to create connections (such as HTTP,
datagram, or streams) and perform I/O. The current version of the Sun SPOT SDK uses the GCF to
provide radio communication between SPOTs, routed via multiple hops if necessary, using a choice
of two protocols.
The
radiostream
protocol provides reliable, buffered, stream-based communication between two
devices.