发表于:2005-10-17 20:37:00
19楼
VC下用下面函数采集时,5路以下都可以,一但大于5路,就提示堆栈溢出?为什么?大虾指教
#define CardNumber 0
#define LastADChan 6
#define ADChanCount 7 //5路以下都可以
#define ScanCount 2048
#define SampleRate 7000.0000
#define SampLen 49152
//Sampling-Length per AD channel,in samples
F64 vaiData[ADChanCount*SampLen];//volt-value of AI data
I16 cardID = -1;
I16 err=0;
BOOLEAN fstop = 0;
BOOLEAN HalfReady = 0;
U32 AccessCnt = 0;
U32 MemSize = 0;
U32 InBuf[ADChanCount*SampLen]; //AI data buffer
U32 CurSamples = 0;//total numbers of current transferred samples
cardID = Register_Card(PCI_9114DG, CardNumber);
if (cardID<0) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: Register_Card(). CarID=%d",cardID);
AfxMessageBox(str);
exit(1);
}
err = AI_InitialMemoryAllocated(cardID,&MemSize);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: AI_InitialMemoryAllocated()");
AfxMessageBox(str);
exit(1);
}
if (MemSize*1024 < ScanCount*ADChanCount*sizeof(U32) ) {
//available memory size for analog input in the device driver
//is smaller than the data size specified!!
//ToDo : do something here
CString str;
str.Format("Error: AI_InitialMemoryAllocated()");
AfxMessageBox(str);
exit(1);
}
err = AI_AsyncDblBufferMode(cardID, 1);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: AI_AsyncDblBufferMode().errcode = %d",err);
AfxMessageBox(str);
exit(1);
}
err=AI_9114_Config(cardID, TRIG_INT_PACER);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: AI_9114_Config().errcode=%d",err);
AfxMessageBox(str);
exit(1);
}
err=AI_ContScanChannels (cardID, LastADChan, AD_B_10_V, NULL, ScanCount*ADChanCount, SampleRate, ASYNCH_OP);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: AI_ContScanChannels(). errcode = %d",err);
AfxMessageBox(str);
exit(1);
}
do {
do {
AI_AsyncDblBufferHalfReady (cardID, &HalfReady, &fstop);
} while (!HalfReady);
//half buffer data is ready for read
AI_AsyncDblBufferTransfer (cardID, (U16*)(&InBuf[CurSamples]));
CurSamples += ScanCount/2;}
//here to add the condition to continue the acquisition
while (CurSamples<ADChanCount*SampLen);
err = AI_AsyncClear(cardID, &AccessCnt);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: AI_AsyncClear().errcode=%d",err);
AfxMessageBox(str);
exit(1);
}
AfxMessageBox("sampling completed!");
err=AI_ContVScale(cardID,AD_B_10_V,InBuf,vaiData,ADChanCount*SampLen);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
CString str;
str.Format("Error: AI_ContVScale().errcode=%d",err);
AfxMessageBox(str);
exit(1);
}
Release_Card(cardID);