📄 pulse.c
字号:
(LPARAM)((LPSTR)szBuffer));
sprintf(szBuffer, "%2.1f", gfUpCycle);
SendDlgItemMessage(hDlg, IDC_UPCYCLE, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
return TRUE;
case WM_COMMAND :
switch (LOWORD(wParam))
{
case IDOK :
//
// get device selection
//
if ((dwIndex = SendDlgItemMessage(hDlg, IDC_DEVICE,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwDevice = (WORD)dwIndex;
//
// get sub-device selection
//
if ((dwIndex = SendDlgItemMessage(hDlg, IDC_MODULE,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwSubDevice = (WORD)dwIndex;
//
// get channel number
//
if (SendDlgItemMessage(hDlg, IDC_ECHANNEL,
EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(hDlg, IDC_ECHANNEL,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
gwChannel = atoi(szBuffer);
SendDlgItemMessage(hDlg, IDC_ECHANNEL,
EM_SETMODIFY, FALSE, 0) ;
}
//
// get gate period
//
SendDlgItemMessage(hDlg, IDC_GATEPERIOD, WM_GETTEXT, 13,
(LPARAM)(LPSTR)szBuffer) ;
gfGatePeriod = (float)atof(szBuffer);
SendDlgItemMessage(hDlg, IDC_UPCYCLE, WM_GETTEXT, 13,
(LPARAM)(LPSTR)szBuffer) ;
gfUpCycle = (float)atof(szBuffer);
EndDialog(hDlg, 0);
return TRUE;
case IDCANCEL :
EndDialog(hDlg, 0);
return TRUE;
case IDC_DEVICE :
//
// When device selection is changed, it needs to
// re-initialize sub-device combobox and input range
// combobox.
//
if (HIWORD(wParam) == CBN_SELCHANGE)
{
if ((dwIndex = SendDlgItemMessage(hDlg, IDC_DEVICE,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwDevice = (WORD)dwIndex;
else
return TRUE;
// ------------------------------------------------------
// Initialize Module Combobox for COM port or CAN devices
// ------------------------------------------------------
// check 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)
{
if ((ErrCde = DRV_DeviceGetSubList(
(DWORD)DeviceList[gwDevice].dwDeviceNum,
(DEVLIST far *)&SubDeviceList[0],
(SHORT)gnNumOfSubdevices,
(SHORT far *)&nOutEntries)) != (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));
for (i = 0; i < gnNumOfSubdevices; i++)
SendDlgItemMessage(hDlg, IDC_MODULE, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)SubDeviceList[i].szDeviceName));
gwSubDevice = 0;
SendDlgItemMessage(hDlg, IDC_MODULE, CB_SETCURSEL,
(WPARAM)gwSubDevice, (LPARAM)0);
}
else
{
EnableWindow(GetDlgItem(hDlg, IDC_MODULE), FALSE);
SendDlgItemMessage(hDlg, IDC_MODULE, CB_RESETCONTENT,
0, (LPARAM)((LPSTR)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 hWnd, // window handle
unsigned message, // type of message
WPARAM wParam, // additional information
LPARAM lParam // additional information
)
{
static HANDLE hInstance ;
HMENU hMenu;
HDC hdc;
char szBuffer[120];
RECT rect;
switch (message)
{
case WM_CREATE:
//
// initialize Stop Menu
//
hMenu = GetMenu(hWnd);
EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED);
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;
return 0 ;
case WM_COMMAND: /* message: from application menu */
hMenu = GetMenu(hWnd);
switch (LOWORD(wParam))
{
case IDM_SETTING :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_SETTING),
hWnd, lpfnConfigDlgProc) ;
return 0;
case IDM_STOP :
//
// counter reset
//
if ((ErrCde = DRV_CounterReset(DriverHandle,
(LPARAM)gwChannel)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg, "Driver Message", MB_OK);
}
DRV_DeviceClose((LONG far *)&DriverHandle);
bRun = FALSE;
//
// reset menu item status
//
EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(hMenu, IDM_START, MF_BYCOMMAND | MF_ENABLED);
return 0;
case IDM_START :
//
// 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)
{
strcpy(szErrMsg,"Device open error !");
MessageBox(hWnd,(LPCSTR)szErrMsg,"Device Open",MB_OK);
return 0;
}
//
// get number of counter channels
//
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;
}
// check number of counter channels
if (DevFeatures.usMaxTimerChl == 0)
{
MessageBox(hWnd,(LPCSTR)"No Counter Channel",
"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
//
// start counter
//
ptCounterPulseStart.counter = gwChannel;
//changping change
ptCounterPulseStart.period = 1/gfGatePeriod;
ptCounterPulseStart.UpCycle = ptCounterPulseStart.period/2;
//changping change end
ptCounterPulseStart.GateMode = gwGateMode;
if((ErrCde = DRV_CounterPulseStart(DriverHandle,
(LPT_CounterPulseStart)&ptCounterPulseStart)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg, "Driver Message", MB_OK);
return TRUE;
}
//
// enable Stop Menu item and disable the others
//
EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_ENABLED);
EnableMenuItem(hMenu, IDM_START, MF_BYCOMMAND | MF_GRAYED);
bRun = TRUE;
//
// display
//
hdc = GetDC(hWnd);
GetClientRect(hWnd, &rect);
sprintf(szBuffer, "Pulse Output Running ...... ");
DrawText(hdc, szBuffer, -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC(hWnd, hdc);
return 0;
}
return 0;
case WM_DESTROY:
if (bRun == TRUE)
{
// counter reset
if( (ErrCde = DRV_CounterReset(DriverHandle,
(LPARAM)gwChannel)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hWnd,(LPCSTR)szErrMsg, "Driver Message", MB_OK);
}
DRV_DeviceClose((LONG far *)&DriverHandle);
}
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return ((LONG)NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -