Follow

Example 5: EEG Logger Demo

This example demonstrates how to extract live EEG data using the EmoEngineTM  in C++.  Data is read from the headset and sent to an output file for later analysis. Please note that this example only works with the SDK versions that allow raw EEG access (Research, Education and Enterprise Plus).

The example starts in the same manner as the earlier examples. A connection is made to the EmoEngine through a call to EE_EngineConnect(), or to XavierComposer through a call to EE_EngineRemoteConnect(). The EmoEngine event handlers and EmoState Buffer’s are also created as before.

Access to EEG measurements requires the creation of a DataHandle, a handle that is used to provide access to the underlying data. This handle is initialized with a call to EE_DataCreate(). During the measurement process, EmoEngine will maintain a data buffer of sampled data, measured in seconds. This data buffer must be initialized with a call to DataSetBufferSizeInSec(…), prior to collecting any data.

When the connection to EmoEngine is first made via EE_EngineConnect(), the engine will not have registered a valid user. The trigger for this registration is an EE_UserAdded event, which is raised shortly after the connection is made.  Once the user is registered, it is possible to enable data acquisition via a call to DataAcquisitionEnable.  With this enabled, EmoEngine will start collecting EEG for the user, storing it in the internal EmoEngine sample buffer. Note that the developer’s application should access the EEG data at a rate that will ensure the sample buffer is not overrun.

To initiate retrieval of the latest EEG buffered data, a call is made to DataUpdateHandle(). When this function is processed, EmoEngine will ready the latest buffered data for access via the hData handle. All data captured since the last call to DataUpdateHandle will be retrieved. Place a call to DataGetNumberOfSample() to establish how much buffered data is currently available. The number of samples can be used to set up a buffer for retrieval into your application as shown.

Finally, to transfer the data into a buffer in our application, we call the EE_DataGet function. To retrieve the buffer we need to choose from one of the available data channels:

ED_COUNTER,ED_AF3, ED_F7, ED_F3, ED_FC5, ED_T7,

ED_P7, ED_O1, ED_O2, ED_P8, ED_T8, ED_FC6, ED_F4,

ED_F8, ED_AF4, ED_GYROX, ED_GYROY, ED_TIMESTAMP,

ED_FUNC_ID, ED_FUNC_VALUE, ED_MARKER, ED_SYNC_SIGNAL

 

For example, to retrieve the first sample of data held in the sensor AF3, place a call to EE_DataGet as follows:

 

                        EE_DataGet(hData, ED_AF3, databuffer, 1);

 

You may retrieve all the samples held in the buffer using the bufferSizeInSample parameter.

Finally, we need to ensure correct clean up by disconnecting from the EmoEngine and free all associated memory.

EE_EngineDisconnect();

EE_EmoStateFree(eState);

EE_EmoEngineEventFree(eEvent);

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk