zoukankan      html  css  js  c++  java
  • 在QT项目中添加对研华数采模块的支持

    一、正确安装研华数采模块管理程序Advantech Device Manager,并安装相应模块驱动。

      

    二、将C:\Program Files\Advantech\Adsapi路径(默认安装位置)下的IncludeLib文件夹复制到QT项目文件夹下。

      

    三、在代码中添加研华数采模块函数库头文件:

    #include "Include\Driver.h"

    并添加系统相关头文件:

    #include <windef.h>

    #include <stdio.h>

     

    四、在pro文件中添加研华数采模块函数库文件。

    HEADERS += Include/Driver.h

    LIBS += Lib/Adsapi32.lib

     

    五、基本代码:

    1、打开驱动

        DWORD  dwErrCde = DRV_DeviceOpen(0, &lDriverHandle);

        if (dwErrCde != SUCCESS) {

            qDebug() << "dwErrCde = " << dwErrCde;

            exit(1);

        }

    2、读取IO输入数字量

        PT_DioReadPortWord m_ptDioReadPortWord;

        USHORT m_ValidMask = 0;

        USHORT m_DiValue = 0;

        m_ptDioReadPortWord.port = 0;

        m_ptDioReadPortWord.ValidChannelMask = ( USHORT far * )&m_ValidMask;

        m_ptDioReadPortWord.value = ( USHORT far * )&m_DiValue;

        LRESULT m_ErrCde = DRV_DioReadPortWord( lDriverHandle, (LPT_DioReadPortWord)&m_ptDioReadPortWord);

        if (m_ErrCde != SUCCESS) {

            qDebug() << "m_ErrCde = " << m_ErrCde;

            exit(1);

        }

     

    3、输出IO数字量

            PT_DioWriteBit ptDioWriteBit;

            ptDioWriteBit.port  = 0;  // output port: 0

            ptDioWriteBit.bit   = 0;  // output channel: 0

            ptDioWriteBit.state = !(tmp_bit & current_dataOut); // output state

            ///*

            DWORD dwErrCde = DRV_DioWriteBit(lDriverHandle, (LPT_DioWriteBit)&ptDioWriteBit);

            if (dwErrCde != SUCCESS) {

                qDebug() << "dwErrCde = " << dwErrCde;

                exit(1);

            } //*/

    4、关闭驱动

        DWORD dwErrCde = DRV_DeviceClose(&lDriverHandle);

        if (dwErrCde != SUCCESS) {

            qDebug() << "dwErrCde = " << dwErrCde;

            exit(1);

    }

    5、更多使用方法请参照使用手册及相关例程。

  • 相关阅读:
    Windows Phone 7 Ti“.NET研究”ps (1) 狼人:
    Eclipse开发Android应用程序入“.NET研究”门:重装上阵 狼人:
    Android UI基本测验“.NET研究”:线性布局 狼人:
    “.NET研究”Eclipse开发Android应用程序入门 狼人:
    Window“.NET研究”s Phone 7 Tips (2) 狼人:
    文件位置修改strurs2中struts.xml文件的位置
    方法类struts2环境搭建
    平台程序微信平台开发应用的签名
    节点数据TYVJ P1742 [NOI2005]维护序列
    版本编译器Unsupported major.minor version 51.0
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3071994.html
Copyright © 2011-2022 走看看