We are developing an application using multiple USB Ni-DAQ devices. Our application needs to collect analog data from 16 channels. Currently, we are using two USB DAQ devices, each with 8 analog input channels. We are able to successfully retrieve data from one USB DAQ, but we are encountering synchronization issues when attempting to synchronize the two devices.
The application is being developed in VC++. We would greatly appreciate any assistance in resolving this problem. Below is a sample code for single DAQ :
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
/////////////////////////////////////////////////////////////////////////////
// Initialize NI's DAQ-AD board
// BOOL NIADBord Init (void)
// No arguments
// Return value BOOL FALSE Abnormal
// TRUE Normal
BOOL CBordInfTask::NIADBordInit(void)
{
BOOL bDAQAdResult = FALSE;
//////////////////////////////////////////////////////////////////////////////////////
// Initialize the device driver of the NI-DAQ AD boad
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DWORD dwEventCnt = GetSampleCount(); // Acquire the number of samples by sample frequency
// Task setting
int iDAQADErrTaskCreate = DAQmxCreateTask( "AdTask", // The name of the task (may be changed internally)
&g_hDAQADTask ) ; // Task handle
// Source settings
int iDAQADErrAIVol = DAQmxCreateAIVoltageChan( g_hDAQADTask, // Task handle"Dev1/ai0:6", "",DAQmx_Val_RSE,
-10.0, // Lowest input
10.0, // Highest input
DAQmx_Val_Volts, // Unit (V)
NULL); // Unit customization
// Sampling settings
int iDAQADCfgSample = DAQmxCfgSampClkTiming(g_hDAQADTask, "", 1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps, 1000);
int iDAQADEveryNSample = DAQmxRegisterEveryNSamplesEvent(g_hDAQADTask,DAQmx_Val_Acquired_Into_Buffer,
dwEventCnt,
0,
EveryNCallback,
NULL);
// Function to call back when CALL DAQmx Stop Task
int iDAQADRegisterDone = DAQmxRegisterDoneEvent(g_hDAQADTask, 0,
DoneCallback,
NULL);
// DAQ AD card error
if ((DAQmxFailed(iDAQADErrTaskCreate) != 0)
|| (DAQmxFailed(iDAQADErrAIVol) != 0)
|| (DAQmxFailed(iDAQADCfgSample) != 0)
|| (DAQmxFailed(iDAQADEveryNSample) != 0)
|| (DAQmxFailed(iDAQADRegisterDone) != 0)) {
// BYTE errBuff[2048] = { '\0' } ;
// DAQmxGetExtendedErrorInfo( (char*)errBuff, 2048 ) ;
// TRACE( (char *)errBuff ) ;
bDAQAdResult = FALSE;
}
else {
bDAQAdResult = TRUE;
}
if (bDAQAdResult == TRUE) {
bDAQAdResult = LogFileOpen();
if (bDAQAdResult == FALSE) {
SetAlarm(eBORD_LOGOPENERR, 4000); // Open error
bDAQAdResult = FALSE;
}
else {
g_dwComplete100usCounter = 0;
////////////////////////////////////////////////////////////////////
// DAQ card driver startup
/*********************************************/
// DAQmx Start Code
/*********************************************/
int iDAQADStart = DAQmxStartTask(g_hDAQADTask);
if (DAQmxFailed(iDAQADStart) != 0) {
// BYTE errBuff[2048] = { '\0' } ;
// DAQmxGetExtendedErrorInfo( (char*)errBuff, 2048 ) ;
// TRACE( (char *)errBuff ) ;
SetAlarm(eDAQ_ADCARD_ERR, 4010); // DAQAD error
bDAQAdResult = FALSE;
}
else {
bDAQAdResult = TRUE;
}
}
}
else { // No processing
}
return(bDAQAdResult);
}