www.pudn.com > C8051JTAG_SRC.rar > C8051JTAGDlg.cpp


// C8051JTAGDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "C8051JTAG.h" 
#include "C8051JTAGDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	BOOL	m_blValue; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	//{{AFX_MSG(CAboutDlg) 
	virtual void OnOK(); 
	afx_msg void OnTimer(UINT nIDEvent); 
	virtual BOOL OnInitDialog(); 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	m_blValue = TRUE; 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	DDX_Check(pDX, IDC_CHECK_AUTOCLS, m_blValue); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
	ON_WM_TIMER() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CC8051JTAGDlg dialog 
 
CC8051JTAGDlg::CC8051JTAGDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CC8051JTAGDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CC8051JTAGDlg) 
	m_strMsg = _T(""); 
	m_strSadd = _T(""); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CC8051JTAGDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CC8051JTAGDlg) 
	DDX_Control(pDX, IDC_LIST_MSG, m_ctrlList); 
	DDX_Control(pDX, IDC_COMBO_CPUTYPE, m_ccCpuType); 
	DDX_Control(pDX, IDC_COMBO_CABTYPE, m_ccCabType); 
	DDX_Control(pDX, IDC_PROGRESS_PROC, m_ctrlProcess); 
	DDX_Text(pDX, IDC_STATIC_MSG, m_strMsg); 
	DDX_Text(pDX, IDC_EDIT_SADD, m_strSadd); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CC8051JTAGDlg, CDialog) 
	//{{AFX_MSG_MAP(CC8051JTAGDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_WM_CLOSE() 
	ON_BN_CLICKED(IDC_BUTTON_FILERD, OnButtonFilerd) 
	ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead) 
	ON_BN_CLICKED(IDC_BUTTON_WV, OnButtonWv) 
	ON_CBN_SELCHANGE(IDC_COMBO_CABTYPE, OnSelchangeComboCabtype) 
	ON_EN_UPDATE(IDC_EDIT_SADD, OnUpdateEditSadd) 
	ON_BN_CLICKED(IDC_BUTTON_VERY, OnButtonVery) 
	ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout) 
	ON_LBN_DBLCLK(IDC_LIST_MSG, OnDblclkListMsg) 
	ON_BN_CLICKED(IDC_CHECK_HIGH, OnCheckHigh) 
	ON_CBN_SELCHANGE(IDC_COMBO_CPUTYPE, OnSelchangeComboCputype) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CC8051JTAGDlg message handlers 
 
BOOL CC8051JTAGDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	CListBox *pList; 
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
	CString strTemp; 
	// TODO: Add extra initialization here 
	m_strSadd = "0000"; 
	m_ccCabType.SetCurSel(0); 
//	m_ccCpuType.SetCurSel(0); 
	iXXX = 99999; 
	if(!InitializeWinIo()) 
	{ 
		strTemp.Format("WinIO库初始化失败!请重新打开软件."); 
 
		MessageBox("Winio Init fail!"); 
	} 
	else 
	{ 
		if(c_jtag.CableSetup(ALTERABLASTER)) 
		{ 
			strTemp.Format("BYTEBLASTER连接失败!!系统检测DB25-7---DB25-10脚是否连接."); 
			 
			MessageBox("ByteBlaster连接检测失败!检查并口连接,确认电源已经打开!"); 
			 
		} 
		else 
		{ 
			unsigned long ulTemp; 
			ulTemp = c_jtag.JtagGetIDCode(); 
			strTemp.Format("连接成功,ID=0x%08X",ulTemp); 
			m_strMsg.Format("Get Chip ID = 0x%08X",ulTemp); 
			UpdateData(false); 
			TRACE(m_strMsg); 
		} 
	} 
	pList->SetSel(0); 
	CTime time=CTime::GetCurrentTime(); 
	strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
	pList->AddString(strTemp); 
 
	GetDlgItem(IDC_EDIT_RSADD)->SetWindowText("0000"); 
	GetDlgItem(IDC_EDIT_READD)->SetWindowText("FE00"); 
	 
	////////////////////////////////////////////////////////////////////////// 
	//加入判断系统参数 
	strTemp=GetCommandLine(); 
	TRACE(strTemp); 
//	int j=strcspn(sMainPara," -"); 
 
	 
	CAboutDlg dlg; 
	int nResponse = dlg.DoModal(); 
	if (nResponse == IDOK) 
	{ 
		// TODO: Place code here to handle when the dialog is 
		//  dismissed with OK 
	} 
	else if (nResponse == IDCANCEL) 
	{ 
		// TODO: Place code here to handle when the dialog is 
		//  dismissed with Cancel 
	} 
 
	UpdateData(FALSE); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CC8051JTAGDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CC8051JTAGDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CC8051JTAGDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CC8051JTAGDlg::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	ShutdownWinIo(); 
	CDialog::OnClose(); 
} 
 
void CC8051JTAGDlg::OnOK()  
{ 
	c_jtag.ResetCpu(); 
} 
 
void CC8051JTAGDlg::OnButtonFilerd()  
{ 
	// TODO: Add your control notification handler code here 
	CString strTemp; 
	CListBox *pList; 
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
 
	CFileDialog filediag(TRUE,NULL,NULL,OFN_READONLY,"Hex Files (*.hex)|*.hex|Bin file (*.bin)|*.bin|All Files (*.*)|*.*|",NULL); 
	if(filediag.DoModal()==IDOK) 
	{ 
			strFileWPath = filediag.GetPathName(); 
			strTemp.Format("打开文件%s成功!",filediag.GetPathName()); 
 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			strTemp.Format("文件路径 %s",filediag.GetPathName()); 
			GetDlgItem(IDC_STATIC_FILEPATH)->SetWindowText(strTemp); 
			GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(TRUE); 
			GetDlgItem(IDC_BUTTON_WV)->EnableWindow(TRUE); 
 
	} 
	else 
	{ 
		GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false); 
		GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false); 
	} 
} 
 
void CC8051JTAGDlg::OnButtonRead()  
{ 
	pProgThread=(ProgThreah *)AfxBeginThread(RUNTIME_CLASS(ProgThreah)); 
	pProgThread->PostThreadMessage(WM_BEGINREAD,(WPARAM)(this),0); 
} 
 
void CC8051JTAGDlg::OnButtonWv()  
{ 
	// TODO: Add your control notification handler code here 
	pProgThread=(ProgThreah *)AfxBeginThread(RUNTIME_CLASS(ProgThreah)); 
	pProgThread->PostThreadMessage(WM_BEGINWRITE,(WPARAM)(this),0);	 
} 
 
 
void CC8051JTAGDlg::OnSelchangeComboCabtype()  
{ 
	// TODO: Add your control notification handler code here 
	int i=c_jtag.CableSetup(m_ccCabType.GetCurSel()); 
	CString strTemp; 
	CListBox *pList; 
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
 
	strTemp.Format("Get Chip ID = 0x%08X",c_jtag.JtagGetIDCode()); 
	m_strMsg = strTemp; 
	UpdateData(false); 
	TRACE(m_strMsg); 
 
	CTime time=CTime::GetCurrentTime(); 
	strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
	pList->AddString(strTemp); 
 
	if (i) 
	{ 
		CString strTemp; 
		strTemp.Format("连接失败!"); 
		CTime time=CTime::GetCurrentTime(); 
		strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
		pList->AddString(strTemp); 
		MessageBox("连接失败!!!请检查电缆!"); 
 
	} 
} 
 
void CC8051JTAGDlg::OnUpdateEditSadd()  
{ 
	// TODO: If this is a RICHEDIT control, the control will not 
	// send this notification unless you override the CDialog::OnInitDialog() 
	// function to send the EM_SETEVENTMASK message to the control 
	// with the ENM_UPDATE flag ORed into the lParam mask. 
	unsigned long ulTemp; 
	CString strTemp; 
	UpdateData(TRUE); 
	ulTemp = c_hex2bin.atih(m_strSadd); 
	if (ulTemp>0xFFFF) 
	{ 
		ulTemp = 0xFFFF; 
		strTemp.Format("%X",ulTemp); 
		GetDlgItem(IDC_EDIT_SADD)->SetWindowText(strTemp); 
	} 
	if (ulTemp==0) 
	{ 
		m_strSadd = "0000"; 
	} 
	else 
	{ 
		 
	} 
	// TODO: Add your control notification handler code here 
	UpdateData(false); 
} 
 
void CC8051JTAGDlg::OnButtonVery()  
{ 
	pProgThread=(ProgThreah *)AfxBeginThread(RUNTIME_CLASS(ProgThreah)); 
	pProgThread->PostThreadMessage(WM_BEGINVERY,(WPARAM)(this),0); 
	 
} 
 
int CC8051JTAGDlg::fnWriteVery() 
{ 
	unsigned long i,k; 
	unsigned char ucTemp,ucWrite,ucVery; 
	int iRet; 
	CString strTemp;	 
	CFile m_File; 
	CFileException fileException; 
	unsigned int uiStartAdd; 
	CTime time=CTime::GetCurrentTime(); 
	CListBox *pList; 
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
 
 
 
	if (strFileWPath == "") 
	{ 
		MessageBox(_T("请先选择文件!!!"),NULL,MB_OK); 
		return 1; 
	} 
 
	strTemp=strFileWPath.Right(3); 
	strTemp.MakeLower(); 
	if ( strTemp== "hex") 
	{ 
		c_hex2bin.SetFile(&strFileWPath,TRUE); 
		strTemp.Format(".bin文件保存在:%s",strFileWPath); 
		strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
		pList->AddString(strTemp); 
	} 
 
 
	if ( !m_File.Open( strFileWPath, CFile::modeRead, &fileException) ) 
	{ 
		TRACE( "Can't open file %s, error = %u\n", 
		   strFileWPath, fileException.m_cause ); 
		return 2; 
	} 
 
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false); 
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false); 
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(false); 
	 
	TRACE("写入大小:%d",m_File.GetLength()); 
 
	strTemp.Format("写入大小:%d",m_File.GetLength()); 
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
	 
	strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
	pList->AddString(strTemp); 
	m_ctrlProcess.SetRange(0,1000); 
	k = m_File.GetLength(); 
	uiStartAdd = c_hex2bin.atih(m_strSadd); 
	m_strSadd.Format("%04X",uiStartAdd); 
 
//	c_jtag.JTAG_Reset(); 
	//写入操作 
	m_File.Seek(0,CFile::begin); 
	for (i=0;iSetWindowText(strTemp); 
				CTime time=CTime::GetCurrentTime(); 
				strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
				pList->AddString(strTemp); 
				TRACE("擦除失败!!!"); 
				break; 
			}												// handle Write Lock condition 
			else 
			{ 
				TRACE("擦除成功!!!"); 
			} 
		} 
		//写入 
		m_File.Read(&ucWrite,1); 
		iRet = c_jtag.FLASH_ByteWrite (i+uiStartAdd, ucWrite);  
		if (!iRet) 
		{ 
			strTemp.Format("写入失败!!!地址:0x%04X",i); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			TRACE(strTemp); 
			break; 
		} 
		else 
		{ 
			m_ctrlProcess.SetPos(i*1000/k); 
			strTemp.Format("写入%0.2f%%,%04X",(float)i/k*100,i); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			 
			TRACE(strTemp); 
		} 
	} 
	strTemp.Format("写入成功,开始校验..."); 
	time = CTime::GetCurrentTime(); 
	strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
	pList->AddString(strTemp); 
 
	Beep(400,70); 
	//读取校验操作 
	m_File.Seek(0,CFile::begin); 
	for (i=0;iSetWindowText(strTemp); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			TRACE(strTemp); 
			break; 
		}; 
		m_File.Read(&ucVery,1); 
		if (ucTemp!=ucVery) 
		{ 
			strTemp.Format("校验失败!!!地址:0x%04X",i); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			TRACE(strTemp); 
			break; 
		} 
		else 
		{ 
			m_ctrlProcess.SetPos(i*1000/k); 
			strTemp.Format("验证%0.2f%%,%04X",(float)i/k*100,i); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			TRACE(strTemp); 
		} 
	} 
	if (i==m_File.GetLength()) 
	{ 
		strTemp.Format("写入&&校验成功!!!写入字节=%d",i); 
	} 
	else 
	{ 
		strTemp.Format("写入&&校验失败!!!错误字节=%d",i); 
	} 
	 
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
	time = CTime::GetCurrentTime(); 
	strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
	pList->AddString(strTemp); 
	TRACE(strTemp); 
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(true); 
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(true); 
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(true); 
	Beep(400,80); 
	return 0; 
} 
 
int CC8051JTAGDlg::fnRead() 
{ 
	// TODO: Add your control notification handler code here 
	CFileDialog filediag(TRUE,NULL,"Read.bin",OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT,"Bin file (*.bin)|*.bin|",NULL); 
	if(filediag.DoModal()==IDOK) 
	{ 
			m_strMsg.Format("文件保存于:%s!",filediag.GetPathName()); 
	} 
	else 
		return 2; 
 
 
 
	unsigned char *pFwrite,*pFwHead; 
	unsigned int pass; 
	unsigned long i,ulSadd,ulEadd; 
	CString strTemp; 
 
	CListBox *pList; 
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
 
	GetDlgItem(IDC_EDIT_RSADD)->GetWindowText(strTemp); 
	ulSadd = c_hex2bin.atih(strTemp); 
	strTemp.Format("%04X",ulSadd); 
 
	GetDlgItem(IDC_EDIT_READD)->GetWindowText(strTemp); 
	ulEadd = c_hex2bin.atih(strTemp); 
	strTemp.Format("%04X",ulEadd); 
 
	if (ulEaddEnableWindow(false); 
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false); 
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(false); 
 
	pFwHead = (unsigned char *)malloc(ulEadd-ulSadd+1); 
	pFwrite = pFwHead; 
	m_ctrlProcess.SetRange(0,1000); 
	for (i=0;iSetWindowText(strTemp); 
		TRACE(strTemp); 
		if(!pass) 
		{ 
			strTemp.Format("读取出错!超出地址?当前地址:0x%04X",i); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			TRACE("读取出错!超出地址?当前地址:0x%04X",i); 
			break; 
		} 
	} 
	if(i ==(ulEadd-ulSadd+1) ) 
	{ 
		//保存文件 
		CFile m_File2W; 
		CFileException fileException; 
		if ( !m_File2W.Open( filediag.GetPathName(), CFile::modeCreate|CFile::modeReadWrite, &fileException) ) 
		{ 
			TRACE( "Can't open file %s, error = %u\n", 
			   filediag.GetPathName(), fileException.m_cause ); 
		} 
		else 
		{ 
			strTemp.Format("读取&&保存成功!文件路径:%s",filediag.GetPathName()); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			m_File2W.Write(pFwHead,i); 
			m_File2W.Close(); 
		} 
	} 
	else 
	{ 
			strTemp.Format("读取&&保存失败!文件路径:%s",filediag.GetPathName()); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
 
	} 
	free(pFwHead); 
 
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(TRUE); 
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(TRUE); 
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(true); 
	Beep(400,100); 
	return 0; 
} 
 
int CC8051JTAGDlg::fnVerify() 
{ 
	unsigned long i,k; 
	unsigned char ucTemp,ucVery; 
	int iRet; 
	CString strTemp; 
	CFile m_File; 
	CFileException fileException; 
 
	CListBox *pList; 
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
 
	if (strFileWPath == "") 
	{ 
		MessageBox(_T("请先选择文件!!!"),NULL,MB_OK); 
		return 1; 
	} 
 
	if (strFileWPath.Right(3) == "hex") 
	{ 
		c_hex2bin.SetFile(&strFileWPath,TRUE); 
	} 
 
 
	if ( !m_File.Open( strFileWPath, CFile::modeRead, &fileException) ) 
	{ 
		TRACE( "Can't open file %s, error = %u\n", 
		   strFileWPath, fileException.m_cause ); 
		return 2; 
	} 
	 
 
 
	TRACE("验证的文件大小:%d",m_File.GetLength()); 
	m_ctrlProcess.SetRange(0,1000); 
	k = m_File.GetLength(); 
	 
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false); 
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false); 
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(false); 
 
	// TODO: Add your control notification handler code here 
	//读取校验操作 
	m_File.Seek(0,CFile::begin); 
	for (i=0;iSetWindowText(strTemp); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			TRACE(strTemp); 
			break; 
		}; 
		m_File.Read(&ucVery,1); 
		if (ucTemp!=ucVery) 
		{ 
			strTemp.Format("校验失败!!!地址:0x%04X",i); 
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
			CTime time=CTime::GetCurrentTime(); 
			strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
			pList->AddString(strTemp); 
			TRACE(strTemp); 
			break; 
		} 
		m_ctrlProcess.SetPos(i*1000/k); 
		strTemp.Format("验证%0.2f%%,%04X",(float)i/k*100,i); 
		GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
	} 
	if (i == m_File.GetLength()) 
	{ 
		strTemp.Format("校验成功!!!字节=%d",i); 
	} 
	else 
	{ 
		strTemp.Format("校验失败!!!字节=%d",i); 
	} 
 
	 
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp); 
	CTime time=CTime::GetCurrentTime(); 
	strTemp = time.Format( "%H:%M:%S->" )+strTemp; 
	pList->AddString(strTemp); 
	TRACE(strTemp); 
 
 
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(TRUE); 
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(TRUE); 
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(TRUE); 
	Beep(400,100); 
	return 0; 
 
} 
 
void CC8051JTAGDlg::OnButtonAbout()  
{ 
	// TODO: Add your control notification handler code here 
	CAboutDlg dlg; 
//	m_pMainWnd = &dlg; 
	int nResponse = dlg.DoModal(); 
	if (nResponse == IDOK) 
	{ 
		// TODO: Place code here to handle when the dialog is 
		//  dismissed with OK 
	} 
	else if (nResponse == IDCANCEL) 
	{ 
		// TODO: Place code here to handle when the dialog is 
		//  dismissed with Cancel 
	} 
} 
 
void CAboutDlg::OnOK()  
{ 
	// TODO: Add extra validation here 
	 
	CDialog::OnOK(); 
} 
 
void CAboutDlg::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	UpdateData(true); 
	if (m_blValue) 
	{ 
		CDialog::OnOK(); 
	} 
	CDialog::OnTimer(nIDEvent); 
} 
 
BOOL CAboutDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	SetTimer(1,2000,NULL); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CC8051JTAGDlg::OnDblclkListMsg()  
{ 
	// TODO: Add your control notification handler code here 
//	int index; 
//	CListBox *pList; 
//	CString strTemp; 
//	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG); 
//	index = pList->GetCurSel(); 
//	pList->GetText(index,strTemp); 
//	::SetClipboardData(1,&strTemp); 
} 
 
void CC8051JTAGDlg::OnCheckHigh()  
{ 
	// TODO: Add your control notification handler code here 
	int i=IsDlgButtonChecked(IDC_CHECK_HIGH); 
	if (i) 
	{ 
		c_jtag.ucFCONBIT7 = 0x80; 
	} 
	else 
	{ 
		c_jtag.ucFCONBIT7 = 0x00; 
	} 
} 
 
void CC8051JTAGDlg::OnSelchangeComboCputype()  
{ 
	// TODO: Add your control notification handler code here 
	CComboBox *cbp; 
	int i; 
	cbp = (CComboBox *)GetDlgItem(IDC_COMBO_CPUTYPE); 
	i = cbp->GetCurSel(); 
	switch(i) 
	{ 
		case 0: 
			{ 
				c_jtag.SelectCPU(C8051F020); 
			}break; 
		case 1: 
			{ 
				c_jtag.SelectCPU(C8051F120); 
			}break; 
 
	} 
}