|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.pc.comm.NXTCommUSB
public abstract class NXTCommUSB
Base Implementation of NXTComm for USB This module implements two types of I/O over USB. 1. The standard Lego LCP format used for LCP command processing. 2. A Simple packet based protocol that can be used to transport a simple byte stream. Protocol 2 is required (rather then using raw USB operations), to allow the signaling of things like open, and close over the connection. Notes This module assumes that the device read and write functions have a built in timeout period of approx 20 seconds. This module assumes that this timeout exists and uses it to timeout some requests. Should not be used directly - use NXTCommFactory to create an appropriate NXTComm object for your system and the protocol you are using.
Field Summary |
---|
Fields inherited from interface lejos.pc.comm.NXTComm |
---|
LCP, PACKET, RAW |
Constructor Summary | |
---|---|
NXTCommUSB()
|
Method Summary | |
---|---|
int |
available()
The number of bytes that can be read without blocking. |
void |
close()
Close the current device. |
java.io.InputStream |
getInputStream()
Return an InputStream for reading a stream of data from the NXT over this connection. |
java.io.OutputStream |
getOutputStream()
Return an OutputStream for writing a stream of data to the NXT over this connection. |
boolean |
open(NXTInfo nxt)
Connect to a NXT found by a search or created from mname and address. |
boolean |
open(NXTInfo nxtInfo,
int mode)
Open a connection to the specified device, and make it available for use. |
byte[] |
read()
Read bytes from the device |
NXTInfo[] |
search(java.lang.String name,
int protocol)
Locate availabe nxt devices and return them. |
byte[] |
sendRequest(byte[] data,
int replyLen)
Send a Lego Command Protocol (LCP) request to the device. |
void |
write(byte[] data)
Write bytes to the device. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NXTCommUSB()
Method Detail |
---|
public NXTInfo[] search(java.lang.String name, int protocol)
search
in interface NXTComm
name
- The name to search for. If null return all devices.protocol
- The protocol to search for, must be USB
public boolean open(NXTInfo nxtInfo, int mode)
open
in interface NXTComm
nxtInfo
- The device to connect to.mode
- the I/O mode to be used on this connection.
public boolean open(NXTInfo nxt) throws NXTCommException
NXTComm
open
in interface NXTComm
nxt
- the NXTInfo object for the NXT
NXTCommException
public void close()
close
in interface NXTCommRequest
public byte[] sendRequest(byte[] data, int replyLen) throws java.io.IOException
sendRequest
in interface NXTCommRequest
data
- The command to send.replyLen
- How many bytes in the optional reply.
java.io.IOException
- Thrown on errors.public byte[] read() throws java.io.IOException
read
in interface NXTComm
java.io.IOException
public int available() throws java.io.IOException
available
in interface NXTComm
java.io.IOException
public void write(byte[] data) throws java.io.IOException
write
in interface NXTComm
data
- Data to be written.
java.io.IOException
public java.io.OutputStream getOutputStream()
NXTComm
getOutputStream
in interface NXTComm
public java.io.InputStream getInputStream()
NXTComm
getInputStream
in interface NXTComm
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |