📄 dio_soft_dword.c
字号:
strcpy(szErrMsg,"Device close error !");
MessageBox(hDlg,(LPCSTR)szErrMsg,"Notice",MB_OK);
}
return TRUE;
}//case IDCANCEL
case IDC_WRITEWORDMASK:
{
EditLimitHexCharacter(hDlg, wParam);
SendDlgItemMessage(hDlg, IDC_WRITEWORDMASK, EM_LIMITTEXT, 4, 0);
break;
}
case IDC_WRITEDWORDMASK:
{
EditLimitHexCharacter(hDlg, wParam);
SendDlgItemMessage(hDlg, IDC_WRITEDWORDMASK, EM_LIMITTEXT, 8, 0);
break;
}
case IDC_WRITEWORD:
{
// get output byte value
glDoState = 0;
for (i = 0; i < 16; i++)
{
if ( IsDlgButtonChecked( hDlg, (IDC_D0 + i) ) > 0 )
glDoState = glDoState + (0x1<<i);
}
// get output mask.
SendDlgItemMessage( hDlg,
IDC_WRITEWORDMASK,
WM_GETTEXT,
16,
( LPARAM )( ( LPSTR )szBuffer ) );
gwWriteMask = ( USHORT )strtoul(
szBuffer,
&pchar,
16 );
// output word
ptDioWritePortWord.port = gwPort;
ptDioWritePortWord.mask = gwWriteMask;
ptDioWritePortWord.state = (USHORT)( glDoState & 0xffff);
ErrCde = DRV_DioWritePortWord(
DriverHandle,
(LPT_DioWritePortWord)&ptDioWritePortWord);
if ( ErrCde != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
}//case IDC_WRITEWORD
case IDC_WRITEDWORD:
{
// get output byte value
glDoState = 0;
for (i = 0; i < 32; i++)
{
if (IsDlgButtonChecked(hDlg, (IDC_D0 + i)) > 0)
glDoState = glDoState | (0x1<<i);
}
// get output mask.
SendDlgItemMessage(
hDlg,
IDC_WRITEDWORDMASK,
WM_GETTEXT,
16,
( LPARAM )( ( LPSTR )szBuffer ) );
glWriteMask = strtoul( szBuffer,
&pchar,
16 );
// output DWord
ptDioWritePortDword.port = gwPort;
ptDioWritePortDword.mask = glWriteMask;
ptDioWritePortDword.state = glDoState;
ErrCde = DRV_DioWritePortDword(
DriverHandle,
(LPT_DioWritePortDword)&ptDioWritePortDword);
if ( ErrCde != 0 )
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
}//case IDC_WRITEDWORD
case IDC_READWORD:
{
// read port word
ptDioReadPortWord.port = gwPort;
ptDioReadPortWord.ValidChannelMask = ( USHORT far * )&gwValidMask;
ptDioReadPortWord.value = ( USHORT far * )&gwDiValue;
ErrCde = DRV_DioReadPortWord(
DriverHandle,
(LPT_DioReadPortWord)&ptDioReadPortWord);
if ( ErrCde != 0 )
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
// display the value
sprintf(szBuffer,"%X",gwDiValue);
SendDlgItemMessage(
hDlg,
IDC_WORDDATA,
WM_SETTEXT,
0,
(LPARAM)((LPSTR)szBuffer));
// display the valid mask.
sprintf(szBuffer,"%X", gwValidMask);
SendDlgItemMessage(
hDlg,
IDC_READWORDMASK,
WM_SETTEXT,
0,
(LPARAM)((LPSTR)szBuffer));
return TRUE;
} //case IDC_READWORD
case IDC_READDWORD:
{
// read port DWord
ptDioReadPortDword.port = gwPort;
ptDioReadPortDword.ValidChannelMask = ( ULONG far * )&glValidMask;
ptDioReadPortDword.value = ( ULONG far * )&glDiValue;
ErrCde = DRV_DioReadPortDword(
DriverHandle,
( LPT_DioReadPortDword )&ptDioReadPortDword );
if( ErrCde != 0 )
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
// display the value
sprintf(szBuffer,"%X",glDiValue);
SendDlgItemMessage( hDlg,
IDC_DWORDDATA,
WM_SETTEXT,
0,
( LPARAM )( ( LPSTR )szBuffer ) );
// display the valid mask.
sprintf(szBuffer,"%X", glValidMask);
SendDlgItemMessage( hDlg,
IDC_READDWORDMASK,
WM_SETTEXT,
0,
( LPARAM )( ( LPSTR )szBuffer ) );
return TRUE;
}//case IDC_READDWORD
case IDC_GETDOWORD:
{
//Get current DO word
ptDioGetCurrentDOWord.port = gwPort;
ptDioGetCurrentDOWord.ValidChannelMask = ( USHORT far * )&gwValidMask;
ptDioGetCurrentDOWord.value = ( USHORT far * )&gwGetDOValue;
ErrCde = DRV_DioGetCurrentDOWord(
DriverHandle,
( LPT_DioGetCurrentDOWord )&ptDioGetCurrentDOWord );
if ( ErrCde != 0 )
{
DRV_GetErrorMessage( ErrCde, ( LPSTR )szErrMsg );
MessageBox( hDlg, ( LPCSTR )szErrMsg, "Driver Message", MB_OK );
return 0;
}
//Display current DO word value
sprintf(szBuffer,"%X", gwGetDOValue);
SendDlgItemMessage( hDlg,
IDC_GETDOWORDVALUE,
WM_SETTEXT,
0,
( LPARAM )( ( LPSTR )szBuffer ) );
//Display current DO word valid mask
sprintf(szBuffer,"%X", gwValidMask);
SendDlgItemMessage( hDlg,
IDC_GETDOWORDMASK,
WM_SETTEXT,
0,
( LPARAM )( ( LPSTR )szBuffer ) );
return TRUE;
}//case IDC_GETDOWORD
case IDC_GETDODWORD:
{
//Get current DO word
ptDioGetCurrentDODword.port = gwPort;
ptDioGetCurrentDODword.ValidChannelMask = ( ULONG far * )&glValidMask;
ptDioGetCurrentDODword.value = ( ULONG far * )&glGetDOValue;
ErrCde = DRV_DioGetCurrentDODword(
DriverHandle,
( LPT_DioGetCurrentDODword )&ptDioGetCurrentDODword );
if ( ErrCde != 0 )
{
DRV_GetErrorMessage( ErrCde, ( LPSTR )szErrMsg );
MessageBox( hDlg, ( LPCSTR )szErrMsg, "Driver Message", MB_OK );
return 0;
}
//Display current DO word value
sprintf(szBuffer,"%X", glGetDOValue);
SendDlgItemMessage( hDlg,
IDC_GETDODWORDVALUE,
WM_SETTEXT,
0,
( LPARAM )( ( LPSTR )szBuffer ) );
//Display current DO word valid mask
sprintf(szBuffer,"%X", glValidMask);
SendDlgItemMessage( hDlg,
IDC_GETDODWORDMASK,
WM_SETTEXT,
0,
( LPARAM )( ( LPSTR )szBuffer ) );
return TRUE;
}//case IDC_GETDODWORD
} //switch (LOWORD(wParam))
break;
}//case WM_COMMAND
}//switch (message)
return FALSE ;
} // RunDlgProc
//*****************************************************************************
// 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,
(DLGPROC)lpfnConfigDlgProc) ;
return 0;
case IDM_RUN :
DialogBox (
hInstance,
MAKEINTRESOURCE(IDD_RUN),
hWnd,
(DLGPROC)lpfnRunDlgProc) ;
return 0;
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
{
return (DefWindowProc(hWnd, message, wParam, lParam));
}
}
return ((LONG)NULL);
}
//------------------------------------------------------------------
// Function: Filter the key strokes that allow to display on edit
// control.
// This subroutine allows the 0-9, A-F characters.
// Paramater: hDlg, IN, dialog box handle
// wParam, IN, WPARAM along with windows message.
// return: none
//------------------------------------------------------------------
void EditLimitHexCharacter(HWND hDlg, WPARAM wParam)
{
char szOneLine[64];
DWORD dwStart, dwStop;
SendDlgItemMessage(hDlg, LOWORD(wParam), EM_GETSEL, (WPARAM)(&dwStart), (LPARAM)(&dwStop));
*(USHORT*)szOneLine = sizeof(szOneLine);
SendDlgItemMessage(hDlg, LOWORD(wParam), EM_GETLINE, 0, (LPARAM)szOneLine);
// Get new added character index
if( dwStart)
dwStart--;
else
//No character on buffer
return;
//Check go through characters
if( ('0' <= szOneLine[dwStart] && szOneLine[dwStart] <= '9') ||
('A' <= szOneLine[dwStart] && szOneLine[dwStart] <= 'F') ||
('a' <= szOneLine[dwStart] && szOneLine[dwStart] <= 'f'))
return;
//Delete this character.
SendDlgItemMessage(hDlg, LOWORD(wParam), EM_SETSEL, (WPARAM)(dwStart), dwStop);
szOneLine[0] = '\0';
SendDlgItemMessage(hDlg, LOWORD(wParam), EM_REPLACESEL, FALSE, (LPARAM)szOneLine);
}//EditLimitHexCharacter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -