You can pass a reference to the dialog class into your thread and manipulate the graph that way. The following snippet demonstrates one way of doing this using the DAQmx C API
UINT CDAQMTExampleDlg::AcquisitionThread(void* pParam)
{
CDAQMTExampleDlg* pDlg = static_cast < CDAQMTExampleDlg* >(pParam);
double data[1000];
int32 read;
int error;
if( (pParam != NULL) && pDlg->IsKindOf(RUNTIME_CLASS(CDAQMTExampleDlg)))
{
CoInitialize(NULL);
TaskHandle taskHandle = pDlg->taskHandle;
CNiReal64Vector vectorData(1000);
double *pvectorData = (double*)vectorData;
while(!pDlg->stopTask)
{
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,pvectorData,1000,&read,NULL));
pDlg->m_Graph.PlotY(vectorData);
}
Error:
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
pDlg->stopTask = true;
CoUninitialize();
}
return 0;
}
void CDAQMTExampleDlg::OnBnClickedButton1()
{
int error;
DAQmxErrChk(DAQmxCreateTask("",&taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk(DAQmxStartTask(taskHandle));
stopTask = false;
AfxBeginThread(AcquisitionThread, this);
return;
Error:
char errBuff[2048]={'\0'};
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
/*/ DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
}
void CDAQMTExampleDlg::OnBnClickedButton2()
{
stopTask = true;
}
I also wanted to make sure that you know that if you have Measurement Studio 7.x, you have access to a C++ DAQmx API. You can find examples of that API under ..\MeasurementStudio\VCNET\Examples\DAQmx. The C++ API provides asynchronous methods, which means that aquisition worker threads are automatically created for you in the background instead of you having to create them yourself. Plus the C++ DAQmx API provides error handling via exceptions and is designed for use with MFC.
I hope this helps
Bilal Durrani
NI