lejos.nxt.comm
Class USBConnection

java.lang.Object
  extended by lejos.nxt.comm.USBConnection
All Implemented Interfaces:
Connection, InputConnection, OutputConnection, StreamConnection, NXTConnection

public class USBConnection
extends Object
implements NXTConnection

Represents a USB Stream Connection.


Constructor Summary
USBConnection(int mode)
           
 
Method Summary
 void close()
          Close the USB stream 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
 int read(byte[] data, int len)
          Perform an blocking read on the USB connection
 int read(byte[] data, int len, boolean wait)
          Perform an optionally blocking read on the USB connection
 void setIOMode(int mode)
          Set the IO mode to be used for this connection.
 int write(byte[] data, int len)
           
 int write(byte[] data, int len, boolean wait)
          Write the requested bytes to the USB connection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

USBConnection

public USBConnection(int mode)
Method Detail

close

public void close()
Close the USB stream connection.

Specified by:
close in interface Connection

openInputStream

public InputStream openInputStream()
Return the InputStream for this connection.

Specified by:
openInputStream in interface InputConnection
Returns:
the input stream

openOutputStream

public OutputStream openOutputStream()
Return the OutputStream for this connection

Specified by:
openOutputStream in interface OutputConnection
Returns:
the output stream

openDataInputStream

public DataInputStream openDataInputStream()
Return the DataInputStream for this connect

Specified by:
openDataInputStream in interface InputConnection
Returns:
the data input stream

openDataOutputStream

public DataOutputStream openDataOutputStream()
Return the DataOutputStream for this connection.

Specified by:
openDataOutputStream in interface OutputConnection
Returns:
the data output stream

read

public int read(byte[] data,
                int len,
                boolean wait)
Perform an optionally blocking read on the USB connection

Specified by:
read in interface NXTConnection
Parameters:
data - byte array to store the results.
len - max number of bytes to read
wait - set true to block waiting for data
Returns:
actual number of bytes read, return -2 for eof

read

public int read(byte[] data,
                int len)
Perform an blocking read on the USB connection

Specified by:
read in interface NXTConnection
Parameters:
data - byte array to store the results.
len - max number of bytes to read
Returns:
actual number of bytes read, return -2 for eof

write

public int write(byte[] data,
                 int len,
                 boolean wait)
Write the requested bytes to the USB connection

Specified by:
write in interface NXTConnection
Parameters:
data - data to be written
len - number of bytes to write
wait - true to block to write the data.
Returns:
number of bytes written or < 0 if error

write

public int write(byte[] data,
                 int len)
Specified by:
write in interface NXTConnection

setIOMode

public void setIOMode(int mode)
Set the IO mode to be used for this connection. Currently only one mode - RAW is supported. Using this mode indicates that the connection will not use a zero length packet to indicate eof.

Parameters:
mode -