欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

1753evt.c

16 relay output channels and 16 isolated digital input channels LED indicators to show activated
C
第 1 页 / 共 4 页
字号:
/*
 ***********************************************************************
 *  Program     : DIGIN.C                                              *
 *  Description : Demo program for digital input                       *
 *  Revision    : 1.00                                                 *
 *  Date        : 9/5/1996                     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
 */


#include <windows.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "..\..\..\..\include\driver.h"

#include "resource.h"

// ------------------------------------------------------------------------
// CONSTANT DEFINITION
// ------------------------------------------------------------------------
#define     MAX_DEVICES     100


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

static      DEVFEATURES             DevFeatures;    // structure for device features
static      PT_DeviceGetFeatures    ptDevFeatures;
static      PT_DioReadPortByte      ptDioReadPortByte;
static      PT_EnableEventEx        ptEnableEventEx;     // Enable event
static      PT_EnableEvent          ptEnableEvent;       // Enable event
static      PT_FAICheck             ptFAICheck;          // FAICheck table
static      PT_CheckEvent           ptCheckEvent;        // Check event
static      PT_FDITransfer          ptFDITransfer;
static      ThreadhWnd;    

HANDLE      hThreadHandle;
DWORD       dwThreadID;

char        szErrMsg[80];               // Use for MESSAGEBOX function
LRESULT     ErrCde;                     // Return error code

//
// used for dynamic allocation memory for the installed devices
//
// static  HGLOBAL     hDeviceList,hSubDeviceList;
// static  LPDEVLIST   DeviceList,SubDeviceList;
//

//
// used for fixed memory for the installed devices
//
DEVLIST     DeviceList[MAX_DEVICES];
DEVLIST     SubDeviceList[MAX_DEVICES];

LONG        DriverHandle = (LONG)NULL;          // driver handle
BOOL        bRun = FALSE;                       // flag for running
USHORT      gwDevice = 0, gwSubDevice = 0;      // device index
USHORT      gwChannel = 0;                      // input channel
USHORT      gwValue;                            // input value
SHORT       gnNumOfDevices, gnNumOfSubdevices;  // number of installed devices
USHORT      gwScanTime = 1000;                  // scan time
DWORD       gdwStartTime;                       // start time
DWORD       gdwElapseTime = 0;                  // elapse time
USHORT      gwOverrunCount = 0;                 // overrun count
FARPROC     lpfnConfigDlgProc;                  // config. dialog procedure
FARPROC     lpfnScanDlgProc;                    // scan dialog procedure
FARPROC     lpfnConfigPatternProc;              // Pattern dialog procedure
FARPROC     lpfnConfigStatusProc;               // Status dialog procedure
FARPROC     lpfnConfigExpPatternProc;           // Expansion board Pattern dialog procedure
FARPROC     lpfnConfigExpStatusProc;            // Expansion board Status dialog procedure

USHORT      usPEnable = 0, usPValue = 0;
USHORT      usSEnable = 0, usIEnable = 0;
USHORT      m_bContinue = FALSE;
USHORT      usSCount=0,usPCount=0, usICount=0;
BOOL        bThreadflag = FALSE;

// ------------------------------------------------------------------------
// FUNCTION DECLARATION
// ------------------------------------------------------------------------
BOOL InitApplication(HANDLE);
BOOL InitInstance(HANDLE, int);
long FTYPE MainWndProc(HWND, UINT, WPARAM, LPARAM);
int  FTYPE WinMain(HINSTANCE, HINSTANCE, LPSTR, int);

void UserThread();
void adPatternMatchEvent();
void adInterruptEvent();
void adStatusChangeEvent();


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

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

int FTYPE WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HINSTANCE hInstance;                          /* current instance             */
HINSTANCE 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(hInstance, "IDI_ICON1");
    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
(
    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.
    hMainWnd = CreateWindow(
        "MyClass",                 /* See RegisterClass() call.           */
        "Advantech Driver Demo : Digital Input with Interrupt for PCI-1753" , /* 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 (!hMainWnd)
        return (FALSE);

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

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

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

    PURPOSE:  Processes dialog box messages for scan time settings
****************************************************************************/
BOOL FTYPE ConfigPatternProc
(
    HWND        hDlg,                          // window handle
    unsigned    message,                       // type of message
    WPARAM      wParam,                        // additional information
    LPARAM      lParam                         // additional information
)
{
    USHORT      i;

    switch (message)
    {
    case WM_INITDIALOG :
	  for(i=0; i<8; i++)
	  {
		 EnableWindow(GetDlgItem(hDlg,(IDC_Pattern0 + i)),TRUE);

		 if(usPEnable & (0x01 << i))
		 {
		    CheckDlgButton(hDlg,(IDC_Pattern0 + i),TRUE);
			EnableWindow(GetDlgItem(hDlg,IDC_PB0HI + (i*2)),TRUE);
			EnableWindow(GetDlgItem(hDlg,IDC_PB0LOW + (i*2)),TRUE);
			if(usPValue & (0x01 << i))
			   CheckDlgButton(hDlg,(IDC_PB0HI + (i*2)),1);
			else
			   CheckDlgButton(hDlg,(IDC_PB0LOW + (i*2)),1);
		 } else	 {
		    CheckDlgButton(hDlg,(IDC_Pattern0 + i),FALSE);
			EnableWindow(GetDlgItem(hDlg,IDC_PB0HI + i*2),FALSE);
			EnableWindow(GetDlgItem(hDlg,IDC_PB0LOW + i*2),FALSE);
		 }
	  }

        return TRUE;

    case WM_COMMAND :
         switch (LOWORD(wParam))
         {
		    case IDC_Pattern0:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern0))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB0HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB0LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB0HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB0LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB0HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB0LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern1:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern1))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB1HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB1LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB1HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB1LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB1HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB1LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern2:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern2))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB2HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB2LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB2HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB2LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB2HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB2LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern3:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern3))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB3HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB3LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB3HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB3LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB3HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB3LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern4:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern4))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB4HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB4LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB4HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB4LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB4HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB4LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern5:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern5))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB5HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB5LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB5HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB5LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB5HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB5LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern6:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern6))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB6HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB6LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB6HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB6LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB6HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB6LOW),FALSE);
				 }
				 break;
		    case IDC_Pattern7:
                 if(IsDlgButtonChecked(hDlg, IDC_Pattern7))
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB7HI ),TRUE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB7LOW),TRUE);
		            CheckDlgButton(hDlg,IDC_PB7HI,TRUE);	 
			        CheckDlgButton(hDlg,IDC_PB7LOW,FALSE);	 
				 }
		         else
				 {  EnableWindow(GetDlgItem(hDlg,IDC_PB7HI ),FALSE);
			        EnableWindow(GetDlgItem(hDlg,IDC_PB7LOW),FALSE);
				 }
				 break;

⌨️ 快捷键说明

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