Using Callback functions in cbSDK

Callback functions allow data to be read into cbsdk and processed with several sample latency instead of 10ms binning of data.
Callback functions exist for the following data packet types, Most likely you will be interested in Spike, Digital input, Serial, or Continuous


CBSDKCALLBACK_ALL = 0, ///< Monitor all events
CBSDKCALLBACK_INSTINFO, ///< Monitor instrument connection information
CBSDKCALLBACK_SPIKE, ///< Monitor spike events
CBSDKCALLBACK_DIGITAL, ///< Monitor digital input events
CBSDKCALLBACK_SERIAL, ///< Monitor serial input events
CBSDKCALLBACK_CONTINUOUS, ///< Monitor continuous events
CBSDKCALLBACK_TRACKING, ///< Monitor video tracking events
CBSDKCALLBACK_COMMENT, ///< Monitor comment or custom events
CBSDKCALLBACK_GROUPINFO, ///< Monitor channel group info events
CBSDKCALLBACK_CHANINFO, ///< Monitor channel info events
CBSDKCALLBACK_FILECFG, ///< Monitor file config events
CBSDKCALLBACK_POLL, ///< respond to poll
CBSDKCALLBACK_SYNCH, ///< Monitor video synchronizarion events
CBSDKCALLBACK_NM, ///< Monitor NeuroMotive events
CBSDKCALLBACK_CCF, ///< Monitor CCF events
CBSDKCALLBACK_IMPEDENCE, ///< Monitor impedence events
CBSDKCALLBACK_SYSHEARTBEAT, ///< Monitor system heartbeats (100 times a second)
CBSDKCALLBACK_LOG, ///< Monitor system heartbeats (100 times a second)
CBSDKCALLBACK_COUNT ///< Always the last value


1. connect the the NSP as usual
2. define your callback function, the code in this function will execute whenever a data packet of the specified type is received. Make sure it is fast enough to complete execution before a new data packet arrives
void Your_Callback_Function(UINT32 nInstance, const cbSdkPktType type, const void* pEventData, void* pCallbackData) {}
3. In the main thread, register the callback function to let it start executing.
cbSdkRegisterCallback(nInstance, CBSDKCALLBACK_TYPE, (cbSdkCallback)Your_Callback_Function, pCallbackData);
4. The code in Callback_function will now run every time a data packet is received. Your main thread can be set to sleep and let the callback run, or your main thread can be executing other functions or running it's own code
5. in the main thread, un-register your callback function to stop executing it
cbSdkUnRegisterCallback(nInstance, CBSDKCALLBACK_TYPE);

See the attached example for a simple raw continuous data extraction and save.
Creation date: 10/10/2018 10:54 AM Greg Palis      Updated: 10/10/2018 10:54 AM Greg Palis
Files
Raw_Callback_Example10_10_18.cpp