📄 do_soft_wddlg.cpp
字号:
DRV_GetErrorMessage(m_ErrCde,(LPSTR)m_szErrMsg);
MessageBox((LPCSTR)m_szErrMsg,"Driver Message",MB_OK);
}
}
void CDO_SOFT_WDDlg::OnReadback()
{
// TODO: Add your control notification handler code here
static PT_DioGetCurrentDOByte ptDioGetCurrentDOByte;
USHORT chValue;
ptDioGetCurrentDOByte.port = m_Port;
ptDioGetCurrentDOByte.value = (USHORT far *)&chValue;
if((m_ErrCde = DRV_DioGetCurrentDOByte(m_DriverHandle,
(LPT_DioGetCurrentDOByte)&ptDioGetCurrentDOByte)) != 0)
{
DRV_GetErrorMessage(m_ErrCde,(LPSTR)m_szErrMsg);
MessageBox((LPCSTR)m_szErrMsg,"Driver Message",MB_OK);
}
m_IDI00 = chValue & 0x1;
m_IDI01 = (chValue>>1) & 0x1;
m_IDI02 = (chValue>>2) & 0x1;
m_IDI03 = (chValue>>3) & 0x1;
m_IDI04 = (chValue>>4) & 0x1;
m_IDI05 = (chValue>>5) & 0x1;
m_IDI06 = (chValue>>6) & 0x1;
m_IDI07 = (chValue>>7) & 0x1;
UpdateData(FALSE);
CString szTemp;
szTemp.Format( "%02X", chValue );
SetDlgItemText( IDC_PORTVALUE, szTemp );
}
void CDO_SOFT_WDDlg::OnStart()
{
// TODO: Add your control notification handler code here
UpdateData();
static PT_EnableEvent ptEnableEvent; // Enable event
DRV_DeviceSetProperty( m_DriverHandle, CFG_WatchdogCounter, &m_WatchdogCounter,sizeof(ULONG) );
m_Start.EnableWindow(FALSE);
m_Stop.EnableWindow(TRUE);
if( m_AutoFeed )
m_TimerEventID=timeSetEvent(m_FeedTimer, 1, FeedWatchdogPorc,
m_DriverHandle, TIME_PERIODIC);
ptEnableEvent.EventType = ADS_EVT_WATCHDOG_OVERRUN;
ptEnableEvent.Enabled = 1;
ptEnableEvent.Count = 1;
if ((m_ErrCde = DRV_EnableEvent(m_DriverHandle,
(LPT_EnableEvent)&ptEnableEvent)) != 0)
{
DRV_GetErrorMessage(m_ErrCde,(LPSTR)m_szErrMsg);
MessageBox((LPCSTR)m_szErrMsg,"Driver Message",MB_OK);
}
pThreadObject = AfxBeginThread( CDO_SOFT_WDDlg::EventThread, this,
THREAD_PRIORITY_NORMAL, 0, 0, NULL );
SetDlgItemText( IDC_INT_COUNT, "" );
if (m_ErrCde = DRV_WatchdogStart( m_DriverHandle,NULL ) !=0)
{
DRV_GetErrorMessage(m_ErrCde,(LPSTR)m_szErrMsg);
MessageBox((LPCSTR)m_szErrMsg,"Driver Message",MB_OK);
}
m_WatchdogRun=TRUE;
}
void CALLBACK FeedWatchdogPorc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1,DWORD dw2)
{
DRV_WatchdogFeed( dwUser );
}
UINT CDO_SOFT_WDDlg::EventThread(LPVOID ThreadArg)
{
PT_CheckEvent ptCheckEvent;
USHORT usEventType;
CString szTemp;
CDO_SOFT_WDDlg *pDlg= (CDO_SOFT_WDDlg *)ThreadArg;
ptCheckEvent.EventType = &usEventType;
ptCheckEvent.Milliseconds = INFINITE;
while (TRUE)
{
if (DRV_CheckEvent( pDlg->m_DriverHandle, &ptCheckEvent ) == SUCCESS)
{
if (usEventType == ADS_EVT_WATCHDOG_OVERRUN )
{
pDlg->SetDlgItemText( IDC_INT_COUNT, "Overflow" );
}
}
}
}
void CDO_SOFT_WDDlg::OnStop()
{
// TODO: Add your control notification handler code here
DWORD dwExitCode;
if(pThreadObject)
{
GetExitCodeThread(pThreadObject->m_hThread, &dwExitCode );
if( dwExitCode == STILL_ACTIVE )
TerminateThread( pThreadObject->m_hThread, dwExitCode );
}
m_Start.EnableWindow(TRUE);
m_Stop.EnableWindow(FALSE);
if (m_ErrCde = DRV_WatchdogStop( m_DriverHandle ) !=0)
{
DRV_GetErrorMessage(m_ErrCde,(LPSTR)m_szErrMsg);
MessageBox((LPCSTR)m_szErrMsg,"Driver Message",MB_OK);
}
timeKillEvent(m_TimerEventID);
PT_EnableEvent EventSetting;
EventSetting.EventType = ADS_EVT_WATCHDOG_OVERRUN;
EventSetting.Enabled = FALSE;
EventSetting.Count = 1;
m_ErrCde = DRV_EnableEvent( m_DriverHandle, &EventSetting );
m_WatchdogRun = FALSE;
}
void CDO_SOFT_WDDlg::OnFeed()
{
// TODO: Add your control notification handler code here
if (m_ErrCde = DRV_WatchdogFeed( m_DriverHandle ) !=0)
{
DRV_GetErrorMessage(m_ErrCde,(LPSTR)m_szErrMsg);
MessageBox((LPCSTR)m_szErrMsg,"Driver Message",MB_OK);
}
}
void CDO_SOFT_WDDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}
void CDO_SOFT_WDDlg::OnSetvalue()
{
// TODO: Add your control notification handler code here
CString szTemp;
char *p;
USHORT usValue;
for(int i = 0; i < 8; i++ )
{
GetDlgItemText( IDC_PRESET0 +i, szTemp);
usValue = (USHORT)strtoul(szTemp, &p, 16);
m_DOPresetValue[2*i] = usValue & 0xFF;
m_DOPresetValue[2*i+1] = (usValue>>8) & 0xFF;
}
for( i = 0; i < 8; i++ )
{
GetDlgItemText( IDC_WATCHDOGVALUE0 +i,szTemp);
usValue = (USHORT)strtoul(szTemp, &p, 16);
m_DOWatchdogValue[2*i] = usValue & 0xFF;
m_DOWatchdogValue[2*i+1] = (usValue>>8) & 0xFF;
}
ULONG ulDataLength = sizeof(BYTE) *16 ;
DRV_DeviceSetProperty( m_DriverHandle, CFG_DoPresetValue, m_DOPresetValue ,ulDataLength);
DRV_DeviceSetProperty( m_DriverHandle, CFG_DoWatchdogValue, m_DOWatchdogValue , ulDataLength );
}
void CDO_SOFT_WDDlg::OnAutoFeed()
{
// TODO: Add your control notification handler code here
UpdateData();
if(!m_WatchdogRun)
return;
if( m_AutoFeed )
m_TimerEventID=timeSetEvent(m_FeedTimer, 1, FeedWatchdogPorc,
m_DriverHandle, TIME_PERIODIC);
else
{
timeKillEvent(m_TimerEventID);
}
}
void CDO_SOFT_WDDlg::OnChangeWatchdogcounter()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
UpdateData();
CString szTemp;
szTemp.Format( "%0.1f", m_WatchdogCounter/10000.0);
SetDlgItemText( IDC_TIMER, szTemp);
// TODO: Add your control notification handler code here
}
//------------------------------------------------------------------
// 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
BOOL CDO_SOFT_WDDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch ( LOWORD( wParam ))
{
case IDC_PRESET0:
case IDC_PRESET1:
case IDC_PRESET2:
case IDC_PRESET3:
case IDC_PRESET4:
case IDC_PRESET5:
case IDC_PRESET6:
case IDC_PRESET7:
if( HIWORD(wParam) == EN_SETFOCUS)
{
// Select all data on first time get focus
::SendDlgItemMessage(m_hWnd, LOWORD(wParam), EM_SETSEL, 0, (LPARAM)-1);
}
else if( HIWORD(wParam) == EN_CHANGE )
{
//Filter Hex charatcters.
EditLimitHexCharacter(m_hWnd, wParam);
// Set focus to next edit control
if(::SendDlgItemMessage(m_hWnd, LOWORD(wParam), EM_LINELENGTH, 0, 0) >= 4
&& LOWORD( wParam ) < IDC_PRESET7 )
GetDlgItem(LOWORD(wParam)+1)->SetFocus();
}
break;
case IDC_WATCHDOGVALUE0:
case IDC_WATCHDOGVALUE1:
case IDC_WATCHDOGVALUE2:
case IDC_WATCHDOGVALUE3:
case IDC_WATCHDOGVALUE4:
case IDC_WATCHDOGVALUE5:
case IDC_WATCHDOGVALUE6:
case IDC_WATCHDOGVALUE7:
if( HIWORD(wParam) == EN_SETFOCUS)
{
// Select all data on first time get focus
::SendDlgItemMessage(m_hWnd, LOWORD(wParam), EM_SETSEL, 0, (LPARAM)-1);
}
else if( HIWORD(wParam) == EN_CHANGE )
{
//Filter Hex charatcters.
EditLimitHexCharacter(m_hWnd, wParam);
// Set focus to next edit control
if(::SendDlgItemMessage(m_hWnd, LOWORD(wParam), EM_LINELENGTH, 0, 0) >= 4
&& LOWORD( wParam ) < IDC_WATCHDOGVALUE7 )
GetDlgItem(LOWORD(wParam)+1)->SetFocus();
}
break;
default:
break;
}
return CDialog::OnCommand(wParam, lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -