01-16-2009 11:03 PM
Hi,
I am currently having a problem with reading two analog inputs from my NI 6008 device simultaenously in my visual C++ application. I currently have two threads, where each thread contains the create task, create channel and read functions for an input channel. However, when i run the application only one read function retrieves the correct values from the device and the other recieves completely random values (off to infinity).
Hope some can help.
Thanks.
James.
The below is an example of one of the threads, the other is almost the same.
//DC Thread
UINT DC_Work(LPVOID pParam)
{
CDialog* dlgPtr1 = static_cast<CDialog*>(pParam);
DAQmxCreateTask("DC_Task",&taskHandle_2);
DAQmxCreateAIVoltageChan(taskHandle_2,chan_2,"DC_Channel",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL);
DAQmxStartTask(taskHandle_2);
//Create File with filename Date.txt
DWORD wmWritten;
DC_File = CreateFile(DC_file,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
char str[10];
//Data Variables
float64 DC_data[bufferSize];
while(runThread == true)
{
//Computes Yaw Value
DAQmxReadAnalogF64(taskHandle_2,pointsToRead_1,timeout,DAQmx_Val_GroupByChannel, DC_data,samplesPerChan,&pointsRead_1,NULL);
double a = DC_data[0];
int aa = (int)(a*1000);
//Print Yaw Value to File
sprintf_s(str,"%1.2f",a);
WriteFile(DC_File,str,(DWORD)(4),&wmWritten,NULL);
WriteFile(DC_File,"\r\n",(DWORD)(2),&wmWritten,NULL);
//Send and sleep
Sleep(100);
::SendMessage(dlgPtr1->GetSafeHwnd(), WM_DCMESSAGE, aa,0);
}
return 0;
}
01-18-2009 01:24 PM
01-19-2009 12:47 AM
Thanks for your help. Although being new to the function of NI DAQmx, how would I do that? Say for example I had two different analog inputs into my device, and I would like to take one sample of them both at the same time then read the values of independently of course.
So I'd create one task and two Analog input voltage channels? Then call two Read functions?
Thanks again.
01-19-2009 03:11 AM
Ok it doesn't matter I worked it all out. My answer was deep in the C Help library.
Thanks for you help anyway!