发表于:2003-12-05 13:38:00
楼主
yoyo1101,谢谢你百忙中的答复,毫无疑问,你是我心眼里最可爱的人,
以至我都想以身相许,可惜我也是男人呀.
下面咱还要提提我的问题呢.
问题在我看来是解决了,程序源代码如下,不知道是不是对呢?
PCI-9114HG的multiple AD-Channels一起连续采集时,是怎样一个时序呢?
请结合以下程序给咱点拨点拨.
我在程序中设置Scan Rate为2000Hz(Per channel),即0.5ms;总采样频率为
2000Hz*32通道=64000Hz.
PCI-9114HG在采集时是不是每个扫描间隔(即每0.5ms)每道转换一个样点,
这样0至31通道都各得到一个样点(姑且称为一帧)?
道间切换的时差是多少呢,可以不用考虑吗?
程序中32个通道每个通道都采了16K个样点,那么总计花了多少时间呢,
该怎么计算?
还有,the size of circular AI-Buffer是多少?
AI_AsyncDblBufferHalfReady时即半满时,能读回来几个样点?
//以下是程序源代码:
//
// P9114AsyncCAI.cpp
//
//
// Before using this program,you must use the utility--
// "NuDAQ PCI Configuration Utility"--to allocate at least 256KBytes
// memory spaces for AI-Buffer.
//
// 32Channels*2048Samples*4Bytes(size of per sample) = 256KBytes
//
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "dask.h"
// PCI_9114HG : Continuous AI
//constants definition
#define CardNumber 0
#define ADChanCount 32
#define LastADChan (ADChanCount-1)
#define ScanCount 2048
#define SampleRate 64000.0000
//Scan Rate(Hz): 64000.0000/32 = 2K
//Sampling-Length per AD channel,in samples
#define SampLen 16384
//variables definition
I16 cardID = -1;
I16 err=0;
BOOLEAN fstop = 0;
BOOLEAN HalfReady = 0;
U32 AccessCnt = 0;
U32 MemSize = 0;
U32 InBuf[32*SampLen]; //AI data buffer
F64 vaiData[32*SampLen];//volt-value of AI data
//total numbers of current transferred samples
U32 CurSamples = 0;
int main(int argc, char* argv[])
{
FILE* fp;
int SampNo,ADChan;
char szLine[1024];
char szTmp[100];
fp = fopen("D:\\P9114AsyncCAI.TXT","w+t");
if(fp==NULL)
{
printf("not found file.\n");
exit(1);
}
cardID = Register_Card(PCI_9114HG, CardNumber);
if (cardID<0) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: Register_Card(). errcode=%d\n",cardID);
exit(1);
}
err = AI_InitialMemoryAllocated(cardID,&MemSize);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_InitialMemoryAllocated().\n");
exit(1);
}
else
printf("Ok : MemSize=%d KB!\n",MemSize);
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
printf("Error: AI-Buffer is too small!\n");
exit(1);
}
err = AI_AsyncDblBufferMode(cardID, 1);//enable double-buffer mode
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_AsyncDblBufferMode().errcode = %d\n",err);
exit(1);
}
err=AI_9114_Config(cardID, TRIG_INT_PACER);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_9114_Config().errcode=%d\n",err);
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
printf("Error: AI_ContScanChannels(). errcode = %d\n",err);
exit(1);
}
do {
do {
AI_AsyncDblBufferHalfReady (cardID, &HalfReady, &fstop);
} while (!HalfReady);
//half buffer data is ready for read
AI_AsyncDblBufferTransfer (cardID, &InBuf[CurSamples] );
CurSamples += ScanCount/2;
printf("CurSamples = %lu\n",CurSamples);
} while (CurSamples<ADChanCount*SampLen);
printf("sampling completed!\n");
err = AI_AsyncClear(cardID, &AccessCnt);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_AsyncClear().errcode=%d\n",err);
}
printf("Now converting the acquired data to volt values...\n");
err = AI_ContVScale(cardID,AD_B_10_V,InBuf,vaiData,ADChanCount*SampLen);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_C