⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdaddma.c

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 ************************************************************************
 *  Program     : CDADDMA.C                                             *
 *  Description : Demo program for Windows with conditional DMA         *
 *                data transfer                                         *
 *  Revision    : 1.00                                                  *
 *  Date        : 12/10/1997                   Advantech Co., Ltd.      *
 ************************************************************************
 *
 * FUNCTIONS:
 *
 *   InitApplication() - Initializes window data and registers window class
 *
 *   InitInstance() - Saves instance handle and creates main window
 *
 *   MainWndProc() - Process main window messages
 *
 *   ShowDataDlgProc() - Process the dialog box messages for acquired data
 *
 *   DisplayDlgProc() - Process the dialog box messages for display range
 *
 *   ConfigDlgProc() - Process the dialog box messages for configuration
 *
 *   GainListDlgProc() - Process the dialog box messages for gain list
 *
 *   CondListDlgProc() - Process the dialog box messages for condition list
 *
 *   LevelListDlgProc() - Process the dialog box messages for gain list
 */


#include <windows.h>              /* required for all Windows applications */
#include <stdlib.h>
#include <windowsx.h>
#include <commdlg.h>
#include <dos.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "..\..\..\include\driver.h"
#include "..\..\..\include\os.h"
#include "resource.h"
#include "cdaddma.h"  // Yujie

// ------------------------------------------------------------------------
// GLOBAL VARIABLES
// ------------------------------------------------------------------------
HANDLE      hInst;                      // current instance
HWND        hWnd;                       // main window handle

static      DEVFEATURES        DevFeatures;       // structure for device features
static      PT_DeviceGetFeatures  ptDevFeatures;  // Devfeatures table
static      PT_FAIWatchdogConfig   ptFAIWatchdogConfig;    // FAIWatchdogConfig table
static      PT_FAIDmaWatchdogStart ptFAIDmaWatchdogStart;  // FAIDmaWatchdogStart table
static      PT_FAIWatchdogCheck    ptFAIWatchdogCheck;     // FAIWatcddogCheck table
static      PT_FAICheck    ptFAICheck;            // FAICheck table
static      PT_FAITransfer ptFAITransfer;         // FAITransfer table
static      PT_AllocateDMABuffer  ptAllocateDMABuffer;  // buffer table

static      PT_EnableEvent     ptEnableEvent;     // Enable event
static      PT_CheckEvent      ptCheckEvent;      // Check event
HANDLE      hEvent;
HANDLE      hThreadHandle;
DWORD       dwThreadID;

char        szErrMsg[80];               // Use for MESSAGEBOX function
char        szBuffer[40];               // Temperatory buffer
char        szDescript[100];            // Description device
char    *szStr, szDest[200], szTemp[50];
LRESULT     ErrCde;                     // Return error code

static  char far szCondString[5][15] = {"No-Condition",
                                        "Less","Between","Greater",
                                        "Outside"};
static  char far szAcqString[3][15] = {"Pre-Trig","Post-Trig","Position-Trig"};

static  USHORT gwGain[16] = {0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0};
static  USHORT gwGainCode;
static  USHORT gwGainCde[16];

static  USHORT gwCond[16] = {0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0};

static  USHORT gwCondition = 0;

static  TRIGLEVEL gfLevel[16] = {{0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},
                                 {0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},
                                 {0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},
                                 {0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f},{0.0f,0.0f}};
static  float fHiLevel = 0.0f;         // overall high level
static  float fLoLevel = 0.0f;        // overall low level

static  LONG   DriverHandle = (LONG)NULL; // driver handle
static  ULONG  dwDeviceNum;               // Device number
static  USHORT gwSelectDevice = FALSE;    // have never selected "Select Device" button

static  DWORD gdwPacerRate = 4000;           // pacer rate
static  ULONG gulConvNum = 4000;             // conversion number
static  USHORT gwStartChl = 0, gwNumChl = 1; // scan channels
static  USHORT gwDataType = 1;         // display type : FLOAT(1)
static  USHORT gwEvtFlag = 1;          // event enable(0)
static  USHORT gwGainList = 0;         // gain list flag
static  USHORT gwCondList = 0;         // condition list flag
static  USHORT gwLevelList = 0;        // level list flag
static  USHORT gwAcqMode = 1;          // acquisition mode index
static  ULONG  gdwStartPt = 0, gdwStopPt = 99;  // display points
static  USHORT gwExtTrig = 0;          // external or internal trigger
static  USHORT gwCyclicMode = 1;       // cyclic or non-cylic mode
static  USHORT gwBufferMode = 0;       // buffer: single or double
static  USHORT gwCyclicCount = 0;      // number of cyclic count
static  USHORT gwIntrCount = 1;
static  ULONG  gwActualBufSize = 0;               // actual allocate buffer size

static  USHORT gwActiveBuf = 0;     // return by FAICheck
static  USHORT gwOverrun   = 0;     // return by FAICheck, FAITransfer
static  USHORT gwStopped   = 0;     // return by FAICheck
static  ULONG gulRetrieved = 0;     // return by FAICheck
static  USHORT gwHalfReady = 0;     // return by FAICheck
static  USHORT gwTriggered = 0;     // return by FAIWatchdogCheck
static  USHORT gwTrigChan  = 0;     // return by FAIWatchdogCheck
static  ULONG gulTrigIndex = 0;		// return by FAIWatchdogCheck
static  USHORT gwTrigData  = 0;     // return by FAIWatchdogCheck
static  FLOAT  gfTrigData  = 0.0f;  // return by FAIWatchdogCheck
static  USHORT gwTerminateflag = 0; //terminate

HGLOBAL hUserBufA, hUserBufB;
LPVOID  hUserA, hUserB;

static  HWND hwndStopButton, hwndStatusButton;
static  HANDLE  hInstance ;
HMENU hMenu;
LONG pBuffer;

BOOL InitApplication(HANDLE hInstance);
BOOL InitInstance(HANDLE hInstance, int nCmdShow);
long FTYPE MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int  FTYPE WinMain(HANDLE hInstance, HANDLE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow);
static  FARPROC lpfnConfigDlgProc, lpfnShowDataDlgProc, lpfnDisplayDlgProc,
        lpfnGainListDlgProc, lpfnCondListDlgProc, lpfnLevelListDlgProc;

void UserThread();
void adInterruptEvent();
void adBufChangeEvent();
void adOverrunEvent();
void adWatchdogEvent();
void adTerminateEvent();

/***************************************************************************
    FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)

    PURPOSE: calls initialization function, processes message loop
****************************************************************************/

int FTYPE WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance;                          /* current instance             */
HANDLE hPrevInstance;                      /* previous instance            */
LPSTR lpCmdLine;                           /* command line                 */
int nCmdShow;                              /* show-window type (open/icon) */
{
    MSG msg;                               /* message                      */

    if (!hPrevInstance)                /* Other instances of app running?  */
      if (!InitApplication(hInstance)) /* Initialize shared things         */
          return (FALSE);              /* Exits if unable to initialize    */

    // Perform initializations that apply to a specific instance
    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    // Acquire and dispatch messages until a WM_QUIT message is received.
    while (GetMessage(&msg,      /* message structure                      */
        (HWND)NULL,                    /* handle of window receiving the message */
        (UINT)NULL,                    /* lowest message to examine              */
        (UINT)NULL))                   /* highest message to examine             */
    {
        TranslateMessage(&msg);  /* Translates virtual key codes           */
        DispatchMessage(&msg);   /* Dispatches message to window           */
    }
    return (msg.wParam);         /* Returns the value from PostQuitMessage */
}

/****************************************************************************
    FUNCTION: InitApplication(HANDLE)

    PURPOSE: Initializes window data and registers window class
****************************************************************************/

BOOL InitApplication(hInstance)
HANDLE hInstance;                            /* current instance           */
{
    WNDCLASS  wc;

    // Fill in window class structure with parameters that describe the
    // main window.
    wc.style = CS_HREDRAW | CS_VREDRAW; /* Class style(s).                 */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;  /* window process procedure    */
    wc.cbClsExtra = 0;                  /* No per-class extra data.        */
    wc.cbWndExtra = 0;                  /* No per-window extra data.       */
    wc.hInstance = hInstance;           /* Application that owns the class.*/
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "MyMenu";   /* Name of menu resource in .RC file.  */
    wc.lpszClassName = "MyClass";  /* Name used in call to CreateWindow. */

    // Register the window class and return success/failure code.
    return (RegisterClass(&wc));

}

/***************************************************************************
    FUNCTION:  InitInstance(HANDLE, int)

    PURPOSE:  Saves instance handle and creates main window
****************************************************************************/

BOOL InitInstance(hInstance, nCmdShow)
HANDLE          hInstance;          /* Current instance identifier.          */
int             nCmdShow;           /* Param for first ShowWindow() call.    */
{

    // Save the instance handle in static variable, which will be used in
    // many subsequence calls from this application to Windows.
    hInst = hInstance;

    // Create a main window for this application instance.
    hWnd = CreateWindow(
        "MyClass",                  /* See RegisterClass() call.           */
        "Advantech Driver Demo : Conditional DMA Data Transfer" ,
                                    /* Window title bar  */
        WS_OVERLAPPEDWINDOW,        /* Window style.                       */
        CW_USEDEFAULT,              /* Default horizontal position.        */
        CW_USEDEFAULT,              /* Default vertical position.          */
        CW_USEDEFAULT,              /* Default width.                      */
        CW_USEDEFAULT,              /* Default height.                     */
        NULL,                       /* Overlapped windows have no parent.  */
        NULL,                       /* Use the window class menu.          */
        hInstance,                  /* This instance owns this window.     */
        NULL                        /* Pointer not needed.                 */
        );

    // If window could not be created, return "failure"
    if (!hWnd)
        return (FALSE);

    // Make the window visible; update its client area; and return "success"

    ShowWindow(hWnd, nCmdShow);   /* Show the window                       */
    UpdateWindow(hWnd);           /* Sends WM_PAINT message                */
    return (TRUE);                /* Returns the value from PostQuitMessage*/
}

/***************************************************************************
    FUNCTION: GainListDlgProc(HWND, unsigned, WPARAM, LPARAM)

    PURPOSE:  Processes dialog box messages for gain list
****************************************************************************/

BOOL FTYPE GainListDlgProc(hDlg, message, wParam, lParam)
HWND hDlg;                                /* window handle                 */
unsigned message;                         /* type of message               */
WPARAM wParam;                            /* additional information        */
LPARAM lParam;                            /* additional information        */
{
    USHORT i, j, temp;

    switch (message)
    {
        case WM_INITDIALOG :

            // ------------------------------------------------------------
            // Initialize Input Range List Combobox, it needs to get device
            // features for gain list
            // ------------------------------------------------------------

            // Step 1: Open Device
            ErrCde = DRV_DeviceOpen(dwDeviceNum, (LONG far *)&DriverHandle);
            if (ErrCde != SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                return 0;
            }

            // Step 2: Get device features
            ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
            ptDevFeatures.size = sizeof(DEVFEATURES);
            if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
                (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return 0;
            }

            // Step 3: Initialize Input Range List Combobox with device features
            for (i = 0; i < 16; i ++)
                EnableWindow(GetDlgItem(hDlg, IDC_CHL0 + i), FALSE);

            if (DevFeatures.usNumGain != 0)
            {
                for(i = (USHORT)gwStartChl; i < (gwNumChl+gwStartChl); i ++)
                {
                    EnableWindow(GetDlgItem(hDlg, IDC_CHL0 + i), TRUE);
                    for(j = 0; j < (USHORT)DevFeatures.usNumGain; j ++)
                        SendDlgItemMessage(hDlg, IDC_CHL0+i, CB_ADDSTRING, 0,
                        (LPARAM)((LPSTR)(DevFeatures.glGainList[j].szGainStr)));

                    temp = gwGain[i];

                    SendDlgItemMessage(hDlg, IDC_CHL0+i,
                        CB_SELECTSTRING, (WPARAM)(-1),
                        (LPARAM)((LPSTR)(DevFeatures.glGainList[temp].szGainStr)));
                }
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -