发表于:2004-10-20 09:34:00
6楼
ljypp大侠:我是cvi新手,目前用LabWindows/cvi对凌华pci-9118编程。驱动程序装的是最新4.06版,我所用系统是PIII 500,windows xp,已经把驱动库文件PCI-DASK.dll和头文件DASK.h添加到工程文件中,代码参考pcis-dask code creator。
在调试程序时,编译已经通过,执行程序时,按动虚拟面板按钮,程序没有反应,查看变量,halfready总为0,跳不出do-while循环。我用卡自带的示例对卡作检测是正常的。我把源程序贴出来,请大侠百忙之中帮忙解决,感激不尽!祝工作愉快!
#include <windows.h>
#include "easyio.h"
#include <cvirte.h>
#include <userint.h>
#include "13.h"
#include "Dask.h"
//constants definition 用凌华pci-9118自己所带的code creator 自动生成的
#define CardNumber 0
#define ADChan 0
#define ScanCount 65536
#define SampleRate 8000.0000
//AI config constants definition
#define ModeCtrl P9118_AI_BiPolar|P9118_AI_SingEnded
#define FunCtrl P9118_AI_DtrgNegative|P9118_AI_EtrgNegative
#define BurstNumber 0
#define PostCount 0
//variables definition
I16 cardID = -1;
I16 err=0;
BOOLEAN HalfReady = 0;
BOOLEAN fstop;
U32 AccessCnt = 0;
U32 MemSize = 0;
U16 InBuf[65536]; //AI data buffer
static int panelHandle;
//CVI的主函数
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "13.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
//CVI面板上的数据采集按钮的回调函数,程序运行时按动该按钮,就驱动数采卡进行采集
int CVICALLBACK Start (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
cardID = Register_Card(PCI_9118DG, CardNumber);
if (cardID<0) {
//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(U16) ) {
//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, 1);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
err=AI_9118_Config(cardID, ModeCtrl, FunCtrl, BurstNumber, PostCount);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
err=AI_ContReadChannel (cardID, ADChan, AD_B_5_V, InBuf, ScanCount, SampleRate, ASYNCH_OP);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
do {
do {
AI_AsyncDblBufferHalfReady (cardID, &HalfReady, &fstop);
} while (!HalfReady); 调试程序时,问题出在该处,变量halfReady总为0,程序跳不出do-while循环
//half buffer data is ready for read
AI_AsyncDblBufferTransfer (cardID, InBuf);
} while (!fstop);
err = AI_AsyncClear(cardID, &AccessCnt);
if (err!=NoError) {
//Error occurs !!
//ToDo : Handle error here
}
Release_Card(cardID);
PlotY (panelHandle, PANEL_GRAPH, InBuf, 65536, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE,
VAL_SOLID, 1, VAL_RED);
break;
}
return 0;
}
//cvi 退出运行回调函数
int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}