lejos.pc.comm
Class NXTConnector

java.lang.Object
  extended by lejos.pc.comm.NXTCommLoggable
      extended by lejos.pc.comm.NXTConnector

public class NXTConnector
extends NXTCommLoggable

Connects to a NXT using Bluetooth or USB (or either) and supplies input and output data streams.

Author:
Lawrie Griffiths and Roger Glassey

Field Summary
 
Fields inherited from class lejos.pc.comm.NXTCommLoggable
fLogListeners
 
Constructor Summary
NXTConnector()
           
 
Method Summary
 void close()
          Close the connection
 boolean connectTo()
          Connect to any NXT over any protocol in NXTComm.PACKET mode
 boolean connectTo(int mode)
          Connect to any NXT over any protocol specifying mode
 boolean connectTo(NXTInfo nxtInfo, int mode)
          Connect to a NXT using a NXTInfo instance
 boolean connectTo(java.lang.String deviceURL)
          Connect to a device by URL in NXTComm.PACKET mode
 boolean connectTo(java.lang.String deviceURL, int mode)
          Connect to a device by URL
 boolean connectTo(java.lang.String nxt, java.lang.String addr, int protocols)
          Connect to a specified NXT in packet mode
 boolean connectTo(java.lang.String nxt, java.lang.String addr, int protocols, int mode)
          Connect to a NXT
 java.io.InputStream getInputStream()
           
 NXTComm getNXTComm()
           
 NXTInfo getNXTInfo()
           
 java.io.OutputStream getOutputStream()
           
 NXTInfo[] search(java.lang.String nxt, java.lang.String addr, int protocols)
          Search for one or more NXTs and return an array of NXTInfo instances for those found.
 void setDebug(boolean debug)
          Set debugging on or off
 
Methods inherited from class lejos.pc.comm.NXTCommLoggable
addLogListener, log, log, removeLogListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NXTConnector

public NXTConnector()
Method Detail

connectTo

public boolean connectTo()
Connect to any NXT over any protocol in NXTComm.PACKET mode

Returns:
true if the connection succeeded
See Also:
NXTComm.PACKET

connectTo

public boolean connectTo(int mode)
Connect to any NXT over any protocol specifying mode

Parameters:
mode - the NXTComm mode (NXTComm.PACKET, NXTComm.LCP, or NXTComm.RAW)
Returns:
true if the connection succeeded

connectTo

public boolean connectTo(java.lang.String nxt,
                         java.lang.String addr,
                         int protocols)
Connect to a specified NXT in packet mode

Parameters:
nxt - the name of the NXT to connect to or null for any
addr - the address of the NXT to connect to or null
protocols - the protocols to use: NXTCommFactory.ALL_PROTOCOLS, NXTCommFactory.BLUETOOTH, or NXTCommFactory.USB
Returns:
true if the connection succeeded

search

public NXTInfo[] search(java.lang.String nxt,
                        java.lang.String addr,
                        int protocols)
Search for one or more NXTs and return an array of NXTInfo instances for those found.

Parameters:
nxt - the name of the NXT to connect to or null for any
addr - the address of the NXT to connect to or null
protocols - the protocols to use: NXTCommFactory.ALL_PROTOCOLS, NXTCommFactory.BLUETOOTH, or NXTCommFactory.USB
Returns:
an array of NXTInfo instances for found NXTs

connectTo

public boolean connectTo(java.lang.String nxt,
                         java.lang.String addr,
                         int protocols,
                         int mode)
Connect to a NXT

Parameters:
nxt - the name of the NXT to connect to or null for any
addr - the address of the NXT to connect to or null
protocols - the protocols to use: NXTCommFactory.ALL_PROTOCOLS, NXTCommFactory.BLUETOOTH, or NXTCommFactory.USB
mode - the NXTComm mode (NXTComm.PACKET, NXTComm.LCP, or NXTComm.RAW)
Returns:
true if the connection succeeded

connectTo

public boolean connectTo(NXTInfo nxtInfo,
                         int mode)
Connect to a NXT using a NXTInfo instance

Parameters:
nxtInfo -
mode -
Returns:
true if the connection succeeded

connectTo

public boolean connectTo(java.lang.String deviceURL,
                         int mode)
Connect to a device by URL

Parameters:
deviceURL - i.e. btspp://[name], usb://[name]
mode - the mode (NXTComm.PACKET, NXTComm.LCP, or NXTComm.RAW)
Returns:
true if the connection succeeded

connectTo

public boolean connectTo(java.lang.String deviceURL)
Connect to a device by URL in NXTComm.PACKET mode

Parameters:
deviceURL - i.e. btspp://[name], usb://[name]
Returns:
true if the connection succeeded
See Also:
NXTComm.PACKET

getInputStream

public java.io.InputStream getInputStream()
Returns:
the InputStream for this connection;

getOutputStream

public java.io.OutputStream getOutputStream()
Returns:
the OutputStream for this connection;

getNXTInfo

public NXTInfo getNXTInfo()
Returns:
the NXTInfo for this connection

getNXTComm

public NXTComm getNXTComm()
Returns:
the NXTComm for this connection

close

public void close()
           throws java.io.IOException
Close the connection

Throws:
java.io.IOException

setDebug

public void setDebug(boolean debug)
Set debugging on or off

Parameters:
debug - true for on, false for off