发表于:2005-07-31 11:25:00
楼主
问题很急,早晨发了这个帖子,在论坛里没看到,重发一下。
各位老师:你们好!我现在在用ADLINK PCI9812进行数据采集,我有个问题希望能到老师们的解惑。我用matlab和c++实现了对第一个通道的数据采集,但我希望能实现单独对第二个通道的数据采集。我用的是XP SP2系统,下面是我的程序,可是就是不能采集数据,请老师们帮看看问题出在哪,非常感谢。
/* $Revision: 1.1 $ */
// mexSample.cpp
// Automatically generated by Matlab AppWizard version 1.0
//
// This is the gateway routine for a MATLAB Math/Graphics Library-based
// C MATLAB MEX File.
#include "afx.h"
#include "mex.h"
#include "math.h"
#include "dask.h"
#include "DAQHeader.h"
int StartSample(U32 ScanCount,F32 SampleRate,double *dpDataOut);
void mexFunction(
int nlhs, // Number of left hand side (output) arguments
mxArray *plhs[], // Array of left hand side arguments
int nrhs, // Number of right hand side (input) arguments
const mxArray *prhs[] // Array of right hand side arguments
)
{
U32 ScanCount;
F32 SampleRate;
long nResult;
double dResult,*dpDataOut=NULL;
if(nrhs!=2) mexErrMsgTxt("Only two input argument is allowed.");
else if(nlhs>2) mexErrMsgTxt("Only two output argument is allowed.");
ScanCount=(long)mxGetScalar(prhs[0]);
SampleRate=*(mxGetPr(prhs[1]));
//dpDataOut=(double *)mxCalloc(nDataNum, sizeof(double));
plhs[0]=mxCreateDoubleMatrix(ScanCount,1,mxREAL);
dpDataOut=mxGetPr(plhs[0]);
nResult=StartSample(ScanCount,SampleRate,dpDataOut);
dResult=nResult;
plhs[1]=mxCreateScalarDouble(dResult);
return;
}
//constants definition
#define CardNumber 0
#define ADChan 0
//AI config constants definition
#define ClkSel P9812_AD2_GT_PCI|P9812_CLKSRC_INT
#define TriggerLevel 127
#define PostCount 0
int StartSample(U32 ScanCount, F32 SampleRate, double *dpDataOut)
{
I16 cardID = -1;
I16 err=0;
U32 AccessCnt = 0;
U32 MemSize = 0;
U16 InBuf[65536]; //AI data buffer
F64 InVolBuf[65536]; // AI voltages buffer
U32 i;
cardID = Register_Card(PCI_9812, CardNumber);
if (cardID<0) {
return -1;
//Error occurs !!
//ToDo : Handle error here
}
err = AI_InitialMemoryAllocated(cardID,&MemSize);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
if (MemSize*1024 < ScanCount*sizeof(I16) ) {
//available memory size for analog input in the device driver
//is smaller than the data size specified!!
//ToDo : do something here
}
err = AI_AsyncDblBufferMode(cardID, 0);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
err=AI_9812_Config(cardID, P9812_TRGMOD_SOFT, P9812_TRGSRC_CH1, P9812_TRGSLP_POS, ClkSel, TriggerLevel, PostCount);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
err=AI_ContReadChannel (cardID, ADChan, AD_B_1_V, InBuf, ScanCount, SampleRate, SYNCH_OP);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
err=AI_ContVScale (cardID, AD_B_1_V, InBuf, InVolBuf, ScanCount);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
for (i=0;i<ScanCount;i++)
{
dpDataOut[i]=InVolBuf[i];
}
//Release_Card(cardID);
return 0;
}
各位老师,采用单独的不同通道,是否就是将下面的函数中的P9812_TRGSRC_CH1参数进行修改就行了:
err=AI_9812_Config(cardID, P9812_TRGMOD_SOFT, P9812_TRGSRC_CH1, P9812_TRGSLP_POS, ClkSel, TriggerLevel, PostCount)。