⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 UHF RFID Reader Program
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			m_wndSplitter.ShowPane(Bottom, TRUE);
		}


		if(/*dlg.m_nComboOffset != 0 && dlg.m_nComboOffset != 1 && */dlg.m_nComboCount != 0)
		{	
			CUtil util;
			CString sBuffer = dlg.m_strData;
			int nLength, i;	
			INT16U* pData;// = new INT16U;

			// Check to data Format for Tag Write 
			nLength = sBuffer.GetLength() / 4;
			pData = (INT16U*) malloc(sizeof(INT16U) * nLength);

			for (i=0; i < nLength; i++)
			{
				CString strWord = TEXT("");
				strWord = sBuffer.Mid(i * 4, 4);

				TRACE(strWord);

				pData[i] = static_cast<INT16U>(util.StrToWord(sBuffer.Mid(i * 4, 4)));//util.StrToINT16U(strWord);
			}

			if(dlg.m_strEPC == TEXT(""))
			{
				m_pRFIDRadioManager->TagWrite(0, NULL, dlg.m_nComboMBank, dlg.m_nComboOffset, dlg.m_nComboCount, pData);
			}
			else
			{
				m_pRFIDRadioManager->TagWrite(0, (INT32U*)pDoc->GetSelectedTag()->GetTagEPC(), dlg.m_nComboMBank, dlg.m_nComboOffset, dlg.m_nComboCount, pData);
			}
		}
		else
		{
			::MessageBox(AfxGetMainWnd()->m_hWnd, _T("Input parameter does not right!"), _T("Error"), MB_ICONERROR);
		}
	}
}

// Tag Lock
void CMainFrame::OnTagLock()
{
	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();	
	CLockTagAccessDlg dlg(this);

	if(m_pRFIDRadioManager->IsInventory())
		OnRfidStopInventory();

	if(pDoc->GetSelectedTag() != NULL)
		dlg.SetSelectedTag(pDoc->GetSelectedTag());

	if(dlg.DoModal() == IDOK)
	{
		if (m_wndSplitter.IsPaneHidden(Bottom))
		{
			m_wndSplitter.ShowPane(Bottom, TRUE);
		}


		RFID_18K6C_TAG_PERM				m_lockPermission;
		INT32U							m_AccessPassword;

		m_lockPermission.killPasswordPermissions = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("KillPasswordPermission"), 0);
		m_lockPermission.accessPasswordPermissions = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("AccessPasswordPermission"), 0);
		m_lockPermission.epcMemoryBankPermissions = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("EPCMemoryBankPermission"), 0);
		m_lockPermission.tidMemoryBankPermissions = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("TIDMemoryBankPermission"), 0);
		m_lockPermission.userMemoryBankPermissions = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("UserMemoryBankPermission"), 0);

		m_AccessPassword = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("AccessPassword"), 0);

		if(dlg.m_strEPC == TEXT(""))
			m_pRFIDRadioManager->TagLock(0, NULL, m_lockPermission, m_AccessPassword);
		else
			m_pRFIDRadioManager->TagLock(0, (INT32U*)pDoc->GetSelectedTag()->GetTagEPC(), m_lockPermission, m_AccessPassword);
	}
}

// Tag Kill 
void CMainFrame::OnTagKill()
{
	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();	
	CKillTagAccessDlg dlg(this);

	if(m_pRFIDRadioManager->IsInventory())
		OnRfidStopInventory();

	if(pDoc->GetSelectedTag() != NULL)
		dlg.SetSelectedTag(pDoc->GetSelectedTag());

	if(dlg.DoModal() == IDOK)
	{
		if (m_wndSplitter.IsPaneHidden(Bottom))
		{
			m_wndSplitter.ShowPane(Bottom, TRUE);
		}

		INT32U							m_AccessPassword;
		INT32U							m_KillPassword;

		m_AccessPassword = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("AccessPassword"), 0);
		m_KillPassword = theApp.GetProfileInt(TEXT("TagAccess"), TEXT("KillPassword"), 0);

		if(dlg.m_strEPC == TEXT(""))
			m_pRFIDRadioManager->TagKill(0, NULL, m_AccessPassword, m_KillPassword);
		else
			m_pRFIDRadioManager->TagKill(0, (INT32U*)pDoc->GetSelectedTag()->GetTagEPC(), m_AccessPassword, m_KillPassword);	}
}

void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default


	CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CMainFrame::OnUpdateTagRead(CCmdUI *pCmdUI)
{
	if(GetRFIDRadioManager()->IsConnect())
		pCmdUI->Enable(TRUE);
	else
		pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateTagWrite(CCmdUI *pCmdUI)
{
	if(GetRFIDRadioManager()->IsConnect())
		pCmdUI->Enable(TRUE);
	else
		pCmdUI->Enable(FALSE);

}

void CMainFrame::OnUpdateTagLock(CCmdUI *pCmdUI)
{
	if(GetRFIDRadioManager()->IsConnect())
		pCmdUI->Enable(TRUE);
	else
		pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateTagKill(CCmdUI *pCmdUI)
{
	if(GetRFIDRadioManager()->IsConnect())
		pCmdUI->Enable(TRUE);
	else
		pCmdUI->Enable(FALSE);
}


void CMainFrame::OnCbnEditchangeLeakTime()
{
	CString strLeakTime;

	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();
	CRFRMView* pView = (CRFRMView*)GetActiveView();

	m_wndComboLeakTime.GetWindowText(strLeakTime);
	pDoc->m_nLeakTime = atoi((LPSTR)(LPCTSTR)strLeakTime);
	
	pView->KillTimer(1);

	if(pDoc->m_bLeakEnable)
	{
		if(pDoc->m_nLeakTime > 0)
			pView->SetTimer(1, pDoc->m_nLeakTime * 1000, NULL);
	}
}

void CMainFrame::OnCbnSelchangeLeakTime()
{
	CString strLeakTime;

	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();

	pDoc->m_nLeakTime = m_wndComboLeakTime.GetCurSel() + 1;

	KillTimer(1);

	if(pDoc->m_bLeakEnable)
	{
		if(pDoc->m_nLeakTime > 0)
			SetTimer(1, pDoc->m_nLeakTime * 1000, NULL);
	}
}

void CMainFrame::OnBnClickedLeakEnable()
{
	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();

	pDoc->m_bLeakEnable = !pDoc->m_bLeakEnable;

	if(pDoc->m_bLeakEnable)
	{
		m_wndLeakCheckButton.SetCheck(TRUE);
		m_wndComboLeakTime.EnableWindow(pDoc->m_bLeakEnable);
	}
	else
	{
		m_wndLeakCheckButton.SetCheck(FALSE);
		m_wndComboLeakTime.EnableWindow(pDoc->m_bLeakEnable);

 		KillTimer(1);
	}
}
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();
	// TODO: Add your message handler code here and/or call default
	switch(nIDEvent)
	{
	case 1:
		{
			if(!pDoc->GetLeakMode())
			{
				//////////////////////////////////////////////////
				// This loop is Leak non-continuous mode

				m_pRFIDRadioManager->StopInventory();

				 KillTimer(1);
				// Timer Kill and Leak mode disable and inventory stop
//				m_wndLeakCheckButton.SetCheck(FALSE);
//				m_wndComboLeakTime.EnableWindow(pDoc->m_bLeakEnable);
			}
			else if(m_pRFIDRadioManager->IsInventory() && pDoc->GetLeakMode())		
			{
				//////////////////////////////////////////////////
				// This loop is Leak continuous mode

				m_wndTotalReadCount.SetWindowText(_T("0"));
				m_pWndEdit->SetWindowText(_T("0"));

				// remove all tag data from document
				CPtrList* tagList = pDoc->GetTagList();

				if(!tagList->IsEmpty())
				{
					POSITION pos = tagList->GetHeadPosition();
/*
					while(pos)
					{
						CTagInfo* lpTagInfoExist = (CTagInfo*)tagList->GetAt(pos);

						if(lpTagInfoExist != NULL)
							delete lpTagInfoExist;

						tagList->RemoveAt(pos);
					}
*/
					tagList->RemoveAll();
				}

				CRFRMView* pView = (CRFRMView*)GetActiveView();

				CListCtrl& listCtrl = pView->GetListCtrl();
				listCtrl.DeleteAllItems();
			}
			break;
		}
	default:
		break;
	}

	CFrameWnd::OnTimer(nIDEvent);
}

void CMainFrame::OnRfidInterfaceconfiguration()
{
#ifndef _WIN32_WCE
	CInterfaceDlg dlg;
	if(dlg.DoModal() == IDOK)
	{
		if(IDOK == MessageBox(TEXT("This machine have to Exit\nbecause Interface configuration \nhave to change."), TEXT("Warning"), MB_OK ))
		{
			PostQuitMessage(0);
		}
	}
#else
	MessageBox(TEXT("This Option don't\noperation on Windows CE"), TEXT("Warning"), MB_OK);
#endif
}

void CMainFrame::OnUpdateRfidInterfaceconfiguration(CCmdUI *pCmdUI)
{
#ifdef _WIN32_WCE
	pCmdUI->Enable(FALSE);
#endif
}

void CMainFrame::OnRfidInventoryOnce()
{
	CRFRMDoc* pDoc = (CRFRMDoc*)GetActiveDocument();
	int radioCount = m_pRFIDRadioManager->GetRadioCount();
	CString strTemp;
//	for(int i = 0; i < radioCount; i++)
//		m_pRFIDRadioManager->RunInventory(0, 0);

	if(RFID_STATUS_OK !=
		m_pRFIDRadioManager->RunInventory(0, 0))
	{
		strTemp.LoadString(IDS_STRING_RFID_STOP_FAIL);
	}

	strTemp.LoadString(IDS_STRING_RFID_STOP_SUCCESS);
	SetStatusBar(0, strTemp);

	if(pDoc->m_bLeakEnable)
		SetTimer(1, pDoc->m_nLeakTime * 1000, NULL);

	if (!m_wndSplitter.IsPaneHidden(Bottom))
	{
		m_wndSplitter.ShowPane(Bottom, FALSE);
	}
}

void CMainFrame::OnUpdateRfidInventoryOnce(CCmdUI *pCmdUI)
{
	if(m_pRFIDRadioManager->GetControlState(RFID_POWER) && m_pRFIDRadioManager->IsConnect() && !m_pRFIDRadioManager->IsInventory())
	{
		pCmdUI->Enable(1);
	}
	else
	{
		pCmdUI->Enable(0);
	}
}

void CMainFrame::OnFirmwareUpdateoption()
{
	CFirmwareUpdateOptionDlg dlg;

	dlg.DoModal();
}

void CMainFrame::OnFirmwareUpdate()
{    
	CString l_strFileName;
	CFileDialog l_FirmwareUpdateDlg(TRUE, NULL, NULL, 
		OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, 
		TEXT("Firmware Update Files (*.xml)|*.xml|"), this);

	int iRet = l_FirmwareUpdateDlg.DoModal();
	l_strFileName = l_FirmwareUpdateDlg.GetPathName();

	if(iRet == IDOK && l_strFileName.GetLength() > 0)
	{
		try
		{
			RFID_RADIO_FIRMWARE_MODE mode = AfxGetApp()->GetProfileInt(_T("Update"),_T("Option"), 0);

			m_pFirmwareStatusDlg = new CFirmwareUpdateStatusDlg(this);
			m_pFirmwareStatusDlg->Create(CFirmwareUpdateStatusDlg::IDD);
			m_pFirmwareStatusDlg->ShowWindow(SW_SHOW);	

			m_pRFIDRadioManager->RadioFirmwareUpdate(0, l_strFileName, mode, m_pFirmwareStatusDlg);

			theApp.DoWaitCursor(1);
		}
		catch (CException* e)
		{
			TRACE(TEXT("Thread Start Error : %ld"), GetLastError());
			e->ReportError();
		}
	}
}

LRESULT CMainFrame::OnReset(WPARAM wParam, LPARAM lParam)
{
	theApp.DoWaitCursor(-1);

	if(IDOK == MessageBox(TEXT("This machine have to Restart\nbacause Firmware Update Complete."), TEXT("Warning"), MB_OK ))
	{
		PostQuitMessage(0);
//		OnRfidReset();
	}

	return S_OK;
}
void CMainFrame::OnUpdateFirmwareUpdate(CCmdUI *pCmdUI)
{
	pCmdUI->Enable(m_pRFIDRadioManager->IsConnect() && !m_pRFIDRadioManager->IsInventory());
}

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
	if (!m_wndSplitter.Create(this, pContext, Horizontal))
	{
		TRACE0("Failed to CreateStaticSplitter\n");
		return FALSE;
	}

	CRect cr; 
	GetClientRect( &cr);
	ScreenToClient(&cr);

	if (!m_wndSplitter.AddView(Top, RUNTIME_CLASS(CRFRMView), CSize(0, 0), pContext))
	{
		TRACE0("Failed to create first pane\n");
		return FALSE;
	}

	if (!m_wndSplitter.AddView(Bottom, RUNTIME_CLASS(CMessageView), CSize(0, 50), pContext))
	{
		TRACE0("Failed to create second pane\n");
		return FALSE;
	}

	if (!m_wndSplitter.IsPaneHidden(Bottom))
	{
		m_wndSplitter.ShowPane(Bottom, FALSE);
	}

/*
	if (!m_wndSplitter.CreateStatic(this, 2, 1))
	{
		TRACE0("Failed to CreateStaticSplitter\n");
		return FALSE;
	}

	CRect cr; 
	GetClientRect( &cr);
	ScreenToClient(&cr);

	if (!m_wndSplitter.AddView(0, 0, RUNTIME_CLASS(CRFRMView), CSize(0, cr.Height() * 0.7), pContext))
	{
		TRACE0("Failed to create first pane\n");
		return FALSE;
	}

	if (!m_wndSplitter.AddView(1, 0, RUNTIME_CLASS(CMessageView), CSize(0, 50), pContext))
	{
		TRACE0("Failed to create first pane\n");
		return FALSE;
	}

	m_wndSplitter.SetColumnInfo(0, 200, 0);
//	m_wndSplitter.HideView(1, 0);
*/
	return TRUE;
//	return CFrameWnd::OnCreateClient(lpcs, pContext);
}

CMessageView* CMainFrame::GetMessageView(void)
{
	return (CMessageView*)m_wndSplitter.GetPane(1, 0);
}

LRESULT CMainFrame::OnTagAccess(WPARAM wParam, LPARAM lParam)
{
	CString pTagAccess = (LPCTSTR)wParam;

	GetMessageView()->TextOut(pTagAccess);

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -