lejos.pc.comm
Class NXTCommBluecove

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

public class NXTCommBluecove
extends Object
implements NXTComm, 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.

Rating red

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(RemoteDevice btDevice, DeviceClass cod)
          Called when a device is found during an inquiry.
 InputStream getInputStream()
          Return an InputStream for reading a stream of data from the NXT over this connection.
 OutputStream getOutputStream()
          Return an OutputStream for writing a stream of data to the NXT over this connection.
 void inquiryCompleted(int discType)
          Called when an inquiry is completed.
 boolean open(NXTInfo nxt)
          Connect to a NXT found by a search or created from mname and address.
 boolean open(NXTInfo nxt, int mode)
          Connect to a NXT found by a search or created from mname and address.
 byte[] read()
          Read data from a NXT that has an open connection.
 NXTInfo[] search(String name, int protocol)
          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, ServiceRecord[] servRecord)
          Called when service(s) are found during a service search.
 void serviceSearchCompleted(int transID, int respCode)
          Called when a service search is completed or was terminated because of an error.
 String stripColons(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(String name,
                        int protocol)
                 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
protocol - bitwise combination of NXTCommFactory.BLUETOOTH and NXTCommFactory.USB
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 mname and address.

Specified by:
open in interface NXTComm
Parameters:
nxt - the NXTInfo object for the NXT
mode - the mode for the connection
Returns:
true iff 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 mname 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 IOException
Description copied from interface: NXTCommRequest
Close the connection

Specified by:
close in interface NXTCommRequest
Throws:
IOException

sendRequest

public byte[] sendRequest(byte[] message,
                          int replyLen)
                   throws 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:
IOException

read

public byte[] read()
            throws 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
Throws:
IOException

available

public int available()
              throws 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:
IOException

write

public void write(byte[] data)
           throws 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:
IOException

deviceDiscovered

public void deviceDiscovered(RemoteDevice btDevice,
                             DeviceClass cod)
Description copied from interface: DiscoveryListener
Called when a device is found during an inquiry. An inquiry searches for devices that are discoverable. During Bluetooth inquiry, a Bluetooth API implementation MUST report each discovered remote Bluetooth device only once. In other words, a Bluetooth API implementation MUST call the DiscoveryListener.deviceDiscovered() method only once for each individual discovered remote device.

Specified by:
deviceDiscovered in interface DiscoveryListener
Parameters:
btDevice - the device that was found during the inquiry
cod - - the service classes, major device class, and minor device class of the remote device
See Also:
DiscoveryAgent.startInquiry(int, javax.bluetooth.DiscoveryListener)

inquiryCompleted

public void inquiryCompleted(int discType)
Description copied from interface: DiscoveryListener
Called when an inquiry is completed. The discType will be DiscoveryListener.INQUIRY_COMPLETED if the inquiry ended normally or DiscoveryListener.INQUIRY_TERMINATED if the inquiry was canceled by a call to DiscoveryAgent.cancelInquiry(DiscoveryListener). The discType will be DiscoveryListener.INQUIRY_ERROR if an error occurred while processing the inquiry causing the inquiry to end abnormally.

Specified by:
inquiryCompleted in interface DiscoveryListener
Parameters:
discType - the type of request that was completed; either DiscoveryListener.INQUIRY_COMPLETED, DiscoveryListener.INQUIRY_TERMINATED, or DiscoveryListener.INQUIRY_ERROR
See Also:
DiscoveryListener.INQUIRY_COMPLETED, DiscoveryListener.INQUIRY_TERMINATED, DiscoveryListener.INQUIRY_ERROR

servicesDiscovered

public void servicesDiscovered(int transID,
                               ServiceRecord[] servRecord)
Description copied from interface: DiscoveryListener
Called when service(s) are found during a service search.

Specified by:
servicesDiscovered in interface DiscoveryListener
Parameters:
transID - the transaction ID of the service search that is posting the result
servRecord - a list of services found during the search request
See Also:
DiscoveryAgent.searchServices(int[], javax.bluetooth.UUID[], javax.bluetooth.RemoteDevice, javax.bluetooth.DiscoveryListener)

serviceSearchCompleted

public void serviceSearchCompleted(int transID,
                                   int respCode)
Description copied from interface: DiscoveryListener
Called when a service search is completed or was terminated because of an error. Legal status values in the respCode argument include DiscoveryListener.SERVICE_SEARCH_COMPLETED, DiscoveryListener.SERVICE_SEARCH_TERMINATED, DiscoveryListener.SERVICE_SEARCH_ERROR, DiscoveryListener.SERVICE_SEARCH_NO_RECORDS and DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE. The following table describes when each respCode will be used:
respCodeReason
DiscoveryListener.SERVICE_SEARCH_COMPLETED if the service search completed normally
DiscoveryListener.SERVICE_SEARCH_TERMINATED if the service search request was cancelled by a call to DiscoveryAgent.cancelServiceSearch(int)
DiscoveryListener.SERVICE_SEARCH_ERROR if an error occurred while processing the request
DiscoveryListener.SERVICE_SEARCH_NO_RECORDS if no records were found during the service search
DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE if the device specified in the search request could not be reached or the local device could not establish a connection to the remote device

Specified by:
serviceSearchCompleted in interface DiscoveryListener
Parameters:
transID - the transaction ID identifying the request which initiated the service search
respCode - the response code that indicates the status of the transaction

getOutputStream

public 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 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 String stripColons(String s)