📄 digout.c
字号:
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: RunDlgProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes dialog box messages for IDD_RUN
****************************************************************************/
BOOL FTYPE RunDlgProc
(
HWND hDlg, // window handle
unsigned message, // type of message
WPARAM wParam, // additional information
LPARAM lParam // additional information
)
{
int i;
DWORD dwIndex;
char szBuffer[40];
switch (message)
{
case WM_INITDIALOG :
// --------------------------------
// Initialize Output Bit Combobox
// --------------------------------
for (i = 0; i < 8; i ++)
{
_itoa(i, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_OUTBIT, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)szBuffer));
}
_itoa(gwOutBit, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_OUTBIT, CB_SELECTSTRING,(WPARAM)(-1),
(LPARAM)((LPSTR)szBuffer));
// -----------------------------------------
// Initialize Output Byte Value Check Button
// -----------------------------------------
CheckDlgButton(hDlg, IDC_D0, (gwData & 0x1));
CheckDlgButton(hDlg, IDC_D1, (gwData & 0x2));
CheckDlgButton(hDlg, IDC_D2, (gwData & 0x4));
CheckDlgButton(hDlg, IDC_D3, (gwData & 0x8));
CheckDlgButton(hDlg, IDC_D4, (gwData & 0x10));
CheckDlgButton(hDlg, IDC_D5, (gwData & 0x20));
CheckDlgButton(hDlg, IDC_D6, (gwData & 0x40));
CheckDlgButton(hDlg, IDC_D7, (gwData & 0x80));
//
// 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(hDlg,(LPCSTR)szErrMsg,"Notice",MB_OK);
return 0;
}
return TRUE;
case WM_COMMAND :
switch (LOWORD(wParam))
{
case IDCANCEL :
//
// close device
//
DRV_DeviceClose((LONG far *)&DriverHandle);
EndDialog(hDlg, 0);
return TRUE;
case IDC_WRITEBYTE :
//
// get output byte value
//
if (IsDlgButtonChecked(hDlg, IDC_D0) > 0)
gwData = 1;
else
gwData = 0;
if (IsDlgButtonChecked(hDlg, IDC_D1) > 0)
gwData += 0x2;
if (IsDlgButtonChecked(hDlg, IDC_D2) > 0)
gwData += 0x4;
if (IsDlgButtonChecked(hDlg, IDC_D3) > 0)
gwData += 0x8;
if (IsDlgButtonChecked(hDlg, IDC_D4) > 0)
gwData += 0x10;
if (IsDlgButtonChecked(hDlg, IDC_D5) > 0)
gwData += 0x20;
if (IsDlgButtonChecked(hDlg, IDC_D6) > 0)
gwData += 0x40;
if (IsDlgButtonChecked(hDlg, IDC_D7) > 0)
gwData += 0x80;
//
// output byte
//
ptDioWritePortByte.port = gwChannel;
ptDioWritePortByte.mask = gwMask;
ptDioWritePortByte.state = gwData;
if((ErrCde = DRV_DioWritePortByte(DriverHandle,
(LPT_DioWritePortByte)&ptDioWritePortByte)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
case IDC_WRITEBIT :
//
// get output byte value
//
if (IsDlgButtonChecked(hDlg, IDC_D0) > 0)
gwData = 1;
else
gwData = 0;
if (IsDlgButtonChecked(hDlg, IDC_D1) > 0)
gwData += 0x2;
if (IsDlgButtonChecked(hDlg, IDC_D2) > 0)
gwData += 0x4;
if (IsDlgButtonChecked(hDlg, IDC_D3) > 0)
gwData += 0x8;
if (IsDlgButtonChecked(hDlg, IDC_D4) > 0)
gwData += 0x10;
if (IsDlgButtonChecked(hDlg, IDC_D5) > 0)
gwData += 0x20;
if (IsDlgButtonChecked(hDlg, IDC_D6) > 0)
gwData += 0x40;
if (IsDlgButtonChecked(hDlg, IDC_D7) > 0)
gwData += 0x80;
//
// get output bit
//
if ((dwIndex = SendDlgItemMessage(hDlg, IDC_OUTBIT,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwOutBit = (WORD)dwIndex;
else
return TRUE;
//
// output bit
//
ptDioWriteBit.port = gwChannel;
ptDioWriteBit.bit = gwOutBit;
if ((gwData & (1 << gwOutBit)))
ptDioWriteBit.state = 1;
else
ptDioWriteBit.state = 0;
if((ErrCde = DRV_DioWriteBit(DriverHandle,
(LPT_DioWriteBit)&ptDioWriteBit)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
case IDC_READBACK :
//
// get current DO byte
//
ptDioGetCurrentDOByte.port = gwChannel;
ptDioGetCurrentDOByte.value = (USHORT far *)&gwDoState;
if((ErrCde = DRV_DioGetCurrentDOByte(DriverHandle,
(LPT_DioGetCurrentDOByte)&ptDioGetCurrentDOByte)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
//
// display the value in Output State Edit
//
_itoa(gwDoState, szBuffer, 16);
SendDlgItemMessage(hDlg, IDC_STATUS, WM_SETTEXT, 0,
(LPARAM)((LPSTR)szBuffer));
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 ;
switch (message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;
lpfnRunDlgProc = MakeProcInstance (RunDlgProc, hInstance) ;
return 0 ;
case WM_COMMAND: // message: from application menu
switch (LOWORD(wParam))
{
case IDM_SETTING :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_SETTING),
hWnd, lpfnConfigDlgProc) ;
return 0;
case IDM_RUN :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_RUN),
hWnd, lpfnRunDlgProc) ;
return 0;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return ((LONG)NULL);
}
WORD CvtHex(char *str)
{
char temp;
WORD data = 0;
int i;
for(i = 0; i < 4; ++i)
{
temp = str[i];
if(temp == 0) break;
if(temp == ' ') continue;
data <<= 4;
if(temp >= '0' && temp <= '9') {
data |= (temp - '0');
}
else if(temp >= 'a' && temp <= 'f') {
data |= (temp - 'a') + 10;
str[i] = temp - 'a' + 'A';
}
else if(temp >= 'A' && temp <= 'F') {
data |= (temp - 'A') + 10;
}
else {
break;
}
}
return(data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -