Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

why there's run time error while I'm using CWAI's start() and configure() in a worker thread of a dialog?

Below is part of my codes:

UINT ThermocoupleReadTemp(LPVOID pParam)
{
P3Dlg* pDlg = (P3Dlg*)pParam;

double AcquireRate;
int NumOfScan;
COleVariant upper = 0.01;
COleVariant lower = -0.01;
COleVariant vOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR);
CString channels;
CString temp;

pDlg->measureCJTemp();
temp.Format("CJTemp = %f",double(pDlg->getCJTemp()));
AfxMessageBox(temp, MB_OK | MB_ICONERROR);

AcquireRate = double(pDlg->getThermocoupleRate());
NumOfScan = 3;
pDlg->findMinMaxCh();
channels.Format("ob0!sc1!md1!%d:%d",pDlg->getMinCh(),pDlg->getMaxCh());

pDlg->getCWAI()->SetDevice(1);
pDlg->getCWAI()->GetChannels().Remo
veAll();
pDlg->getCWAI()->GetChannels().Add(channels,upper,lower,vOptional,vOptional);
//this SetNScans cause the graph to stop when dragging the window
pDlg->getCWAI()->SetNScans(NumOfScan);
pDlg->getCWAI()->GetScanClock().SetFrequency(AcquireRate * NumOfScan);
pDlg->getCWAI()->GetStopCondition().SetType(cwaiContinuous);
checker(pDlg->getCWAI()->Configure(),1); //problem!!!
checker(pDlg->getCWAI()->Start(),2);

return 0;
}
}


this is the function run in a worker thread, but I get run time errpr with that, the problem is with the configure() and start(). Can somebody tell me why? Thanks. By the way, I also wondering how to put the "return 0;" things, cos it can't run the start(), then end thread itself..
0 Kudos
Message 1 of 4
(3,154 Views)
Have you tried running your code from a single main thread? This would be a good technique for narrowing the issue you are experiencing, eliminating your settings from the threading issue.

You might also try just scanning one channel. Lets narrow the issue a little more to decide where to start.
0 Kudos
Message 2 of 4
(3,154 Views)
I have tried in a main thread, there's no prob at all, I've also tried with single channel, it just gave me runtime error.. sigh..

I now give it up and try to use lower level language to implement the thermocouple reading, got any idea how to do it without using CWAI?
0 Kudos
Message 3 of 4
(3,154 Views)
Check your other post for solution:

http://exchange.ni.com/servlet/Redirect?id=9045342
0 Kudos
Message 4 of 4
(3,154 Views)