madsoft.c
来自「16 relay output channels and 16 isolated」· C语言 代码 · 共 1,682 行 · 第 1/5 页
C
1,682 行
/*
***********************************************************************
* Program : MAIEXP.C *
* Description : Demo program for multiple channel AI with expansion *
* 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
*
* GainListDlgProc() - Process the dialog box messages for gain list
*/
#include <windows.h> /* required for all Windows applications */
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <commctrl.h>
#include "..\..\..\include\driver.h"
#include "..\..\..\include\os.h"
#include "resource.h"
// ------------------------------------------------------------------------
// CONSTANT DEFINITION
// ------------------------------------------------------------------------
#define MAX_DEVICES 100
#define MAX_CHANNELS 64
// ------------------------------------------------------------------------
// GLOBAL VARIABLES
// ------------------------------------------------------------------------
HANDLE hInst; // current instance
HWND hMainWnd; // main window handle
static DEVFEATURES DevFeatures; // structure for device features
static DEVCONFIG_AI DevCfg; // structure for DEVCONFIG_AI table
static PT_MAIConfig ptMAIConfig; // structure for MAIConfig table
static PT_MAIVoltageIn ptMAIVoltageIn; // structure for MAIVoltageIn table
static PT_MAIVoltageInExp ptMAIVoltageInExp; // structure for MAIVoltageInExp table
static PT_DeviceGetFeatures ptDevFeatures; // structure for DeviceGetFeatures
static PT_AIGetConfig ptAIGetConfig; // structure for AIGetConfig table
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
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 lpfnGainListDlgProc; // gain list setting dialog procedure
char szBuffer[40];
USHORT usStartChan = 0; // start channel
USHORT usNumChan = 1; // Number of channel
USHORT usCurrentChan = 0; // Current channel number
USHORT usDasChan[MAX_CHANNELS]; // das Channel array
USHORT usExpChan[MAX_CHANNELS]; // varied expansion chan
USHORT usExpChanTemp[MAX_CHANNELS]; // varied for PCLD-788 use
USHORT usBoardID [MAX_CHANNELS]; // varied board ID for 788
USHORT usExpFlag = 0; // expansion board flag
USHORT usMaxChannel = 0; // max channel
CHAR szExpName[15]; // expansion name
CHAR szBuf[64]; // temp buffer
USHORT gwGainList = 0; // gain list flag
USHORT gwGainIndex = 0;
USHORT usGainIndex[MAX_CHANNELS]; // varied input range index
USHORT usGainCode[MAX_CHANNELS]; // varied input range array
// ------------------------------------------------------------------------
// FUNCTION DECLARATION
// ------------------------------------------------------------------------
BOOL InitApplication(HANDLE hInstance);
BOOL InitInstance(HANDLE hInstance, int nCmdShow);
long FTYPE MainWndProc(HWND, UINT, WPARAM, LPARAM);
int FTYPE WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow);
PRIVATE void AllWindows(HWND hDlg);
PRIVATE void SetChannel(HWND hDlg);
PRIVATE void SetCurrentChan(HWND hDlg, BOOL bflag);
PRIVATE void SetGain(HWND hDlg, BOOL bflag);
PRIVATE void SetExpChan(HWND hDlg, BOOL bflag);
PRIVATE void SetBoardID(HWND hDlg, BOOL bflag);
int PhyChanToLogChan(DEVCONFIG_AI *pDevCfg,int phychan);
/***************************************************************************
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(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 : Software 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 (!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: 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;
HWND hGainListWnd;
DWORD ListStyle;
LVCOLUMN lvColum;
LVITEM lvItem;
char szBuff[40];
static int iPos = -1;
LPNMITEMACTIVATE lpnmitem;
LPNMHDR lpnmhdr;
DWORD dwPhyChan; // Physical channel number
char szTmpBuff[40];
switch (message)
{
case WM_INITDIALOG :
// ------------------------------------------------------------
// Initialize Input Range List Combobox, it needs to get device
// features for gain list
// ------------------------------------------------------------
// Step 1: Open Device
if (gnNumOfSubdevices == 0)
{
ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
else
{
ErrCde = DRV_DeviceOpen(
SubDeviceList[gwSubDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
if (ErrCde != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hMainWnd,(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(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 3: Get AI config
ptAIGetConfig.buffer = &DevCfg;
if ((ErrCde = DRV_AIGetConfig(DriverHandle,
(LPT_AIGetConfig)&ptAIGetConfig)) != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 4: Initialize Input Range List Combobox with device features
if (DevFeatures.usNumGain != 0)
{
for(i = 0; i < (USHORT)DevFeatures.usNumGain; i ++)
SendDlgItemMessage(hDlg, IDC_CMB_GAIN, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)(DevFeatures.glGainList[i].szGainStr)));
SendDlgItemMessage(hDlg, IDC_CMB_GAIN,
CB_SELECTSTRING, (WPARAM)(-1),
(LPARAM)((LPSTR)(DevFeatures.glGainList[0].szGainStr)));
}
// Step 5: Initialize Gain Setting List Box
// Set List View Style
hGainListWnd = GetDlgItem(hDlg, IDC_LST_GAIN);
ListStyle = ListView_GetExtendedListViewStyle(hGainListWnd);
ListStyle = ListStyle | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
ListView_SetExtendedListViewStyle(hGainListWnd, ListStyle);
// Insert Column
lvColum.mask = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
wsprintf(szBuff, "%s", "Physical Chan");
lvColum.pszText = szBuff;
lvColum.fmt = LVCFMT_CENTER;
lvColum.cx = 80;
ListView_InsertColumn(hGainListWnd, 0, &lvColum);
wsprintf(szBuff, "%s", "Gain");
lvColum.cx = 80;
ListView_InsertColumn(hGainListWnd, 1, &lvColum);
wsprintf(szBuff, "%s", "Configuration");
lvColum.cx = 90;
ListView_InsertColumn(hGainListWnd, 2, &lvColum);
// Insert Item
lvItem.mask = LVIF_TEXT;
lvItem.pszText = szBuff;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?