com.NeuroSky.ThinkGear.IO
Class Connection

java.lang.Object
  extended by com.NeuroSky.ThinkGear.IO.Connection
Direct Known Subclasses:
DummyConnection, HeadsetConnection

public abstract class Connection
extends java.lang.Object

This class defines an implementation of the ThinkGear driver. Both ThinkGear.Driver and ThinkGear.DummyDriver extend from this class, allowing a programmer to (possibly programmatically) swap between debug non-live code and live code by changing which driver type gets instantiated.


Constructor Summary
Connection()
           
 
Method Summary
abstract  boolean closeConnection()
          Closes the connection to the ThinkGear headset.
abstract  void flush()
          Flushes data in the output buffer directly to the headset.
abstract  boolean isConnected()
          Check whether the driver is connected to a ThinkGear headset.
abstract  boolean openConnection(java.lang.String deviceID)
          Open a connection to the ThinkGear headset using a unique device identifier.
abstract  boolean openConnection(java.lang.String deviceID, int channel)
          Open a connection to the ThinkGear headset using a unique device identifier and a channel number.
abstract  int read(byte[] byteArray)
          Reads data from the headset into a byte array reference passed in as a parameter.
abstract  void write(byte[] values, int off, int len)
          Writes a value to the headset.
abstract  void write(int value)
          Writes a value to the headset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection()
Method Detail

openConnection

public abstract boolean openConnection(java.lang.String deviceID)
                                throws java.io.IOException
Open a connection to the ThinkGear headset using a unique device identifier. The identifier takes the form of 12 hexadecimal digits with no delimiters. Implementations of this method assume that the serial IO communications are performed on channel 1.

Parameters:
deviceID - a 12-digit hexadecimal value representing the unique device identifier
Returns:
true if the connection attempt was successful, false otherwise
Throws:
java.io.IOException

openConnection

public abstract boolean openConnection(java.lang.String deviceID,
                                       int channel)
                                throws java.io.IOException
Open a connection to the ThinkGear headset using a unique device identifier and a channel number. The identifier takes the form of 12 hexadecimal digits with no delimiters.

Parameters:
deviceID - a 12-digit hexadecimal value representing the unique device identifier
channel - an integer representing the desired channel to connect on
Returns:
true if the connection attempt was successful, false otherwise
Throws:
java.io.IOException

closeConnection

public abstract boolean closeConnection()
                                 throws java.io.IOException
Closes the connection to the ThinkGear headset.

Returns:
true if the connection was successfully closed, false otherwise
Throws:
java.io.IOException

read

public abstract int read(byte[] byteArray)
                  throws java.io.IOException
Reads data from the headset into a byte array reference passed in as a parameter.

Parameters:
byteArray - the byte array that is to be written to
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException

write

public abstract void write(int value)
                    throws java.io.IOException
Writes a value to the headset.

Parameters:
values - the value to be written to the headset
Throws:
java.io.IOException

write

public abstract void write(byte[] values,
                           int off,
                           int len)
                    throws java.io.IOException
Writes a value to the headset.

Parameters:
values - the value to be written to the headset
Throws:
java.io.IOException

flush

public abstract void flush()
                    throws java.io.IOException
Flushes data in the output buffer directly to the headset. Use this after a write(int) to perform an immediate write.

Throws:
java.io.IOException

isConnected

public abstract boolean isConnected()
Check whether the driver is connected to a ThinkGear headset.

Returns:
true if the headset is connect, false otherwise.