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 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
 boolean connectTo(java.lang.String deviceURL)
          Connect to a device by URL in 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.DataInputStream getDataIn()
           
 java.io.DataOutputStream getDataOut()
           
 java.io.InputStream getInputStream()
           
 NXTComm getNXTComm()
           
 NXTInfo getNXTInfo()
           
 NXTInfo[] getNXTInfos()
           
 java.io.OutputStream getOutputStream()
           
 NXTInfo[] search(java.lang.String nxt, java.lang.String addr, int protocols)
          Search for a NXT
 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 PACKET mode

Returns:
0 true iff the open succeeded

connectTo

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

Parameters:
mode - the NXTComm mode (PACKET, LCP, or RAW)
Returns:
0 true iff the open 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
Returns:
true iff the open succeeded

search

public NXTInfo[] search(java.lang.String nxt,
                        java.lang.String addr,
                        int protocols)
Search for 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
Returns:
0 if opened successfully, -1 if failed, 1 if there is a list to choose from

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
Returns:
0 if opened successfully, -1 if failed, 1 if there is a list to choose from

connectTo

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

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

connectTo

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

Parameters:
deviceURL -
mode - the mode (NXTComm.LCP or NXTComm.PACKET)
Returns:
true iff the connection succeeded

connectTo

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

Parameters:
deviceURL -
Returns:
true iff the connection succeeded

getInputStream

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

getDataIn

public java.io.DataInputStream getDataIn()
Returns:
the DataInputStream for this connection;

getOutputStream

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

getDataOut

public java.io.DataOutputStream getDataOut()
Returns:
the DataOutputStream for this connection

getNXTInfo

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

getNXTInfos

public NXTInfo[] getNXTInfos()
Returns:
the array of NXTInfos 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