📄 dio_soft_dword.c
字号:
//#############################################################################
//*****************************************************************************
//
// Copyright (c) 2004 Xi'an R&D Center Advantech Automation Corp.
//
// This is An Unpublished Work Containing Confidential And Proprietary
// Information Which Is The Property Of Advantech Automation Corp.
//
// Any Disclosure, Use, Or Reproduction, Without Written Authorization From
// Advantech Automation Corp., Is Strictly Prohibit.
//
//*****************************************************************************
//#############################################################################
//
// File Name : DIO_SOFT_DWORD.C
// Revision : 1.0
//
// Created : 08/26/2004
//
// Description :
// This examples performs the DIO Word and DWord operation.
//
//-----------------------------------------------------------------------------
//
// 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
//
// RunDlgProc() - Precess the dialog box message for run.
//
//-----------------------------------------------------------------------------
#include <windows.h> /* required for all Windows applications */
#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 PT_DioReadPortWord ptDioReadPortWord; //DioReadPortWord table
static PT_DioWritePortWord ptDioWritePortWord; //DioWritePortWord table
static PT_DioReadPortDword ptDioReadPortDword; //DioReadPortDword table
static PT_DioWritePortDword ptDioWritePortDword; //DioWritePortDword table
static PT_DioGetCurrentDOWord ptDioGetCurrentDOWord; //DioGetCurrentDOWord table
static PT_DioGetCurrentDODword ptDioGetCurrentDODword;//DioGetCurrentDODword table
static PT_DeviceGetFeatures ptDevFeatures; // Devfeatures table
static DEVFEATURES DevFeatures;
char szErrMsg[80]; // used for MESSAGEBOX function
LRESULT ErrCde; // return error code
DEVLIST DeviceList[MAX_DEVICES];
DEVLIST SubDeviceList[MAX_DEVICES];
LONG DriverHandle = (LONG)NULL; // driver handle
USHORT gwPort = 0x0; // device index
USHORT gwDiValue = 0; // read port Word value
ULONG glDiValue = 0; // read port DWord value
USHORT gwValidMask = 0; // read port Word valid mask
ULONG glValidMask = 0; // read port DWord valid mask
ULONG glDoState = 0xA55A5AA5; // write port data
USHORT gwWriteMask = 0xFFFF; // write port Word mask
ULONG glWriteMask = 0xFFFFFFFF; // write port DWord mask
USHORT gwGetDOValue = 0;
ULONG glGetDOValue = 0;
USHORT gwDevice = 0, gwSubDevice = 0; // device index
SHORT gnNumOfDevices, gnNumOfSubdevices; // number of installed devices
USHORT usTemp;
FARPROC lpfnConfigDlgProc; // config. dialog procedure
FARPROC lpfnRunDlgProc; // run dialog procedure
// ------------------------------------------------------------------------
// FUNCTION DECLARATION
// ------------------------------------------------------------------------
BOOL InitApplication(HANDLE hInstance);
BOOL InitInstance(HANDLE hInstance, int nCmdShow);
long FTYPE MainWndProc(
HWND,
UINT,
WPARAM,
LPARAM);
int PASCAL WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow);
void EditLimitHexCharacter(HWND hDlg, WPARAM wParam);
//*****************************************************************************
// FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
//
// PURPOSE: calls initialization function, processes message loop
//-----------------------------------------------------------------------------
int PASCAL WinMain(
HINSTANCE hInstance, // current instance
HINSTANCE hPrevInstance, // previous instance
LPSTR lpCmdLine, // command line
int nCmdShow ) // show-window type (open/icon)
{
MSG msg; // message
if (!hPrevInstance)
{
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(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 : DIO_SOFT_DWORD" , // 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: ConfigDlgProc(HWND, unsigned, WPARAM, LPARAM)
//
// PURPOSE: Processes dialog box messages for configuration
//-----------------------------------------------------------------------------
BOOL FTYPE ConfigDlgProc(
HWND hDlg, // window handle
unsigned message, // type of message
WPARAM wParam, // additional information
LPARAM lParam) // additional information
{
char szBuffer[40];
int nOutEntries;
int i;
DWORD dwIndex;
switch (message)
{
case WM_INITDIALOG :
{
// --------------------------------
// Initialize Device List Combobox
// --------------------------------
// get number of the installed devices
ErrCde = DRV_DeviceGetNumOfList((SHORT far *)&gnNumOfDevices);
if (ErrCde != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hMainWnd,(LPCSTR)szErrMsg, "Driver Message", MB_OK);
return TRUE;
}
if (gnNumOfDevices > MAX_DEVICES)
{
gnNumOfDevices = MAX_DEVICES;
}
// retrieve the information of all installed devices
ErrCde = DRV_DeviceGetList(
(DEVLIST far *)&DeviceList[0],
(SHORT)gnNumOfDevices,
(SHORT far *)&nOutEntries);
if (ErrCde != (LONG)SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return TRUE;
}
// initialize the Device List Combobox with the retrieved information
for (i = 0; i < gnNumOfDevices; i ++)
{
SendDlgItemMessage(
hDlg,
IDC_DEVICE,
CB_ADDSTRING,
0,
(LPARAM)((LPSTR)DeviceList[i].szDeviceName));
}
SendDlgItemMessage(
hDlg,
IDC_DEVICE,
CB_SETCURSEL,
(WPARAM)gwDevice,
(LPARAM)0);
// -----------------------------------------------------------
// Initialize Module List Combobox for COM port or CAN devices
// -----------------------------------------------------------
// check if there is any device attached on this COM port or CAN
gnNumOfSubdevices = DeviceList[gwDevice].nNumOfSubdevices;
if (gnNumOfSubdevices > MAX_DEVICES)
{
gnNumOfSubdevices = MAX_DEVICES;
}
// retrieve the information of all installed devices
if (gnNumOfSubdevices != 0)
{
ErrCde = DRV_DeviceGetSubList(
(DWORD)DeviceList[gwDevice].dwDeviceNum,
(DEVLIST far *)&SubDeviceList[0],
(SHORT)gnNumOfSubdevices,
(SHORT far *)&nOutEntries);
if (ErrCde != (LONG)SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(
hMainWnd,
(LPCSTR)szErrMsg,
"Driver Message",
MB_OK);
return TRUE;
}
// initialize the Module List Combobox with the retrieved
// information
EnableWindow(GetDlgItem(hDlg, IDC_MODULE), TRUE);
SendDlgItemMessage(
hDlg,
IDC_MODULE,
CB_RESETCONTENT,
0,
(LPARAM)((LPSTR)0));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -