发表于:2003-11-21 16:59:00
楼主
我的困惑:
本人购得ADLINK一块PCI-9114HG采集板(16-bit resolution;32 S.E. or 16 D.I.)。
现要在Win98下用VC++ 6.0调用PCIS-DASK 4.0作32 S.E.采集程序.
要求0至31通道连续采集,每道的采样频率均为0.5ms,即2000Hz,每道的采样长度均为
16K samples.
请问该如何实现(不许用AI_ContScanChannelsToFile)?
采集回来的数据要放在自定义的缓冲区中.
以下是稍有修改的用PCIS-DASK Code Creator生成的代码,怎样在此基础上做出我要的程序?
请列位热心家Garylin,Yoyo1101,李侃,张斌,国安及其他大侠做答.
// P9114AsyncCAI.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "dask.h"
// PCI_9114HG : Continuous AI
/********************************************************
The following code segment is generated according to
your device setup. You can copy and insert it into
your program to operate your device.
********************************************************/
//constants definition
#define CardNumber 0
#define ADChanCount 32
#define LastADChan (ADChanCount-1)
#define ScanCount 512
#define SampleRate 64000.0000
//Scan Rate(Hz): 64000.0000/32 = 2K
//variables definition
I16 cardID = -1;
I16 err=0;
BOOLEAN fstop = 0;
BOOLEAN HalfReady = 0;
U32 AccessCnt = 0;
U32 MemSize = 0;
U32 InBuf[ADChanCount*ScanCount]; //AI data buffer
F64 vaiData[ADChanCount*ScanCount];
int main(int argc, char* argv[])
{
FILE* fp;
int i,j;
char szStr[1024];
char szTmp[100];
fp = fopen("D:\\P9114HGAsyncContAI.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(). CarID=%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);
}
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: no enough memory.\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().\n");
exit(1);
}
err=AI_9114_Config(cardID, TRIG_INT_PACER);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_9114_Config().\n");
exit(1);
}
err=AI_ContScanChannels (cardID, LastADChan, AD_B_10_V,
(U16 *)((U32 *)InBuf),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, (U16 *)((U32 *)InBuf) );
} while (!kbhit());
err = AI_AsyncClear(cardID, &AccessCnt);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_AsyncClear() failure!\n");
}
printf("Now begin write the acquired data to file\n");
err = AI_ContVScale(cardID,AD_B_10_V,InBuf,vaiData,
ScanCount*ADChanCount);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
printf("Error: AI_ContVScale() failure!\n");
}
fprintf(fp,"data of Ch#%02d---->Ch#%02d as follows.\n\0",0,LastADChan);
for(i=0;i<ScanCount;i++)
{
sprintf(szStr,"%lf ",vaiData[ADChanCount*i+0]);
for(j=1;j<ADChanCount;j++)
{
sprintf(szTmp,"%lf ",vaiData[ADChanCount*i+j]);
strcat(szStr,szTmp);