Using TGCD to get Raw Wave Values

Here are some pointers and explanations for how to use TGCD to get Raw Wave Values from the MindSet:

  1. You should always use TG_STREAM_PACKETS for TG_Connect(). TG_STREAM_5VRAW can only be used to parse data from a non-commercial headset. It won't do anything for a MindSet.

  2. To capture all the raw wave samples at 512Hz, you will need to use TG_ReadPackets() to poll fairly quickly and often (A new Packet should be arriving from the headset to the operating system every 1.95ms). It is possible to poll less frequently, since serial data is buffered by the operating system to a certain degree. You still need to poll quickly
    enough so that the operating system's buffer does not fill up and data is lost.

  3. To capture every raw wave sample, you want to call TG_ReadPackets(connectionId, 1 ). Note that we instruct it to read '1' packet, instead of '-1' (all available packets). Using '1', we can ensure that we look at every
    packet. With -1, only the most recently arrived value is available when you call TG_GetValue().

  4. After calling TG_ReadPackets(), you will want to check its return value (errCode). You should only attempt to process data if it returns 1, indicating that one Packet was successfully read. If no Packets were available to be read, you could Sleep() for 2 ms to save processor before trying again.

  5. If one Packet was successfully read in step 4., you should then call TG_GetValueStatus( connectionId, TG_DATA_RAW ) to check if a new raw wave value was included in the Packet. This is necessary because not every Packet contains a new raw wave value (for example, the Packet that arrives every 1s carrying the new Attention, Meditation, and signal quality values).

  6. If TG_GetValueStatus() indicates a new raw wave value arrived in step 5., you can then call TG_GetValue( connectionId, TG_DATA_RAW ) to get the new raw wave value. You can then print out that raw wave value, save it to a data structure, or write it to a log file immediately.

  7. It is recommended you perform steps 3. through 6. repeatedly, without Sleep(), until TG_ReadPackets() returns 0 in step 4. This ensures you consume all currently available Packets before sleeping.

The following is a new version of the thinkgear_testapp.c that illustrates the above points (It will be included in future releases of the MDT):

thinkgear_testraw.c