Sun Microsystems V2.0 Welding System User Manual


 
28
example above two sectors are allocated (and thus erased), starting with the first sector available to
applications.
Using the Record Management Store
The Record Management Store (RMS) that is part of the Java IM Profile provides a simple record-
based mechanism for access to persistent data.
Here is a very simple example of using the record store:
RecordStore rms = RecordStore.openRecordStore("TEST", true);
byte[] inputData = new byte[]{12,13,14,15,16};
int recordId = rms.addRecord(inputData, 0, inputData.length);
byte[] outputData = rms.getRecord(recordId);
rms.closeRecordStore();
See
javax.microedition.rms.RecordStore
for full details.
Configuration
Although read streams can be opened on any area of flash memory, output streams can only be
opened on sectors allocated for that purpose. By default sectors 39 to 46 inclusive (8 * 64Kb) are
allocated for stream-based access.
By default sectors 47 to 69 inclusive (23 * 64Kb) are allocated for RMS use.
The number of sectors allocated for stream use can be adjusted by setting the system property
spot.sectors.reserved.for.streaming
to the number of required sectors. The first RMS sector
always follows the last streaming sector.
Using input and output streams over the USB and USART connections
There is a mechanism provided for Sun SPOT applications to access input and output streams that
access the USB and USART connections. A standard Sun SPOT can only access the USB
connection. However, with a suitable adaptor, the Sun SPOT can access a USART connected to its
top connector
3
.
// for input from USB
InputStream inputStream = Connector.openInputStream("serial://usb");
int character = inputStream.read();
// for output from USB
OutputStream outputStream = Connector.openOutputStream("serial://usb");
outputStream.write("[output message goes here\n]".getBytes());
The same mechanism can be used to read to and from the USART by replacing the URL
"serial://usb"
with
"serial://usart".
A third URL
"serial://"
is also supported. This reads
and writes on USB when USB is connected and in use by a host application, and otherwise on the
USART.
Only one input stream may be opened to each device, and if
"serial://"
is opened for input then
neither
"serial://usb"
nor
"serial://usart"
can be opened for input. Multiple output streams
may be opened, and output will be interspersed in an unpredictable fashion.
By default,
System.out
and
System.err
are directed to
"serial://"
(because the Sun SPOT is
conformant with CLDC 1.1, there is no
System.in
on the Sun SPOT).
3
The USART is USART0 in the AT91RM9200 package.