Sun Microsystems V2.0 manual Radio communication library

Page 29
multihoplib_rt.jar, and the

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

29

Image 29
Contents Page Page Contents Http protocol support Introduction Deploying and running a sample application Building and deploying Sun Spot applicationsBuild Successful Total time 3 seconds \MyApplication Ant -Dport=COM2 info Total time 4 seconds \MyApplication Total time 0 seconds \MyApplication Incorporating utility classes into your application Deploying a pre-existing jarOther user properties Manifest and resourcesExcluding files from the compilation Overview Using the BasestationBuilt-in properties Set up Introduction Base Station configurationRemote operation Connect a Sun Spot base station Managing keys and sharing Sun SPOTs Using short names for SPOTsTake suitable actions during over-the-air downloads BackgroundSharing Sun SPOTs Changing the owner of a Sun SpotDeploying and running a host application What is protected?Generating a new key-pair LimitationsYour own host application Configuring network featuresIncorporating pre-existing jars into your host application Mesh routingLogging Hardware configurations and USB powerTrace route Page Thread priorities Overview of an applicationThreads Device Interface Sun Spot device librariesSun Spot device library Persistent properties Overriding the Ieee address Accessing flash memoryUsart Radio communication library Program Radiogram protocol Server end Client endYou can open server radiogram connections in a similar way Broadcasting Radio properties Turning the receiver off and on Shallow Sleep Conserving power using deep sleep modeMonitoring radio activity Deep Sleep Activating deep sleep modePreconditions for deep sleeping USB inhibits deep sleepDeep sleep behaviour of the standard drivers Device Condition to permit deep sleepWriting a device driver Http protocol support Configuring the http protocolSocket Proxy GUI mode Configuring projects in an IDEDebugging Classpath configurationJavadoc/source configuration Ant selectapplication Configuring Eclipse as a debug client Configuring NetBeans as a debug clientAdvanced topics Using library suitesWith adderlib as your current directory, execute the command Use the command Using the spot client SpotSerialPortException other exception in serial port comms Property name Meaning ReferencePersistent system properties Contents of the lib directory Contents of the arm directoryMemory usage Start address Space UseContents of the bin directory preverify.exe Contents of the tests directory Contents of the upgrade directory