|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.pc.comm.NXTCommBluecove
public class NXTCommBluecove
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(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 |
---|
public NXTCommBluecove()
Method Detail |
---|
public NXTInfo[] search(String name, int protocol) throws NXTCommException
NXTComm
search
in interface NXTComm
name
- name of the NXT or nullprotocol
- bitwise combination of NXTCommFactory.BLUETOOTH and NXTCommFactory.USB
NXTCommException
public boolean open(NXTInfo nxt, int mode) throws NXTCommException
NXTComm
open
in interface NXTComm
nxt
- the NXTInfo object for the NXTmode
- the mode for the connection
NXTCommException
public boolean open(NXTInfo nxt) throws NXTCommException
NXTComm
open
in interface NXTComm
nxt
- the NXTInfo object for the NXT
NXTCommException
public void close() throws IOException
NXTCommRequest
close
in interface NXTCommRequest
IOException
public byte[] sendRequest(byte[] message, int replyLen) throws IOException
sendRequest
in interface NXTCommRequest
message
- Data to send.replyLen
- the reply length expected
IOException
public byte[] read() throws IOException
NXTComm
read
in interface NXTComm
IOException
public int available() throws IOException
NXTComm
available
in interface NXTComm
IOException
public void write(byte[] data) throws IOException
NXTComm
write
in interface NXTComm
data
- the data to be written.
Used for stream connections.
IOException
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
DiscoveryListener
DiscoveryListener.deviceDiscovered()
method only once for each
individual discovered remote device.
deviceDiscovered
in interface DiscoveryListener
btDevice
- the device that was found during the inquirycod
- - the service classes, major device class, and minor device
class of the remote deviceDiscoveryAgent.startInquiry(int, javax.bluetooth.DiscoveryListener)
public void inquiryCompleted(int discType)
DiscoveryListener
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.
inquiryCompleted
in interface DiscoveryListener
discType
- the type of request that was completed; either
DiscoveryListener.INQUIRY_COMPLETED
, DiscoveryListener.INQUIRY_TERMINATED
,
or DiscoveryListener.INQUIRY_ERROR
DiscoveryListener.INQUIRY_COMPLETED
,
DiscoveryListener.INQUIRY_TERMINATED
,
DiscoveryListener.INQUIRY_ERROR
public void servicesDiscovered(int transID, ServiceRecord[] servRecord)
DiscoveryListener
servicesDiscovered
in interface DiscoveryListener
transID
- the transaction ID of the service search that is posting the
resultservRecord
- a list of services found during the search requestDiscoveryAgent.searchServices(int[], javax.bluetooth.UUID[],
javax.bluetooth.RemoteDevice, javax.bluetooth.DiscoveryListener)
public void serviceSearchCompleted(int transID, int respCode)
DiscoveryListener
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:
respCode | Reason |
---|---|
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 |
serviceSearchCompleted
in interface DiscoveryListener
transID
- the transaction ID identifying the request which
initiated the service searchrespCode
- the response code that indicates the status of the transactionpublic OutputStream getOutputStream()
NXTComm
getOutputStream
in interface NXTComm
public InputStream getInputStream()
NXTComm
getInputStream
in interface NXTComm
public String stripColons(String s)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |