lejos.pc.comm
Class NXTCommBluecove

java.lang.Object
  extended by lejos.pc.comm.NXTCommBluecove
All Implemented Interfaces:
javax.bluetooth.DiscoveryListener, NXTCommRequest, NXTComm

public class NXTCommBluecove
extends java.lang.Object
implements NXTComm, javax.bluetooth.DiscoveryListener

Implementation of NXTComm using the Bluecove libraries on Microsoft Windows. 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
 
Fields inherited from interface javax.bluetooth.DiscoveryListener
INQUIRY_COMPLETED, INQUIRY_ERROR, INQUIRY_TERMINATED, SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_DEVICE_NOT_REACHABLE, SERVICE_SEARCH_ERROR, SERVICE_SEARCH_NO_RECORDS, SERVICE_SEARCH_TERMINATED
 
Constructor Summary
NXTCommBluecove()
           
 
Method Summary
 int available()
          Request the number of bytes available to read.
 void close()
          Close the connection
 void deviceDiscovered(javax.bluetooth.RemoteDevice btDevice, javax.bluetooth.DeviceClass cod)
           
 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.
 void inquiryCompleted(int discType)
           
 boolean open(NXTInfo nxt)
          Connect to a NXT found by a search or created from name and address.
 boolean open(NXTInfo nxt, int mode)
          Connect to a NXT found by a search or created from name and address.
 byte[] read()
          Read data from a NXT that has an open connection.
 NXTInfo[] search(java.lang.String name)
          Search for NXTs over USB, Bluetooth or both
 byte[] sendRequest(byte[] message, int replyLen)
          Sends a request to the NXT brick.
 void servicesDiscovered(int transID, javax.bluetooth.ServiceRecord[] servRecord)
           
 void serviceSearchCompleted(int transID, int respCode)
           
 java.lang.String stripColons(java.lang.String s)
           
 void write(byte[] data)
          Write data to a NXT that has an open connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NXTCommBluecove

public NXTCommBluecove()
Method Detail

search

public NXTInfo[] search(java.lang.String name)
                 throws NXTCommException
Description copied from interface: NXTComm
Search for NXTs over USB, Bluetooth or both

Specified by:
search in interface NXTComm
Parameters:
name - name of the NXT or null
Returns:
a NXTInfo object describing the NXt found and the connection to it
Throws:
NXTCommException

open

public boolean open(NXTInfo nxt,
                    int mode)
             throws NXTCommException
Description copied from interface: NXTComm
Connect to a NXT found by a search or created from name and address.

Specified by:
open in interface NXTComm
Parameters:
nxt - the NXTInfo object for the NXT
mode - the mode for the connection: NXTComm.LCP, NXTComm.PACKET or NXTComm.RAW
Returns:
true if the open succeeded
Throws:
NXTCommException

open

public boolean open(NXTInfo nxt)
             throws NXTCommException
Description copied from interface: NXTComm
Connect to a NXT found by a search or created from name and address.

Specified by:
open in interface NXTComm
Parameters:
nxt - the NXTInfo object for the NXT
Returns:
true if the open succeeded
Throws:
NXTCommException

close

public void close()
           throws java.io.IOException
Description copied from interface: NXTCommRequest
Close the connection

Specified by:
close in interface NXTCommRequest
Throws:
java.io.IOException

sendRequest

public byte[] sendRequest(byte[] message,
                          int replyLen)
                   throws java.io.IOException
Sends a request to the NXT brick.

Specified by:
sendRequest in interface NXTCommRequest
Parameters:
message - Data to send.
replyLen - the reply length expected
Returns:
the reply
Throws:
java.io.IOException

read

public byte[] read()
            throws java.io.IOException
Description copied from interface: NXTComm
Read data from a NXT that has an open connection. Used for stream connections.

Specified by:
read in interface NXTComm
Returns:
the data in a byte[] array
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Description copied from interface: NXTComm
Request the number of bytes available to read.

Specified by:
available in interface NXTComm
Returns:
the number of bytes available
Throws:
java.io.IOException

write

public void write(byte[] data)
           throws java.io.IOException
Description copied from interface: NXTComm
Write data to a NXT that has an open connection.

Specified by:
write in interface NXTComm
Parameters:
data - the data to be written. Used for stream connections.
Throws:
java.io.IOException

deviceDiscovered

public void deviceDiscovered(javax.bluetooth.RemoteDevice btDevice,
                             javax.bluetooth.DeviceClass cod)
Specified by:
deviceDiscovered in interface javax.bluetooth.DiscoveryListener

inquiryCompleted

public void inquiryCompleted(int discType)
Specified by:
inquiryCompleted in interface javax.bluetooth.DiscoveryListener

servicesDiscovered

public void servicesDiscovered(int transID,
                               javax.bluetooth.ServiceRecord[] servRecord)
Specified by:
servicesDiscovered in interface javax.bluetooth.DiscoveryListener

serviceSearchCompleted

public void serviceSearchCompleted(int transID,
                                   int respCode)
Specified by:
serviceSearchCompleted in interface javax.bluetooth.DiscoveryListener

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: NXTComm
Return an OutputStream for writing a stream of data to the NXT over this connection.

Specified by:
getOutputStream in interface NXTComm
Returns:
the OutputStream object

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: NXTComm
Return an InputStream for reading a stream of data from the NXT over this connection.

Specified by:
getInputStream in interface NXTComm
Returns:
the InputStream object

stripColons

public java.lang.String stripColons(java.lang.String s)