Sun Microsystems V2.0 manual Usart

Page 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 connector3.

// 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).

3The USART is USART0 in the AT91RM9200 package.

28

Image 28
Contents Page Page Contents Http protocol support Introduction Building and deploying Sun Spot applications Deploying and running a sample applicationBuild Successful Total time 3 seconds \MyApplication Ant -Dport=COM2 info Total time 4 seconds \MyApplication Total time 0 seconds \MyApplication Deploying a pre-existing jar Incorporating utility classes into your applicationExcluding files from the compilation Manifest and resourcesOther user properties Built-in properties Using the BasestationOverview Set up Remote operation Base Station configurationIntroduction Connect a Sun Spot base station Using short names for SPOTs Managing keys and sharing Sun SPOTsTake suitable actions during over-the-air downloads BackgroundChanging the owner of a Sun Spot Sharing Sun SPOTsWhat is protected? Deploying and running a host applicationGenerating a new key-pair LimitationsConfiguring network features Your own host applicationIncorporating pre-existing jars into your host application Mesh routingTrace route Hardware configurations and USB powerLogging Page Threads Overview of an applicationThread priorities Sun Spot device library Sun Spot device librariesDevice Interface Persistent properties Accessing flash memory Overriding the Ieee addressUsart Radio communication library Program Radiogram protocol Client end Server endYou can open server radiogram connections in a similar way Broadcasting Radio properties Turning the receiver off and on Monitoring radio activity Conserving power using deep sleep modeShallow Sleep Activating deep sleep mode Deep SleepUSB inhibits deep sleep Preconditions for deep sleepingDeep sleep behaviour of the standard drivers Device Condition to permit deep sleepWriting a device driver Configuring the http protocol Http protocol supportConfiguring projects in an IDE Socket Proxy GUI modeJavadoc/source configuration Classpath configurationDebugging Ant selectapplication Configuring NetBeans as a debug client Configuring Eclipse as a debug clientUsing library suites Advanced topicsWith adderlib as your current directory, execute the command Use the command Using the spot client SpotSerialPortException other exception in serial port comms Persistent system properties ReferenceProperty name Meaning Contents of the arm directory Contents of the lib directoryMemory usage Start address Space UseContents of the bin directory preverify.exe Contents of the upgrade directory Contents of the tests directory