SunSPOT API V6.0


com.sun.spot.peripheral
Class Serial

java.lang.Object
  extended by com.sun.spot.resources.Resource
      extended by com.sun.spot.peripheral.Serial
All Implemented Interfaces:
ISerial, IResource, Connection, InputConnection, OutputConnection, StreamConnection
Direct Known Subclasses:
EDemoSerial

public class Serial
extends Resource
implements ISerial

Serial - provides read access to the serial/USB ports of an eSPOT

The rev8 eSPOT has 3 available usarts: usart0, usart1 & usart2.
The initial eSPOT only has one: usart0.
Note: usart is the same as usart0

Note that in the case where the URL is "serial://usart" it is possible to append parameters to control the serial port settings. For example:

"serial://usart?baudrate=115200&databits=8&parity=even&stopbits=0"

Allowed values for parity are even, odd, mark and none.


Constructor Summary
Serial()
           
Serial(int type)
           
 
Method Summary
 int available()
           
protected  void cleanUpOldIsolates()
           
 void close()
          Close the connection.
 void closeInputStream()
           
 void closeOutputStream()
           
protected  boolean inUseByOtherIsolate()
          Check if the serial line is in use by another running isolate.
 DataInputStream openDataInputStream()
          Open and return a data input stream for a connection.
 DataOutputStream openDataOutputStream()
          Open and return a data output stream for a connection.
 InputStream openInputStream()
          Open and return an input stream for a connection.
 OutputStream openOutputStream()
          Open and return an output stream for a connection.
 int read()
           
 int read(byte[] b, int off, int len)
           
 void setUSARTParams(int baudrate, int databits, String parity, float stopbits)
          Set one of the ARM9's USART line parameteres.
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class com.sun.spot.resources.Resource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

Constructor Detail

Serial

public Serial()

Serial

public Serial(int type)
Method Detail

cleanUpOldIsolates

protected void cleanUpOldIsolates()

inUseByOtherIsolate

protected boolean inUseByOtherIsolate()
Check if the serial line is in use by another running isolate.

Returns:
true if the serial line is in use

setUSARTParams

public void setUSARTParams(int baudrate,
                           int databits,
                           String parity,
                           float stopbits)
                    throws IOException
Set one of the ARM9's USART line parameteres.

Specified by:
setUSARTParams in interface ISerial
Parameters:
baudrate - baud speed to set module to
databits - supported values are 5,6,7,8
parity - supported options are none, odd, even, space & mark
stopbits - supported options are 1, 1.5 or 2
Throws:
IOException

close

public void close()
Description copied from interface: Connection
Close the connection.

When a connection has been closed, access to any of its methods that involve an I/O operation will cause an IOException to be thrown. Closing an already closed connection has no effect. Streams derived from the connection may be open when method is called. Any open streams will cause the connection to be held open until they themselves are closed. In this latter case access to the open streams is permitted, but access to the connection is not.

Specified by:
close in interface Connection

openInputStream

public InputStream openInputStream()
                            throws IOException
Description copied from interface: InputConnection
Open and return an input stream for a connection.

Specified by:
openInputStream in interface ISerial
Specified by:
openInputStream in interface InputConnection
Returns:
An input stream
Throws:
IOException - If an I/O error occurs

openDataInputStream

public DataInputStream openDataInputStream()
                                    throws IOException
Description copied from interface: InputConnection
Open and return a data input stream for a connection.

Specified by:
openDataInputStream in interface InputConnection
Returns:
An input stream
Throws:
IOException - If an I/O error occurs

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Description copied from interface: OutputConnection
Open and return an output stream for a connection.

Specified by:
openOutputStream in interface ISerial
Specified by:
openOutputStream in interface OutputConnection
Returns:
An output stream
Throws:
IOException - If an I/O error occurs

openDataOutputStream

public DataOutputStream openDataOutputStream()
                                      throws IOException
Description copied from interface: OutputConnection
Open and return a data output stream for a connection.

Specified by:
openDataOutputStream in interface OutputConnection
Returns:
An output stream
Throws:
IOException - If an I/O error occurs

closeInputStream

public void closeInputStream()
                      throws IOException
Specified by:
closeInputStream in interface ISerial
Throws:
IOException

closeOutputStream

public void closeOutputStream()
                       throws IOException
Specified by:
closeOutputStream in interface ISerial
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in interface ISerial
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Specified by:
read in interface ISerial
Throws:
IOException

available

public int available()
              throws IOException
Specified by:
available in interface ISerial
Throws:
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in interface ISerial
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface ISerial
Throws:
IOException

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.