字号:    

(转)研华数采卡编程(-)——数字IO基本操作

VC编程基本步骤

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

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

3、  开始编程

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

static      PT_DioWritePortByte ptDioWritePortByte; // DioWritePortByte table

static      PT_DioReadPortByte ptDioReadPortByte;

……

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

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

        if (ErrCde != SUCCESS)

        {

          打开板卡出错处理……

        }

3)  控制IO

读取端口状态:

ptDioReadPortByte.port = gwChannel;

              ptDioReadPortByte.value = (USHORT far *)&gwValue;

              if ((ErrCde = DRV_DioReadPortByte(DriverHandle,

                     (LPT_DioReadPortByte)&ptDioReadPortByte)) != 0)

              {

                     读出错处理……

}

       写入端口状态:

            ptDioWritePortByte.port  = m_iChannel;

         ptDioWritePortByte.mask  = 0xff;

         ptDioWritePortByte.state = m_ioData;

if((ErrCde = DRV_DioWritePortByte(DriverHandle,(LPT_DioWritePortByte)&ptDioWritePortByte)) != 0)

         {

             写出错处理……

         }

4)  关闭办卡

DRV_DeviceClose((LONG far *)&DriverHandle);

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