ThinkGear

Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class ThinkGear

    java.lang.Object
      ThinkGear

    public class ThinkGear

extends java.lang.Object

Field Summary
`static int` | `BAUD_115200`
`static int` | `BAUD_1200` Baud rate for use with Connect() and SetBaudrate().
`static int` | `BAUD_2400`
`static int` | `BAUD_4800`
`static int` | `BAUD_57600`
`static int` | `BAUD_9600`
`static int` | `DATA_ALPHA1`
`static int` | `DATA_ALPHA2`
`static int` | `DATA_ATTENTION`
`static int` | `DATA_BATTERY` Data type that can be requested from GetValue().
`static int` | `DATA_BETA1`
`static int` | `DATA_BETA2`
`static int` | `DATA_DELTA`
`static int` | `DATA_GAMMA1`
`static int` | `DATA_GAMMA2`
`static int` | `DATA_MEDITATION`
`static int` | `DATA_POOR_SIGNAL`
`static int` | `DATA_RAW`
`static int` | `DATA_THETA`
`static int` | `MAX_CONNECTION_HANDLES` Maximum number of Connections that can be requested before being required to free one.
`static int` | `STREAM_5VRAW`
`static int` | `STREAM_FILE_PACKETS`
`static int` | `STREAM_PACKETS` Data format for use with Connect() and SetDataFormat().

Method Summary
`static int` | `Connect(int connectionId, java.lang.String serialPortName, int serialBaudrate, int serialDataFormat)` Connects a ThinkGear Connection, given by `connectionId`, to a serial communication (COM) port in order to communicate with a ThinkGear module.
`static void` | `Disconnect(int connectionId)` Disconnects the ThinkGear Connection, given by `connectionId`, from its serial communication (COM) port.
`static void` | `FreeConnection(int connectionId)` Frees all memory associated with the given ThinkGear Connection.
`static int` | `GetDriverVersion()` Returns a number indicating the version of the ThinkGear Communications Driver (TGCD) library accessed by this API.
`static int` | `GetNewConnectionId()` Returns an ID handle (an int) to a newly-allocated ThinkGear Connection object.
`static double` | `GetValue(int connectionId, int dataType)` Returns the most recently read value of the given `dataType`, which is one of the DATA_* constants defined above.
`static int` | `GetValueStatus(int connectionId, int dataType)` Returns Non-zero if the `dataType` was updated by the most recent call to GetValue().
`static int` | `ReadPackets(int connectionId, int numPackets)` Attempts to use the ThinkGear Connection, given by `connectionId`, to read `numPackets` of data from the serial stream.
`static int` | `SendByte(int connectionId, int b)` Sends a byte through the ThinkGear Connection (presumably to a ThinkGear module).
`static int` | `SetBaudrate(int connectionId, int serialBaudrate)` Attempts to change the baud rate of the ThinkGear Connection, given by `connectionId`, to `serialBaudrate`.
`static int` | `SetDataFormat(int connectionId, int serialDataFormat)` Attempts to change the data Packet parsing format used by the ThinkGear Connection, given by `connectionId`, to `serialDataFormat`.
`static int` | `SetDataLog(int connectionId, java.lang.String filename)` As a ThinkGear Connection reads and parses Packets of data from its serial stream, it may log the parsed data into a log file.
`static int` | `SetStreamLog(int connectionId, java.lang.String filename)` As a ThinkGear Connection reads bytes from its serial stream, it may automatically log those bytes into a log file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MAX_CONNECTION_HANDLES

    public static final int MAX_CONNECTION_HANDLES

  Maximum number of Connections that can be requested before being required to free one.

  See Also:
    Constant Field Values

### BAUD_1200

    public static final int BAUD_1200

  Baud rate for use with Connect() and SetBaudrate().

  See Also:
    Constant Field Values

### BAUD_2400

    public static final int BAUD_2400

See Also:
  Constant Field Values

### BAUD_4800

    public static final int BAUD_4800

See Also:
  Constant Field Values

### BAUD_9600

    public static final int BAUD_9600

See Also:
  Constant Field Values

### BAUD_57600

    public static final int BAUD_57600

See Also:
  Constant Field Values

### BAUD_115200

    public static final int BAUD_115200

See Also:
  Constant Field Values

### STREAM_PACKETS

    public static final int STREAM_PACKETS

  Data format for use with Connect() and SetDataFormat().

  See Also:
    Constant Field Values

### STREAM_5VRAW

    public static final int STREAM_5VRAW

See Also:
  Constant Field Values

### STREAM_FILE_PACKETS

    public static final int STREAM_FILE_PACKETS

See Also:
  Constant Field Values

### DATA_BATTERY

    public static final int DATA_BATTERY

  Data type that can be requested from GetValue().

  See Also:
    Constant Field Values

### DATA_POOR_SIGNAL

    public static final int DATA_POOR_SIGNAL

See Also:
  Constant Field Values

### DATA_ATTENTION

    public static final int DATA_ATTENTION

See Also:
  Constant Field Values

### DATA_MEDITATION

    public static final int DATA_MEDITATION

See Also:
  Constant Field Values

### DATA_RAW

    public static final int DATA_RAW

See Also:
  Constant Field Values

### DATA_DELTA

    public static final int DATA_DELTA

See Also:
  Constant Field Values

### DATA_THETA

    public static final int DATA_THETA

See Also:
  Constant Field Values

### DATA_ALPHA1

    public static final int DATA_ALPHA1

See Also:
  Constant Field Values

### DATA_ALPHA2

    public static final int DATA_ALPHA2

See Also:
  Constant Field Values

### DATA_BETA1

    public static final int DATA_BETA1

See Also:
  Constant Field Values

### DATA_BETA2

    public static final int DATA_BETA2

See Also:
  Constant Field Values

### DATA_GAMMA1

    public static final int DATA_GAMMA1

See Also:
  Constant Field Values

### DATA_GAMMA2

    public static final int DATA_GAMMA2

See Also:
  Constant Field Values

Method Detail

### GetDriverVersion

    public static int GetDriverVersion()

  Returns a number indicating the version of the ThinkGear Communications Driver (TGCD) library accessed by this API. Useful for debugging version-related issues.

  Returns:
    The TGCD library's version number.

### GetNewConnectionId

    public static int GetNewConnectionId()

  Returns an ID handle (an int) to a newly-allocated ThinkGear Connection object. The Connection is used to perform all other operations of this API, so the ID handle is passed as the first argument to all functions of this API. When the ThinkGear Connection is no longer needed, be sure to call FreeConnection() on the ID handle to free its resources. No more than MAX_CONNECTION_HANDLES Connection handles may exist simultaneously without being freed.

  Returns:
    -1 if too many Connections have been created without being freed by FreeConnection().

### SetStreamLog

    public static int SetStreamLog(int connectionId,
                                   java.lang.String filename)

  As a ThinkGear Connection reads bytes from its serial stream, it may automatically log those bytes into a log file. This is useful primarily for debugging purposes. Calling this function with a valid `filename` will turn this feature on. Calling this function with an invalid `filename`, or with `filename` set to NULL, will turn this feature off. This function may be called at any time for either purpose on a ThinkGear Connection.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to enable stream logging for, as obtained from GetNewConnectionId().
    `filename` - The name of the file to use for stream logging. Any existing contents of the file will be erased. Set to NULL to disable stream logging by the ThinkGear Connection.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### SetDataLog

    public static int SetDataLog(int connectionId,
                                 java.lang.String filename)

  As a ThinkGear Connection reads and parses Packets of data from its serial stream, it may log the parsed data into a log file. This is useful primarily for debugging purposes. Calling this function with a valid `filename` will turn this feature on. Calling this function with an invalid `filename`, or with `filename` set to NULL, will turn this feature off. This function may be called at any time for either purpose on a ThinkGear Connection.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to enable data logging for, as obtained from GetNewConnectionId().
    `filename` - The name of the file to use for data logging. Any existing contents of the file will be erased. Set to NULL to disable stream logging by the ThinkGear Connection.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### Connect

    public static int Connect(int connectionId,
                              java.lang.String serialPortName,
                              int serialBaudrate,
                              int serialDataFormat)

  Connects a ThinkGear Connection, given by `connectionId`, to a serial communication (COM) port in order to communicate with a ThinkGear module. It is important to check the return value of this function before attempting to use the Connection further for other functions in this API.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to connect, as obtained from GetNewConnectionId().
    `serialPortName` - The name of the serial communication (COM) stream port. COM ports on PC Windows systems are named like '\\.\COM4' (remember that backslashes in strings in most programming languages need to be escaped), while COM ports on Windows Mobile systems are named like 'COM4:' (note the colon at the end). Linux COM ports may be named like '/dev/ttys0'. Refer to the documentation for your particular platform to determine the available COM port names on your system.
    `serialBaudrate` - The baudrate to use to attempt to communicate on the serial communication port. Select from one of the BAUD_* constants defined above, such as BAUD_9600 or BAUD_57600. BAUD_9600 is the typical default baud rate for standard ThinkGear modules.
    `serialDataFormat` - The type of ThinkGear data stream. Select from one of the STREAM_* constants defined above. Most applications should use STREAM_PACKETS (the data format for Embedded ThinkGear modules). STREAM_5VRAW is supported only for legacy non-embedded purposes.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### ReadPackets

    public static int ReadPackets(int connectionId,
                                  int numPackets)

  Attempts to use the ThinkGear Connection, given by `connectionId`, to read `numPackets` of data from the serial stream. The Connection will (internally) "remember" the most recent value it has seen of each possible ThinkGear data type, so that any subsequent call to `GetValue`() will return the most recently seen values. Set `numPackets` to -1 to attempt to read all Packets of data that may be currently available on the serial stream.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection which should read packets from its serial communication stream, as obtained from GetNewConnectionId().
    `numPackets` - The number of data Packets to attempt to read from the ThinkGear Connection. Only the most recently read value of each data type will be "remembered" by the ThinkGear Connection. Setting this parameter to -1 will attempt to read all currently available Packets that are on the data stream.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### GetValue

    public static double GetValue(int connectionId,
                                  int dataType)

  Returns the most recently read value of the given `dataType`, which is one of the DATA_* constants defined above. Use `ReadPackets`() to read more Packets in order to obtain updated values. Afterwards, use `GetValueStatus`() to check if a call to `ReadPackets`() actually updated a particular `dataType`. NOTE: This function will terminate the program with a message printed to stderr if `connectionId` is not a valid ThinkGear Connection, or if `dataType` is not a valid DATA_* constant.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to get a data value from, as obtained from GetNewConnectionId().
    `dataType` - The type of data value desired. Select from one of the DATA_* constants defined above. Refer to the documentation of each constant for details of how to interpret its value.
  Returns:
    The most recent value of the requested `dataType`.

### GetValueStatus

    public static int GetValueStatus(int connectionId,
                                     int dataType)

  Returns Non-zero if the `dataType` was updated by the most recent call to GetValue(). Returns 0 otherwise.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to get a data value from, as obtained from GetNewConnectionId().
    `dataType` - The type of data value desired. Select from one of the DATA_* constants defined above. NOTE: This function will terminate the program with a message printed to stderr if `connectionId` is not a valid ThinkGear Connection, or if `dataType` is not a valid DATA_* constant.
  Returns:
    Non-zero if the `dataType` was updated by the most recent call to GetValue(). Returns 0 otherwise.

### SendByte

    public static int SendByte(int connectionId,
                               int b)

  Sends a byte through the ThinkGear Connection (presumably to a ThinkGear module). This function is intended for advanced ThinkGear Command Byte operations. WARNING: Always make sure at least one valid Packet has been read (i.e. through the `ReadPackets`() function) at some point BEFORE calling this function. This is to ENSURE the Connection is communicating at the right baud rate. Sending Command Byte at the wrong baud rate may put a ThinkGear module into an indeterminate and inoperable state until it is reset by power cycling (turning it off and then on again). NOTE: After sending a Command Byte that changes a ThinkGear baud rate, you will need to call `SetBaudrate`() to change the baud rate of your `connectionId` as well. After such a baud rate change, it is important to check for a valid Packet to be received by `ReadPacket`() before attempting to send any other Command Bytes, for the same reasons as describe in the WARNING above.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to send a byte through, as obtained from GetNewConnectionId().
    `b` - The byte to send through. Note that only the lowest 8-bits of the value will actually be sent through.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### SetBaudrate

    public static int SetBaudrate(int connectionId,
                                  int serialBaudrate)

  Attempts to change the baud rate of the ThinkGear Connection, given by `connectionId`, to `serialBaudrate`. This function does not typically need to be called, except after calling `SendByte`() to send a Command Byte that changes the ThinkGear module's baud rate. See SendByte() for details and NOTE.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to send a byte through, as obtained from GetNewConnectionId().
    `serialBaudrate` - The baudrate to use to attempt to communicate on the serial communication port. Select from one of the BAUD_* constants defined above, such as BAUD_9600 or BAUD_57600. BAUD_9600 is the typical default baud rate for standard ThinkGear modules.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### SetDataFormat

    public static int SetDataFormat(int connectionId,
                                    int serialDataFormat)

  Attempts to change the data Packet parsing format used by the ThinkGear Connection, given by `connectionId`, to `serialDataFormat`. This function does not typically need to be called, and is provided only for special testing purposes.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to send a byte through, as obtained from GetNewConnectionId().
    `serialDataFormat` - The type of ThinkGear data stream. Select from one of the STREAM_* constants defined above. Most applications should use STREAM_PACKETS (the data format for Embedded ThinkGear modules). STREAM_5VRAW is supported only for legacy non-embedded purposes.
  Returns:
    -1 if `connectionId` does not refer to a valid ThinkGear Connection ID handle.

### Disconnect

    public static void Disconnect(int connectionId)

  Disconnects the ThinkGear Connection, given by `connectionId`, from its serial communication (COM) port. Note that after this call, the Connection will not be valid to use with any of the API functions that require a valid ThinkGear Connection, except SetStreamLog(), SetDataLog(), Connect(), and FreeConnection(). Note that FreeConnection() will automatically disconnect a Connection as well, so it is not necessary to call this function unless you wish to reuse the `connectionId` to call Connect() again.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to disconnect, as obtained from GetNewConnectionId().

### FreeConnection

    public static void FreeConnection(int connectionId)

  Frees all memory associated with the given ThinkGear Connection. Note that this function will automatically call Disconnect() to disconnect the Connection first, if appropriate, so that it is not necessary to explicitly call Disconnect() before calling this function, unless you wish to reuse the `connectionId` without freeing it first.

  Parameters:
    `connectionId` - The ID of the ThinkGear Connection to disconnect, as obtained from GetNewConnectionId().

Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD