📄 adint.c
字号:
case IDC_OVERALLGAIN :
gwGainList = 0;
EnableWindow(GetDlgItem(hDlg, IDC_INPRANGE), TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_GAINLIST), FALSE);
break;
case IDC_GAINARRAY :
gwGainList = 1;
EnableWindow(GetDlgItem(hDlg, IDC_INPRANGE), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_GAINLIST), TRUE);
break;
case IDC_INTTRIG :
EnableWindow(GetDlgItem(hDlg, IDC_PACER), TRUE);
gwExtTrig = 0;
break;
case IDC_EXTTRIG :
EnableWindow(GetDlgItem(hDlg, IDC_PACER), FALSE);
gwExtTrig = 1;
break;
case IDC_CYCLIC :
gwCyclicMode = 1;
break;
case IDC_NONCYCLIC :
gwCyclicMode = 0;
break;
case IDC_DATAUSHORT :
gwDataType = 0;
break;
case IDC_DATAFLOAT :
gwDataType = 1;
break;
case IDC_EVTENABLE :
gwEvtFlag = 1;
break;
case IDC_EVTDISABLE :
gwEvtFlag = 0;
break;
case IDC_BUFSINGLE :
gwBufferMode = 0;
break;
case IDC_BUFDOUBLE :
gwBufferMode = 1;
break;
}
break;
}
return FALSE ;
}
/***************************************************************************
FUNCTION: ShowDataDlgProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes dialog box messages for acquired data
****************************************************************************/
BOOL FTYPE ShowDataDlgProc(hDlg, message, wParam, lParam)
HWND hDlg; /* window handle */
unsigned message; /* type of message */
WPARAM wParam; /* additional information */
LPARAM lParam; /* additional information */
{
ULONG i;
LPVOID temp;
switch (message)
{
case WM_INITDIALOG :
if (gwDataType == 0)
temp = (USHORT far *)ptFAITransfer.DataBuffer;
else
temp = (FLOAT far *)ptFAITransfer.DataBuffer;
for(i = gdwStartPt; i <= gdwStopPt; ++i)
{
if (gwDataType == 0)
sprintf(szBuffer, "Buf[%ld] = %4x",i, ((USHORT far *)temp)[i]);
else
sprintf(szBuffer, "Buf[%ld] = %10.6f", i, ((FLOAT far *)temp)[i]);
if(SendDlgItemMessage(hDlg, IDC_DATALIST, LB_ADDSTRING, 0,
(LPARAM)(LPSTR)szBuffer) == LB_ERRSPACE)
{ MessageBox(hWnd,(LPCSTR)"Not Enough Memory",
"Display Data",MB_OK);
return TRUE;
}
}
return TRUE;
case WM_COMMAND :
switch (LOWORD(wParam))
{
case IDOK :
case IDCANCEL :
EndDialog(hDlg, 0);
return TRUE;
}
break;
}
return FALSE ;
}
/***************************************************************************
FUNCTION: DisplayDlgProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes dialog box messages for display range
****************************************************************************/
BOOL FTYPE DisplayDlgProc(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 :
// Initialize Start Point
ultoa(gdwStartPt, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_ESTAPT, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
// Initialize Stop Point
ultoa(gdwStopPt, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_ESTOPT, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
return TRUE;
case WM_COMMAND :
switch (LOWORD(wParam))
{
case IDOK :
case IDCANCEL :
EndDialog(hDlg, 0);
return TRUE;
case IDC_ESTAPT :
if (HIWORD(wParam) == EN_KILLFOCUS)
{
if(SendDlgItemMessage(hDlg, IDC_ESTAPT,
EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(hDlg, IDC_ESTAPT,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
gdwStartPt = (USHORT)atoi(szBuffer);
SendDlgItemMessage(hDlg, IDC_ESTAPT,
EM_SETMODIFY, FALSE, 0) ;
}
}
return TRUE;
case IDC_ESTOPT :
if (HIWORD(wParam) == EN_KILLFOCUS)
{
if(SendDlgItemMessage(hDlg, IDC_ESTOPT,
EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(hDlg, IDC_ESTOPT,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
gdwStopPt = atol(szBuffer);
SendDlgItemMessage(hDlg, IDC_ESTOPT,
EM_SETMODIFY, FALSE, 0) ;
}
}
return TRUE;
}
break;
}
return FALSE ;
}
/***************************************************************************
FUNCTION: MainWndProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes messages
MESSAGES:
WM_CREATE - create window
WM_COMMAND - application menu (About dialog box)
WM_DESTROY - destroy window
****************************************************************************/
long FTYPE MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd; /* window handle */
unsigned message; /* type of message */
WPARAM wParam; /* additional information */
LPARAM lParam; /* additional information */
{
int dec, sign;
TEXTMETRIC tm;
HDC hdc;
static int cxChar, cyChar;
DWORD dwExitCode;
BOOL bThreadStatus;
char *szStr, szDest[100], szTemp[50];
double ratio;
switch (message)
{
case WM_CREATE:
hMenu = GetMenu(hWnd);
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;
lpfnShowDataDlgProc = MakeProcInstance (ShowDataDlgProc, hInstance) ;
lpfnDisplayDlgProc = MakeProcInstance (DisplayDlgProc, hInstance) ;
lpfnGainListDlgProc = MakeProcInstance (GainListDlgProc, hInstance) ;
hdc = GetDC(hWnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hWnd, hdc);
//Create stop button and status button
hwndStopButton = CreateWindow("button", "Stop",
(DWORD)(WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON),
0, 0, 8*cxChar, 3*cyChar/2, hWnd,
(HMENU)IDC_STOPBUTTON,
(HANDLE)hInstance, (LPVOID)NULL);
hwndStatusButton = CreateWindow("button", "Status",
(DWORD)(WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON),
8*cxChar, 0, 8*cxChar, 3*cyChar/2, hWnd,
(HMENU)IDC_STATUSBUTTON,
(HANDLE)hInstance, (LPVOID)NULL);
EnableWindow(hwndStopButton, FALSE);
EnableWindow(hwndStatusButton, FALSE);
return 0 ;
case WM_COMMAND: /* message: from application menu */
hMenu = GetMenu(hWnd);
switch(LOWORD(wParam))
{
// Show the dialog box of the input parameter
case IDM_SETTING :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_SETTING),
hWnd, lpfnConfigDlgProc) ;
return 0;
// Show the dialog box for the range of data to display
case IDM_DISPLAY:
DialogBox (hInstance, MAKEINTRESOURCE(IDD_DISPLAY),
hWnd, lpfnDisplayDlgProc) ;
return 0;
case IDM_RUN :
// Step 1: Device open
ErrCde = DRV_DeviceOpen(dwDeviceNum,
(LONG far *)&DriverHandle);
if (ErrCde != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Device Open",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: Allocate memory for driver
if((hBuf=(USHORT far *)GlobalAlloc(GHND,
sizeof(USHORT) * gulConvNum)) == 0)
{
MessageBox(hWnd,"Not enough memory for buffer ",
"High Speed",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 4: Allocate memory for Voltage data or Raw data
if((hUserBuf=(FLOAT far *)GlobalAlloc(GHND,
sizeof(FLOAT) * gulConvNum)) == 0)
{
MessageBox(hWnd,"Not enough memory for buffer ",
"High Speed",MB_OK);
GlobalFree(hBuf);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Prepare some informations to run
ptFAIIntStart.buffer = (USHORT far *)GlobalLock(hBuf);
ptFAITransfer.DataBuffer = (FLOAT far *)GlobalLock(hUserBuf);
// Step 5: Enable event feature
ptEnableEvent.EventType = ADS_EVT_INTERRUPT |
ADS_EVT_BUFCHANGE |
ADS_EVT_TERMINATED |
ADS_EVT_OVERRUN;
ptEnableEvent.Enabled = gwEvtFlag;
ptEnableEvent.Count = gwFifoSize ? gwFifoSize : 1;
if ((ErrCde = DRV_EnableEvent(DriverHandle,
(LPT_EnableEvent)&ptEnableEvent)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
GlobalUnlock(hBuf);
GlobalUnlock(hUserBuf);
GlobalFree(hBuf);
GlobalFree(hUserBuf);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 6: Start Interrupt transfer
ptFAIIntStart.TrigSrc = gwExtTrig;
ptFAIIntStart.SampleRate = gdwPacerRate;
ptFAIIntStart.chan = gwStartChl;
ptFAIIntStart.gain = DevFeatures.glGainList[gwGainCode].usGainCde;
ptFAIIntStart.count = gulConvNum;
ptFAIIntStart.cyclic = gwCyclicMode;
if (gwFifoEnable && gwFifoSize)
ptFAIIntStart.IntrCount = gwFifoSize;
else
ptFAIIntStart.IntrCount = 1;
if ((ErrCde = DRV_FAIIntStart(DriverHandle,
(LPT_FAIIntStart)&ptFAIIntStart)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
GlobalUnlock(hBuf);
GlobalUnlock(hUserBuf);
GlobalFree(hBuf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -