📄 cntintdlg.cpp
字号:
}
void CCntIntDlg::OnChkintoverflow()
{
// TODO: Add your control notification handler code here
//int counter;
int offset;
//counter = m_comboCnt.GetCurSel();
offset = 7 + m_nCounter;
SetInterruptValue(IDC_CHKINTOVERFLOW,offset);
}
void CCntIntDlg::OnChklock()
{
// TODO: Add your control notification handler code here
//int counter;
//counter = m_comboCnt.GetCurSel();
m_baOverflowLock[m_nCounter] = !m_baOverflowLock[m_nCounter];
gConfig833.CounterConfig[m_nCounter].counter = m_nCounter;
gConfig833.CounterConfig[m_nCounter].LatchOverflow = m_baOverflowLock[m_nCounter];
}
void CCntIntDlg::OnChkresetlatch()
{
// TODO: Add your control notification handler code here
//int counter;
//counter = m_comboCnt.GetCurSel();
m_baResetCounterAfterLatch[m_nCounter] = !m_baResetCounterAfterLatch[m_nCounter];
gConfig833.CounterConfig[m_nCounter].counter = m_nCounter;
gConfig833.CounterConfig[m_nCounter].ResetOnLatch = m_baResetCounterAfterLatch[m_nCounter];
}
void CCntIntDlg::OnChkresetvalue()
{
// TODO: Add your control notification handler code here
//int counter;
//counter = m_comboCnt.GetCurSel();
m_baResetValueTo0x8[m_nCounter] = !m_baResetValueTo0x8[m_nCounter];
gConfig833.CounterConfig[m_nCounter].counter = m_nCounter;
gConfig833.CounterConfig[m_nCounter].ResetValue = m_baResetValueTo0x8[m_nCounter];
}
void CCntIntDlg::OnSelchangeCounter()
{
// TODO: Add your control notification handler code here
CString str;
m_nCounter = m_comboCnt.GetCurSel();
ResetCounterConfig(m_nCounter);
str.Format("Reset Counter %d",m_nCounter+1);
GetDlgItem(IDC_BTNRESETCOUNTER)->SetWindowText(str);
}
void CCntIntDlg::OnSelchangeInputMode()
{
// TODO: Add your control notification handler code here
//int counter;
//m_nCounter = m_comboCnt.GetCurSel();
gConfig833.CountStart[m_nCounter].counter = m_nCounter;
gConfig833.CountStart[m_nCounter].InputMode = m_comboInputMode.GetCurSel();
}
void CCntIntDlg::OnSelchangeLatchSource()
{
// TODO: Add your control notification handler code here
//int counter;
//counter = m_comboCnt.GetCurSel();
gConfig833.CounterConfig[m_nCounter].counter = m_nCounter;
gConfig833.CounterConfig[m_nCounter].LatchSrc = m_comboLatchSource.GetCurSel();
}
void CCntIntDlg::OnRddi1()
{
// TODO: Add your control notification handler code here
SetInterruptValue(IDC_RDDI1,1);
}
void CCntIntDlg::OnRdtimer()
{
// TODO: Add your control notification handler code here
SetInterruptValue(IDC_RDTIMER,0);
}
void CCntIntDlg::SetInterruptValue(int nID, int nOffset)
{
int bCheck;
USHORT usMask;
bCheck = ((CButton*)GetDlgItem(nID))->GetCheck();
m_usInterrupt &= 0x03ff;
usMask = 0x03ff & (~(0x0001<<nOffset));
if (bCheck == BST_CHECKED)
{
m_usInterrupt |= (0x0001<<nOffset);
}
if (bCheck == BST_UNCHECKED)
{
m_usInterrupt &= usMask;
}
gConfig833.usInterrupt = m_usInterrupt;
}
void CCntIntDlg::OnSelchangeCmbsymclock()
{
// TODO: Add your control notification handler code here
gConfig833.CounterConfigSys.SysClock = m_comboSystemLock.GetCurSel();
}
void CCntIntDlg::OnSelchangeCmbcascade()
{
// TODO: Add your control notification handler code here
gConfig833.CounterConfigSys.CascadeMode = m_comboCascade.GetCurSel();
}
void CCntIntDlg::ResetCounterConfig(int counter)
{
USHORT usMaskFlow,usMaskIn;
//Reset counter UI according to last setting
m_baOverflowLock[counter] = gConfig833.CounterConfig[counter].LatchOverflow;
m_baResetCounterAfterLatch[counter] = gConfig833.CounterConfig[counter].ResetOnLatch;
m_baResetValueTo0x8[counter] = gConfig833.CounterConfig[counter].ResetValue;
m_comboLatchSource.SetCurSel(gConfig833.CounterConfig[counter].LatchSrc);
m_comboInputMode.SetCurSel(gConfig833.CountStart[counter].InputMode);
((CButton*)GetDlgItem(IDC_CHKLOCK))->SetCheck(m_baOverflowLock[counter]);
((CButton*)GetDlgItem(IDC_CHKRESETLATCH))->SetCheck(m_baResetCounterAfterLatch[counter]);
((CButton*)GetDlgItem(IDC_CHKRESETVALUE))->SetCheck(m_baResetValueTo0x8[counter]);
usMaskFlow = 1 << (counter + 7);
usMaskIn = 1 << (counter + 4);
((CButton*)GetDlgItem(IDC_CHKINTOVERFLOW))->SetCheck(gConfig833.usInterrupt & usMaskFlow);
((CButton*)GetDlgItem(IDC_CHKINTINDEX))->SetCheck(gConfig833.usInterrupt & usMaskIn);
}
void CCntIntDlg::OnChkdi0()
{
// TODO: Add your control notification handler code here
SetInterruptValue(IDC_CHKDI0,3);
}
void CCntIntDlg::UpdateContentConfig()
{
int i;
for(i = 0; i < COUNT_NUMBER ; i++)
{
strConfigContent[i][2].Format("%s",szInputMode[gConfig833.CountStart[i].InputMode]);
strConfigContent[i][3].Format("%s",szLatchSource[gConfig833.CounterConfig[i].LatchSrc]);
m_listCnt.SetItemText(i,2,strConfigContent[i][2]);
m_listCnt.SetItemText(i,3,strConfigContent[i][3]);
}
}
void CCntIntDlg::OnBtnEnable()
{
// TODO: Add your control notification handler code here
int i;
DWORD dwRet;
USHORT usMaskFlow,usMaskIn;
PT_EnableEvent enableEvent;
if (gConfig833.usInterrupt != 0)
{
enableEvent.Enabled = TRUE;
//Enable overflow and indexin event
for(i = 0;i < COUNT_NUMBER; i++)
{
usMaskFlow = 1 << (i + 7);
usMaskIn = 1 << (i + 4);
if (gConfig833.usInterrupt & usMaskFlow)
{
enableEvent.EventType = ADS_EVT_OVERFLOW_CNT0 + i;
dwRet = DRV_EnableEvent(m_DriverHandle,&enableEvent);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
DRV_DeviceClose(&m_DriverHandle);
return;
}
}
if (gConfig833.usInterrupt & usMaskIn)
{
enableEvent.EventType = ADS_EVT_INDEX_CNT0 + i;
dwRet = DRV_EnableEvent(m_DriverHandle,&enableEvent);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
DRV_DeviceClose(&m_DriverHandle);
}
}
}
//Enable DI0
if (gConfig833.usInterrupt & 0x8)
{
enableEvent.EventType = ADS_EVT_INTERRUPT_IDI0;
dwRet = DRV_EnableEvent(m_DriverHandle,&enableEvent);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
DRV_DeviceClose(&m_DriverHandle);
}
}
//Enable DI1
if ((gConfig833.usInterrupt & 0x4)
&& (gConfig833.usInterrupt & 0x2))
{
enableEvent.EventType = ADS_EVT_INTERRUPT_IDI1;
dwRet = DRV_EnableEvent(m_DriverHandle,&enableEvent);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
DRV_DeviceClose(&m_DriverHandle);
}
}
}
////////////////////////////////////
// create a thread to check event
pThread_Par.DeviceHandle = m_DriverHandle;
pThread_Par.hWnd = GetSafeHwnd();
hThread = CreateThread(0, 0,
(LPTHREAD_START_ROUTINE)UserThread,
this,
CREATE_SUSPENDED,
&dwThreadID);
if (hThread == (HANDLE)NULL)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
DRV_DeviceClose(&m_DriverHandle);
return;
}
// resume the thread to wait for event
gbThreadRun = TRUE;
ResumeThread(hThread);
for (i = 0; i < COUNT_NUMBER; i++)
{
// if any counter is run, set timer run
if (gConfig833.CountStart[i].InputMode != DISABLE)
{
if (SetTimer(1, 50, NULL) == (UINT)NULL)
{
uShowMsg(GetSafeHwnd(), IDS_ERR_TIMER, IDS_TITLE);
// terminate thread
if (hThread)
{
StopThread();
}
DRV_DeviceClose(&m_DriverHandle);
return;
}
break;
}
}
((CButton*)GetDlgItem(IDC_BTN_ENABLE))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_BTN_DISABLE))->EnableWindow(TRUE);
((CButton*)GetDlgItem(IDOK))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_BTN_CONFIG))->EnableWindow(FALSE);
}
DWORD UserThread(LPVOID lpPara)
{
PT_CheckEvent pCheckEvent ;
DWORD dwRet;
USHORT uEventType = 0;
DWORD dwCountDI0 = 0,dwCountDI1 = 0;
DWORD dwOverFlow[COUNT_NUMBER],dwIndexIn[COUNT_NUMBER];
char szCount[20];
pCheckEvent.Milliseconds = INFINITE; // 5000;
pCheckEvent.EventType = &uEventType;
for(int i = 0;i < COUNT_NUMBER ; i++)
{
dwOverFlow[i] = 0;
dwIndexIn[i] = 0;
}
CCntIntDlg* pCntIntDlg = (CCntIntDlg*) lpPara;
while (gbThreadRun)
{
gbRunning = TRUE;
dwRet = DRV_CheckEvent(pThread_Par.DeviceHandle, &pCheckEvent);
gbRunning = FALSE;
if (dwRet != 0)
{
uShowDriverErrMsg(pThread_Par.hWnd , dwRet);
SendMessage(pThread_Par.hWnd, WM_COMMAND, IDC_BTN_DISABLE, 0);
break;
}
if (uEventType == ADS_EVT_OVERFLOW_CNT0)
{
//SetDlgItemText(pThread_Par.hWnd, IDC_EDTINTSOURCE, _T("Counter1 Overflow"));
//SendMessage(GetDlgItem(pThread_Par.hWnd, IDC_OV1), STM_SETIMAGE,
// (WPARAM)IMAGE_BITMAP, (LPARAM)bmon.m_hObject);
//((CStatic*)GetDlgItem(pOperDlg->m_hWnd,IDC_OV1))->SetBitmap((HBITMAP)bmon);
wsprintf(szCount,_T("%ld"),++dwOverFlow[0]);
pCntIntDlg->m_listCnt.SetItemText(0,4,_T(szCount));
}
if (uEventType == ADS_EVT_OVERFLOW_CNT1)
{
wsprintf(szCount,_T("%ld"),++dwOverFlow[1]);
pCntIntDlg->m_listCnt.SetItemText(1,4,_T(szCount));
}
if (uEventType == ADS_EVT_OVERFLOW_CNT2)
{
wsprintf(szCount,_T("%ld"),++dwOverFlow[2]);
pCntIntDlg->m_listCnt.SetItemText(2,4,_T(szCount));
}
if (uEventType == ADS_EVT_INDEX_CNT0)
{
wsprintf(szCount,_T("%ld"),++dwIndexIn[0]);
pCntIntDlg->m_listCnt.SetItemText(0,5,_T(szCount));
}
if (uEventType == ADS_EVT_INDEX_CNT1)
{
wsprintf(szCount,_T("%ld"),++dwIndexIn[1]);
pCntIntDlg->m_listCnt.SetItemText(1,5,_T(szCount));
}
if (uEventType == ADS_EVT_INDEX_CNT2)
{
wsprintf(szCount,_T("%ld"),++dwIndexIn[2]);
pCntIntDlg->m_listCnt.SetItemText(2,5,_T(szCount));
}
if (uEventType == ADS_EVT_INTERRUPT_IDI0)
{
wsprintf(szCount,_T("%ld"),++dwCountDI0);
SetDlgItemText(pThread_Par.hWnd, IDC_STATIC_DI0, _T(szCount));
}
if (uEventType == ADS_EVT_INTERRUPT_IDI1)
{
wsprintf(szCount,_T("%ld"),++dwCountDI1);
SetDlgItemText(pThread_Par.hWnd, IDC_STATIC_DI1, _T(szCount));
}
if (uEventType == ADS_EVT_TC_TIMER)
{
}
}
return 0;
}
void CCntIntDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
PT_QCounterRead pCounterRead;
UINT i;
USHORT uOverflow = 0;
ULONG LoCount = 0, HiCount = 0;
DWORD dwRet;
TCHAR szCounter[30];
for (i = 0; i < COUNT_NUMBER; i++)
{
pCounterRead.counter = i;
pCounterRead.HiCount = &HiCount;
pCounterRead.LoCount = &LoCount;
pCounterRead.overflow = &uOverflow;
dwRet = DRV_QCounterRead(m_DriverHandle, &pCounterRead);
if (dwRet != 0)
{
return;
}
if ((gConfig833.CounterConfigSys.CascadeMode & 0x1) == 0)
{
wsprintf(szCounter, _T("0x%06X"), LoCount);
}
else
{
wsprintf(szCounter, _T("0x%04X%08X"), HiCount, LoCount);
}
m_listCnt.SetItemText(i,1,szCounter);
}
CDialog::OnTimer(nIDEvent);
}
void CCntIntDlg::OnBtnDisable()
{
// TODO: Add your control notification handler code here
DWORD dwRet;
int i,j;
PT_QCounterStart pCounterStart;
PT_EnableEvent pEnableEvent;
// disable event
if (gConfig833.usInterrupt != 0)
{
pEnableEvent.Enabled = FALSE;
dwRet = DRV_EnableEvent(m_DriverHandle, &pEnableEvent);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
}
}
gConfig833.usInterrupt = 0;
// disable counter
for (i = 0; i < COUNT_NUMBER; i++)
{
pCounterStart.counter = i;
pCounterStart.InputMode = 0;
dwRet = DRV_QCounterStart(m_DriverHandle, &pCounterStart);
}
StopThread();
// stop timer
for (i = 0; i < COUNT_NUMBER; i++)
{
if (gConfig833.CountStart[i].InputMode != DISABLE)
{
KillTimer(1);
break;
}
}
//Reset value into initial value
for(i = 0; i< COUNT_NUMBER ; i++)
{
for(j = 0; j< COL_NUMER ;j++)
{
m_listCnt.SetItemText(i,j,szContent[i][j]);
}
}
((CButton*)GetDlgItem(IDOK))->EnableWindow(TRUE);
((CButton*)GetDlgItem(IDC_BTN_ENABLE))->EnableWindow(TRUE);
((CButton*)GetDlgItem(IDC_BTN_CONFIG))->EnableWindow(TRUE);
((CButton*)GetDlgItem(IDC_BTN_DISABLE))->EnableWindow(FALSE);
m_staticDI0.SetWindowText("0");
m_staticDI1.SetWindowText("0");
}
void CCntIntDlg::StopThread()
{
gbThreadRun = FALSE;
Sleep(500); // wait for thread exit
DWORD dwExitcode = 0;
GetExitCodeThread(hThread, &dwExitcode);
if (dwExitcode == STILL_ACTIVE)
{
// while (gbRunning) ;
TerminateThread(hThread, 0);
}
CloseHandle(hThread);
hThread = (HANDLE)NULL;
}
void CCntIntDlg::OnBtnresetcounter()
{
// TODO: Add your control notification handler code here
DWORD dwRet;
PT_QCounterConfig pCounterConfig;
pCounterConfig.counter = m_nCounter;
pCounterConfig.ResetValue = gConfig833.CounterConfig[m_nCounter].ResetValue;
dwRet = DRV_QCounterConfig(m_DriverHandle, &pCounterConfig);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
DRV_DeviceClose(&m_DriverHandle);
return;
}
dwRet = DRV_CounterReset(m_DriverHandle, (LPARAM)m_nCounter);
if (dwRet != 0)
{
uShowDriverErrMsg(GetSafeHwnd(), dwRet);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -