|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.nxt.comm.BTConnection
public class BTConnection
Provides a Bluetooth connection Supports both packetized and stream based commincation. Blocking and non-blocking I/O. Notes: Because of the limited buffer space and the way that several connections have to share the interface to the Bluetooth device data may be lost. This will happen if a switch into command mode is required when there is data arriving from the remote connection that can not be placed into the input buffer. Every attempt is made to avoid this but it can happen. Application programs can help avoid this problem by: 1) Using just a single Bluetooth connection 2) Using Bluetooth commands while data transfers are in progress. 3) Performing application level flow control to avoid more then 256 bytes of data being sent from the remote side at any one time. 4) Reading any pending data as soon as possible. If data is lost then calls to read and write will return -2 to indicate the problem. If using packet mode then the input stream can be re-synchronized by issuing a read to discard the partial packet which may be in the input buffer.
Field Summary | |
---|---|
static int |
AM_ALWAYS
|
static int |
AM_DISABLE
|
static int |
AM_OUTPUT
|
Constructor Summary | |
---|---|
BTConnection(int chan)
|
Method Summary | |
---|---|
int |
available()
|
int |
available(int what)
Indicate the number of bytes available to be read. |
void |
close()
Close the connection. |
void |
closeStream()
Close the stream for this connection. |
int |
getSignalStrength()
Get the signal strength of this connection. |
DataInputStream |
openDataInputStream()
Return the DataInputStream for this connect |
DataOutputStream |
openDataOutputStream()
Return the DataOutputStream for this connection. |
InputStream |
openInputStream()
Return the InputStream for this connection. |
OutputStream |
openOutputStream()
Return the OutputStream for this connection |
void |
openStream()
Open the stream for this connection. |
int |
read(byte[] data,
int len)
|
int |
read(byte[] data,
int outLen,
boolean wait)
Attempt to read data from the connection. |
int |
readPacket(byte[] buf,
int len)
Read a packet from the stream. |
void |
sendPacket(byte[] buf,
int bufLen)
Send a data packet. |
void |
setIOMode(int mode)
Set operating mode. |
int |
write(byte[] data,
int len)
|
int |
write(byte[] data,
int len,
boolean wait)
Attempt to write bytes to the Bluetooth connection. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait |
Field Detail |
---|
public static final int AM_DISABLE
public static final int AM_ALWAYS
public static final int AM_OUTPUT
Constructor Detail |
---|
public BTConnection(int chan)
Method Detail |
---|
public void close()
close
in interface StreamConnection
public int write(byte[] data, int len, boolean wait)
data
- The data to be written.len
- The number of bytes to write.wait
- True if the call should block until all of the data has
been sent.
public int write(byte[] data, int len)
public int read(byte[] data, int outLen, boolean wait)
data
- Location to return the data. If null the data is discarded.outLen
- Max number of bytes to read.wait
- Should the call block waiting for data.
public int read(byte[] data, int len)
public int available(int what)
what
- 0 (all modes) return the number of bytes that can be
read without blocking.
1 (packet mode) return the number of bytes still to be
read from the current packet.
2 (packet mode) return the length of the current packet.public int available()
public void setIOMode(int mode)
mode
- Size of header, 0 indicates stream mode.public int readPacket(byte[] buf, int len)
buf
- Buffer to read data into.len
- Number of bytes to read.
public void sendPacket(byte[] buf, int bufLen)
buf
- the data to sendbufLen
- the number of bytes to sendpublic InputStream openInputStream() throws IOException
openInputStream
in interface StreamConnection
IOException
public OutputStream openOutputStream() throws IOException
openOutputStream
in interface StreamConnection
IOException
public DataInputStream openDataInputStream() throws IOException
openDataInputStream
in interface StreamConnection
IOException
public DataOutputStream openDataOutputStream() throws IOException
openDataOutputStream
in interface StreamConnection
IOException
public void closeStream()
public void openStream()
public int getSignalStrength()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |