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

📄 wdadmabm.c

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
 ************************************************************************
 *  Program     : DADMA.C                                               *
 *  Description : Demo program for Windows with 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
 *
 *   ConfigDlgProc() - Process the dialog box messages for configuration
 *
 *   WaveDlgProc() - Process the dialog box messages for waveform setting
 */


#include <windows.h>              /* required for all Windows applications */
#include <stdlib.h>
#include <windowsx.h>
#include <commdlg.h>
#include <string.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 "WDaDmaBM.h"

typedef struct {
    int wWaveform;
    float fMagnitude;
    float fOffset;
    int wPeriod;
} SWAVE, FAR *LPSWAVE;

// ------------------------------------------------------------------------
// 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_FAOWaveFormStart     ptFAOWaveFormStart;     // FAODMAStart table
static      PT_FAOScale        ptFAOScale;        // FAOScale table
static      PT_EnableEvent     ptEnableEvent;     // Enable event
static      PT_CheckEvent      ptCheckEvent;      // Check event
static		PT_FAOCheck		   ptFAOCheck;


static  USHORT gwActiveBuf = 0;     // return by FAOCheck
static  USHORT gwOverrun   = 0;     // return by FAOCheck
static  USHORT gwStopped   = 0;     // return by FAOCheck
static  ULONG  ulCurrentCount = 0;     // return by FAOCheck
static  USHORT gwHalfReady = 0;     // return by FAOCheck

HANDLE      hEvent;
HANDLE      hThreadHandle;
DWORD       dwThreadID;
BOOL        bThreadloop = FALSE;
BOOL        bThreadflag = FALSE;

char        szErrMsg[80];               // Use for MESSAGEBOX function
char        szBuffer[40];               // Temperatory buffer
char        szDescript[100];            // Description device
LRESULT     ErrCde;                     // Return error code

static  char far szWaveform[5][15] = {"SINE","TRIANGLE","SQUARE","SINETRIANGLE","None"};

static  LONG   DriverHandle = (LONG)NULL;         // driver handle
static  ULONG  dwDeviceNum;                       // Device number
static  USHORT gwSelectDevice = FALSE;  // have never selected "Select Device" button
static  USHORT gwDevice = 0;            // device index
static  DWORD  gdwPacerRate = 10000;    // pacer rate
static  ULONG  gulConvNum = 2048;      // conversion number
static  ULONG gwWaveFormCount = 30;  // scan channels
static  USHORT gwExtTrig = 0;           // external or internal trigger
static  USHORT gwCyclicMode = 1;        // cyclic or non-cylic mode
static  USHORT gwEvtFlag = 1;           // event enable(0)
static	BOOL   bRunTimer = FALSE;

static  USHORT  usEnabledChannel=0;
static  USHORT	usChannelCount=0;



HGLOBAL hBuf[4], hVoltageBuf[4];
FLOAT  far * lpVoltageBuf[4]={NULL,NULL,NULL,NULL};
USHORT far * lpBuf[4]={NULL,NULL,NULL,NULL};

HGLOBAL			hCommonBuf;
USHORT far *	lpCommonBuf;	

static  SWAVE sWaveCh0 = {0,          // output waveform A index
                        2.00f,      // the magnitude of output waveform A
                        2.00f,      // the offset of output waveform A
                        2048},       // the points of one period
              sWaveCh1 = {1,          // output waveform B index
                        1.00f,      // the magnitude of output waveform B
                        3.00f,      // the offset of output waveform B
                        2048},       // the points of one period
              sWaveCh2 = {2,          // output waveform C index
                        2.00f,      // the magnitude of output waveform C
                        2.00f,      // the offset of output waveform C
                        2048},       // the points of one period
              sWaveCh3 = {3,          // output waveform C index
                        2.00f,      // the magnitude of output waveform C
                        2.00f,      // the offset of output waveform C
                        2048};       // the points of one period


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, lpfnWaveDlgProc;
void SetRealBuffer(float far *lpBuf, long num, LPSWAVE lpWave);
void SetMultiToOneBuffer(USHORT usEnabledChannel, int count);

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


/***************************************************************************
    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 : Analog output with bus master DMA" , /* 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: ConfigDlgProc(HWND, unsigned, WPARAM, LPARAM)

    PURPOSE:  Processes dialog box messages for configuration
****************************************************************************/

BOOL FTYPE ConfigDlgProc(hDlg, message, wParam, lParam)
HWND hDlg;                              /* window handle                   */
unsigned message;                       /* type of message                 */
WPARAM wParam;                          /* additional information          */
LPARAM lParam;                          /* additional information          */
{

    switch (message)
    {
        case WM_INITDIALOG :

            if (!gwSelectDevice)
            {
                // Step 1: Select Device
                ErrCde = DRV_SelectDevice(hDlg, FALSE, &dwDeviceNum, szDescript);
                if (ErrCde != SUCCESS)
                {
                    DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                    MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                    return 0;
                }

                gwSelectDevice = TRUE;
            }

			// Show device description to Button text
            SendDlgItemMessage(hDlg, IDC_DeviceSelect, WM_SETTEXT,
               50, (LPARAM)(LPSTR)szDescript);



            // Initialize Conversion Number
            ltoa(gulConvNum, szBuffer, 10);
            SendDlgItemMessage(hDlg, IDC_CONVERSION, EM_REPLACESEL, 0,
                            (LPARAM)((LPSTR)szBuffer));

            // Initialize Pacer Rate
            ltoa(gdwPacerRate, szBuffer, 10);
            SendDlgItemMessage(hDlg, IDC_PACER, EM_REPLACESEL, 0,
                            (LPARAM)((LPSTR)szBuffer));

            // Initialize wave form count
			if(gwWaveFormCount == INFINITE ) 
				strcpy(szBuffer,"INFINITE");
			else
				ltoa(gwWaveFormCount, szBuffer, 10);
            SendDlgItemMessage(hDlg, IDC_WAVEFORMCOUNT, EM_REPLACESEL, 0,
                            (LPARAM)((LPSTR)szBuffer));

            // Initialize Triggering
            CheckRadioButton(hDlg, IDC_INTTRIG, IDC_EXTTRIG,
                                   (gwExtTrig)?IDC_EXTTRIG:IDC_INTTRIG);

            // Initialize Message Flag
            CheckRadioButton(hDlg, IDC_EVTENABLE, IDC_EVTDISABLE,
                (gwEvtFlag)?IDC_EVTENABLE:IDC_EVTDISABLE);

            return TRUE;

        case WM_COMMAND :
             switch (LOWORD(wParam))
             {
                case IDOK :

                     EndDialog(hDlg, 0);
                     return TRUE;


                case IDCANCEL :
                     EndDialog(hDlg, 0);
                     return TRUE;

                case IDC_DeviceSelect:

                    // Step 1: Select Device
                    ErrCde = DRV_SelectDevice(hDlg, FALSE, &dwDeviceNum, szDescript);
                    if (ErrCde != SUCCESS)
                    {
                        DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                        MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                        return 0;
                    }

                    // Show device description to Button text
                    SendDlgItemMessage(hDlg, IDC_DeviceSelect, WM_SETTEXT,
                        50, (LPARAM)(LPSTR)szDescript);

                    gwSelectDevice = TRUE;

                    return TRUE;

                case IDC_CONVERSION :
                     if (HIWORD(wParam) == EN_KILLFOCUS)
                     {
                        if(SendDlgItemMessage(hDlg, IDC_CONVERSION,
                                  EM_GETMODIFY, 0, 0))
                        {

⌨️ 快捷键说明

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