字号:    

研华数采卡编程(二)——模拟量采集基本操作

1、  创建工程并添加库文件Adsapi32.lib(研华驱动提供)到工程中

2、  包含头文件,最直接的办法——拷贝所需头文件到当前工作文件夹;也可以在VC编译环境中的项目属性里面设置增加Include路径。

3、  开始编程

1)  添加所需变量:最简单的方法——直接从研华例程的文件里拷贝到自己的文件中。

static      DEVFEATURES     DevFeatures;    // structure for device features

static      PT_AIConfig     ptAIConfig;     // structure for AIConfig table

static      PT_AIVoltageIn  ptAIVoltageIn;  // structure for AIVoltageIn table

……

2)  打开办卡,如果只安装了一块卡片,可以直接根据DeviceManager中的数字操作板卡,如这里DRV_DeviceOpen函数中的0。

          ErrCde = DRV_DeviceOpen(0,(LONG far *)&DriverHandle);

        if (ErrCde != SUCCESS)

        {打开板卡出错处理……}

3)  控制IO

// get gain code

     ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;

     ptDevFeatures.size = sizeof(DEVFEATURES);

     if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,

                   (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)

     {出错处理……}

     // configures the gain for the specifed analog input channel

     ptAIConfig.DasGain = DevFeatures.glGainList[gwGain].usGainCde;

     ptAIConfig.DasChan = gwChannel;

     if ((ErrCde = DRV_AIConfig(DriverHandle,(LPT_AIConfig)&ptAIConfig)) != 0)

     {出错处理……}

    // reads an analog input channel

    ptAIVoltageIn.chan = gwChannel;

    ptAIVoltageIn.gain = ptAIConfig.DasGain;

    ptAIVoltageIn.TrigMode = 0;               // internal trigger

ptAIVoltageIn.voltage = (FLOAT far *)&fVoltage;

// Read voltage from the

if ((ErrCde = DRV_AIVoltageIn(DriverHandle,

(LPT_AIVoltageIn)&ptAIVoltageIn)) != 0)

    {出错处理……}

4)  关闭办卡

DRV_DeviceClose((LONG far *)&DriverHandle);

分类:技术笔记
?次阅读
 2008-01-07 19:03