📄 alarm.c
字号:
(LPARAM)((LPSTR)0));
for (i = 0; i < gnNumOfSubdevices; i++)
SendDlgItemMessage(hDlg, IDC_MODULE, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)SubDeviceList[i].szDeviceName));
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));
}
// ------------------------------------------------------------
// Initialize Channel Edit, it needs to get device
// features for alarm channels
// ------------------------------------------------------------
// first : 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(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
// second: 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;
}
// third: initialize Channel Edit with device features
if (DevFeatures.usMaxAlarmChl != 0)
{
EnableWindow(GetDlgItem(hDlg, IDC_ECHANNEL), TRUE);
itoa(gwChannel, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_ECHANNEL, WM_SETTEXT, 0,
(LPARAM)((LPSTR)szBuffer));
}
else
EnableWindow(GetDlgItem(hDlg, IDC_ECHANNEL), FALSE);
// fourth: close device
DRV_DeviceClose((LONG far *)&DriverHandle);
// ------------------------------------------------------------
// Initialize Alarm Limit Edit
// ------------------------------------------------------------
sprintf(szBuffer, "%6.3f", gfLoLimit);
SendDlgItemMessage(hDlg, IDC_LOW, WM_SETTEXT, 0,
(LPARAM)((LPSTR)szBuffer));
sprintf(szBuffer, "%6.3f", gfHiLimit);
SendDlgItemMessage(hDlg, IDC_HIGH, WM_SETTEXT, 0,
(LPARAM)((LPSTR)szBuffer));
// ------------------------------------------------------------
// Initialize Latching Mode Radio Button
// ------------------------------------------------------------
CheckRadioButton(hDlg, IDC_LATCH, IDC_MOMENTARY,
(gwLatchMode==1)?IDC_MOMENTARY:IDC_LATCH);
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
//
SendDlgItemMessage(hDlg, IDC_ECHANNEL, WM_GETTEXT, 10,
(LPARAM)(LPSTR)szBuffer) ;
gwChannel = atoi(szBuffer);
//
// get alarm limit
//
SendDlgItemMessage(hDlg, IDC_LOW, WM_GETTEXT, 10,
(LPARAM)(LPSTR)szBuffer) ;
gfLoLimit = (float)atof(szBuffer);
SendDlgItemMessage(hDlg, IDC_HIGH, WM_GETTEXT, 10,
(LPARAM)(LPSTR)szBuffer) ;
gfHiLimit = (float)atof(szBuffer);
//
// get latching mode
//
if (IsDlgButtonChecked(hDlg, IDC_LATCH))
gwLatchMode = 0; // latch mode
else
gwLatchMode = 1; // momentary mode
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));
}
// -------------------------------------------------
// Initialize Input Range List Combobox, it needs to
// get device features for gain list
// -------------------------------------------------
// first : Open Device
// for non COM port or CAN device
if (gnNumOfSubdevices == 0)
{
ErrCde = DRV_DeviceOpen(
DeviceList[gwDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
// for COM port or CAN device
else
{
ErrCde = DRV_DeviceOpen(
SubDeviceList[gwSubDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
if (ErrCde != SUCCESS)
{
strcpy(szErrMsg,"Device open error !");
MessageBox(hMainWnd, (LPCSTR)szErrMsg,
"Driver Message", MB_OK);
return 0;
}
// second: 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;
}
// third: initialize Channel Edit with device features
if (DevFeatures.usMaxAlarmChl != 0)
EnableWindow(GetDlgItem(hDlg, IDC_ECHANNEL), TRUE);
else
EnableWindow(GetDlgItem(hDlg, IDC_ECHANNEL), FALSE);
// fourth: close device
DRV_DeviceClose((LONG far *)&DriverHandle);
}
return TRUE;
}
break;
}
return FALSE ;
}
/***************************************************************************
FUNCTION: ScanDlgProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes dialog box messages for scan time settings
****************************************************************************/
BOOL FTYPE ScanDlgProc
(
HWND hDlg, // window handle
unsigned message, // type of message
WPARAM wParam, // additional information
LPARAM lParam // additional information
)
{
char szBuffer[40];
switch (message)
{
case WM_INITDIALOG :
// ---------------------------------------------------
// Initialize Scan Time Edit, Maximum accuracy: 40 ms
// ---------------------------------------------------
itoa(gwScanTime, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_SCAN, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -