📄 dadma.c
字号:
{
SendDlgItemMessage(hDlg, IDC_PERIOD_A,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
sWaveA.wPeriod = atoi(szBuffer);
SendDlgItemMessage(hDlg, IDC_PERIOD_A,
EM_SETMODIFY, FALSE, 0) ;
}
}
return TRUE;
case IDC_PERIOD_B:
if (HIWORD(wParam) == EN_KILLFOCUS)
{
if(SendDlgItemMessage(hDlg, IDC_PERIOD_B,
EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(hDlg, IDC_PERIOD_B,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
sWaveB.wPeriod = atoi(szBuffer);
SendDlgItemMessage(hDlg, IDC_PERIOD_B,
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;
char *szStr, szDest[100], szTemp[50];
double ratio;
DWORD dwExitCode;
BOOL bThreadStatus;
switch (message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;
lpfnWaveDlgProc = MakeProcInstance (WaveDlgProc, 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
//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;
case IDM_WAVEFORM :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_WAVEFORM),
hWnd, lpfnWaveDlgProc) ;
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: Allocate memory used by 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 3: Allocate memory for real voltage
if((hVoltageBuf=(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;
}
// Step 4: Allocate memory for binary data
if((hBinaryBuf=(USHORT far *)GlobalAlloc(GHND,
sizeof(USHORT) * gulConvNum)) == 0)
{
MessageBox(hWnd,"Not enough memory for buffer ",
"High Speed",MB_OK);
GlobalFree(hBuf);
GlobalFree(hVoltageBuf);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 5: Allocate DMA buffer for DMA transfer
ptAllocateDMABuffer.CyclicMode = gwCyclicMode;
ptAllocateDMABuffer.RequestBufSize = gulConvNum * 2;
ptAllocateDMABuffer.ActualBufSize = &gwActualBufSize;
ptAllocateDMABuffer.buffer = &pBuffer;
if ((ErrCde = DRV_AllocateDMABuffer(DriverHandle,
(LPT_AllocateDMABuffer)&ptAllocateDMABuffer)) != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
GlobalUnlock(hBuf); GlobalFree(hBuf);
GlobalUnlock(hVoltageBuf); GlobalFree(hVoltageBuf);
GlobalUnlock(hBinaryBuf); GlobalFree(hBinaryBuf);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Lock down buffer
lpBuf = (USHORT far *)GlobalLock(hBuf);
lpBinaryBuf = (USHORT far *)GlobalLock(hBinaryBuf);
lpVoltageBuf = (FLOAT far *)GlobalLock(hVoltageBuf);
// set real voltage to hVoltageBuf
SetRealBuffer(lpVoltageBuf, gulConvNum, &sWaveA);
// Step 6: call FAOScale for transfer voltage to binary data
ptFAOScale.VoltArray = lpVoltageBuf;
ptFAOScale.BinArray = lpBuf;
ptFAOScale.chan = gwStartChl;
ptFAOScale.count = gulConvNum;
if ((ErrCde = DRV_FAOScale(DriverHandle,
(LPT_FAOScale)&ptFAOScale)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
GlobalUnlock(hBuf); GlobalFree(hBuf);
GlobalUnlock(hVoltageBuf); GlobalFree(hVoltageBuf);
GlobalUnlock(hBinaryBuf); GlobalFree(hBinaryBuf);
DRV_FreeDMABuffer(DriverHandle, (LPARAM)&pBuffer);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 7: Enable event feature
ptEnableEvent.EventType = ADS_EVT_INTERRUPT |
ADS_EVT_BUFCHANGE |
ADS_EVT_TERMINATED |
ADS_EVT_OVERRUN;
ptEnableEvent.Enabled = gwEvtFlag;
ptEnableEvent.Count = 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); GlobalFree(hBuf);
GlobalUnlock(hVoltageBuf); GlobalFree(hVoltageBuf);
GlobalUnlock(hBinaryBuf); GlobalFree(hBinaryBuf);
DRV_FreeDMABuffer(DriverHandle, (LPARAM)&pBuffer);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// Step 8: call FAOIntStart for start action
// Default steting - conversion number = 1000
// start channel = 1, pacer rate = 1000 Hz
// cyclic , enable event
ptFAODmaStart.buffer = (LONG far *)lpBuf; // analog output data
ptFAODmaStart.TrigSrc = gwExtTrig; // triggering
ptFAODmaStart.SampleRate = gdwPacerRate; // pacer rate = 1K
ptFAODmaStart.chan = gwStartChl; // start channel
ptFAODmaStart.count = gulConvNum; // DA conversion number
if ((ErrCde = DRV_FAODmaStart(DriverHandle,
(LPT_FAODmaStart)&ptFAODmaStart)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
GlobalUnlock(hBuf); GlobalFree(hBuf);
GlobalUnlock(hVoltageBuf); GlobalFree(hVoltageBuf);
GlobalUnlock(hBinaryBuf); GlobalFree(hBinaryBuf);
DRV_FreeDMABuffer(DriverHandle, (LPARAM)&pBuffer);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
gwRepeatCount = 0;
// if event feature is enabled , then create one thread.
if (gwEvtFlag)
{
hThreadHandle = CreateThread(0, 0,
(LPTHREAD_START_ROUTINE) UserThread,
0, 0, (LPDWORD)&dwThreadID);
}
EnableMenuItem(hMenu, IDM_RUN, MF_DISABLED | MF_BYCOMMAND);
// Enable stop and status buttons
EnableWindow(hwndStopButton, TRUE);
EnableWindow(hwndStatusButton, TRUE);
return 0;
//end IDM_RUN
case IDC_STOPBUTTON:
// Close thread
bThreadStatus = GetExitCodeThread(hThreadHandle, &dwExitCode);
if ((dwExitCode== (DWORD)STILL_ACTIVE) && (bThreadStatus))
{
TerminateThread(hThreadHandle, 0);
CloseHandle(hThreadHandle);
CloseHandle(hEvent);
Sleep(0);
}
// Disable stop and status buttons
EnableWindow(hwndStopButton, FALSE);
EnableWindow(hwndStatusButton, FALSE);
// Step 1: Stop D/A conversion for high speed
if ((ErrCde = DRV_FAOStop(DriverHandle)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
GlobalUnlock(hBuf); GlobalFree(hBuf);
GlobalUnlock(hVoltageBuf); GlobalFree(hVoltageBuf);
GlobalUnlock(hBinaryBuf); GlobalFree(hBinaryBuf);
DRV_FreeDMABuffer(DriverHandle, (LPARAM)&pBuffer);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -