?? myapp1dlg.cpp
字號:
DisplayMessage("正在檢測芯片... ...");
com.ClearRecvBuff(); //讀編程器標(biāo)題
char c='\r',str[60];
com.Write(&c,1);
if(com.GetStrWait(str,30)<10)
{
DisplayMessage("未發(fā)現(xiàn)下載器!");
return;
}
int ei=0;
while(str[strlen(str)-1]!='>')
{
if(!com.GetCharWait(&c) || ei>55)
{
DisplayMessage("未發(fā)現(xiàn)下載器!");
return;
}
char l=strlen(str);
str[l]=c;
str[l+1]='\0';
ei++;
} //讀編程器標(biāo)題結(jié)束
//DisplayMessage(str);return;
CString estr=str;
DWORD CpuType=0,NonBlankLen,SetLen;
if(estr.Find("2051")!=-1)
{
DisplayMessage("發(fā)現(xiàn)Atmel 89C2051/4051 下載器!");
CpuType=21;
}
else if(estr.Find("89C51")!=-1)
{
DisplayMessage("發(fā)現(xiàn)Atmel 89C51/52 下載器!");
com.ClearRecvBuff();
char c='p',str[60];
com.Write(&c,1);
if(com.GetStrWait(str,10)<10)
{
return;
}
int ei=0;
while(str[strlen(str)-1]!='>')
{
if(!com.GetCharWait(&c) || ei>20)
{
return;
}
char l=strlen(str);
str[l]=c;
str[l+1]='\0';
ei++;
}
sscanf(str,"p%u,%u,%u",&CpuType,&NonBlankLen,&SetLen);
//DisplayMessage(CpuType);
}
else DisplayMessage("請檢查下載器!"); //此行不會執(zhí)行
switch (CpuType)
{
case 21:
StopWait();
UpdateData();
m_radio1=0;
UpdateData(FALSE);
DisplayMessage("89C4051請手動選擇!");
if(com.IsOpen())
{
(CButton*)GetDlgItem(IDC_BUTTON2)->EnableWindow();
(CButton*)GetDlgItem(IDC_BUTTON4)->EnableWindow();
}
break;
case 51:
StopWait();
UpdateData();
m_radio1=2;
UpdateData(FALSE);
DisplayMessage("發(fā)現(xiàn)Atmel 89C51 ");
if(com.IsOpen())
{
(CButton*)GetDlgItem(IDC_BUTTON2)->EnableWindow();
(CButton*)GetDlgItem(IDC_BUTTON4)->EnableWindow();
}
break;
case 52:
StopWait();
UpdateData();
m_radio1=3;
UpdateData(FALSE);
DisplayMessage("發(fā)現(xiàn)Atmel 89C52 ");
if(com.IsOpen())
{
(CButton*)GetDlgItem(IDC_BUTTON2)->EnableWindow();
(CButton*)GetDlgItem(IDC_BUTTON4)->EnableWindow();
}
break;
default:UpdateData();m_radio1=-1;UpdateData(FALSE);
DisplayMessage("請檢查芯片!");
break;
}
} //end com.IsOpen()
CDialog::OnTimer(nIDEvent);
}
void CMYAPP1Dlg::StartWait(UINT ms=5000)
{
WAIT_OVER=FALSE;
m_nTimer=SetTimer(1,ms,NULL);
}
void CMYAPP1Dlg::StopWait()
{
KillTimer(1);
}
void CMYAPP1Dlg::OnCheck3()
{
// TODO: Add your control notification handler code here
int i;
CButton* pr[5];
UpdateData();
m_radio1=-1;
UpdateData(FALSE);
pr[0]=(CButton*)GetDlgItem(IDC_RADIO1);
pr[1]=(CButton*)GetDlgItem(IDC_RADIO2);
pr[2]=(CButton*)GetDlgItem(IDC_RADIO3);
pr[3]=(CButton*)GetDlgItem(IDC_RADIO4);
pr[4]=(CButton*)GetDlgItem(IDC_RADIO5);
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON2);
CButton* WriteButton=(CButton*)GetDlgItem(IDC_BUTTON4);
if (m_check3==TRUE)
{
for (i=0;i<5;i++) pr[i]->EnableWindow(FALSE);
ReadButton->EnableWindow(FALSE);
WriteButton->EnableWindow(FALSE);
DisplayMessage("自動檢測芯片");
StartWait();
CMYAPP1Dlg::OnTimer(1);
}
else
{
for (i=0;i<5;i++)pr[i]->EnableWindow();
if(0<=m_radio1 && m_radio1<5)
{
ReadButton->EnableWindow();
WriteButton->EnableWindow();
}
DisplayMessage("手動設(shè)定芯片");
StopWait();
}
}
void CMYAPP1Dlg::OnClickList3(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
CListCtrl* pList =
(CListCtrl*) GetDlgItem(IDC_LIST3);
int nSelected = pNMListView->iItem;
if (nSelected >= 0) {
CString strItem = pList->GetItemText(nSelected, 0);
SetDlgItemText(IDC_STATIC_LIST3, strItem);
}
*pResult = 0;
}
void CMYAPP1Dlg::OnRadio1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
UpdateData(FALSE);
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON2);
CButton* WriteButton=(CButton*)GetDlgItem(IDC_BUTTON4);
if(com.IsOpen())
{
ReadButton->EnableWindow();
WriteButton->EnableWindow();
}
}
void CMYAPP1Dlg::OnRadio2()
{
UpdateData(TRUE);
UpdateData(FALSE);
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON2);
CButton* WriteButton=(CButton*)GetDlgItem(IDC_BUTTON4);
if(com.IsOpen())
{
ReadButton->EnableWindow();
WriteButton->EnableWindow();
}
}
void CMYAPP1Dlg::OnRadio3()
{
UpdateData(TRUE);
UpdateData(FALSE);
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON2);
CButton* WriteButton=(CButton*)GetDlgItem(IDC_BUTTON4);
if(com.IsOpen())
{
ReadButton->EnableWindow();
WriteButton->EnableWindow();
}
}
void CMYAPP1Dlg::OnRadio4()
{
UpdateData(TRUE);
UpdateData(FALSE);
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON2);
CButton* WriteButton=(CButton*)GetDlgItem(IDC_BUTTON4);
if(com.IsOpen())
{
ReadButton->EnableWindow();
WriteButton->EnableWindow();
}
}
void CMYAPP1Dlg::OnRadio5()
{
UpdateData(TRUE);
UpdateData(FALSE);
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON2);
CButton* WriteButton=(CButton*)GetDlgItem(IDC_BUTTON4);
if(com.IsOpen())
{
ReadButton->EnableWindow();
WriteButton->EnableWindow();
}
}
void CMYAPP1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
// CFileDialog( BOOL bOpenFileDialog, false=保存,true=打開
// LPCTSTR lpszDefExt = NULL, 缺省擴(kuò)展名
// LPCTSTR lpszFileName = NULL, 文件名
// DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 讀寫方式
// LPCTSTR lpszFilter = NULL, 文件流
// CWnd* pParentWnd = NULL );
CString m_edit2temp=m_edit2;
CString sFilter="Binfile(*.bin)|*.bin|Hexfile(*.hex)|*.hex|All Files (*.*)|*.*|";
CFileDialog dlg(true,"bin",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,(LPCTSTR)sFilter,this);
UpdateData(TRUE);
if(dlg.DoModal()==IDOK)
m_edit2=dlg.GetPathName();
else
m_edit2=m_edit2temp;
UpdateData(FALSE);
}
void CMYAPP1Dlg::OnButton3()
{
// TODO: Add your control notification handler code here
CString sFilter="Binfile(*.bin)|*.bin|Hexfile(*.hex)|*.hex|All Files (*.*)|*.*|";
CFileDialog dlg(false,"bin",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,(LPCTSTR)sFilter,this);
CString m_edit3temp=m_edit3;
UpdateData(TRUE);
if(dlg.DoModal()==IDOK)
m_edit3=dlg.GetPathName();
else
m_edit3=m_edit3temp;
UpdateData(FALSE);
}
void CMYAPP1Dlg::OnChangeEdit3()
{
// 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.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
UpdateData(FALSE);
}
void CMYAPP1Dlg::OnChangeEdit2()
{
// 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.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
UpdateData(FALSE);
}
bool CMYAPP1Dlg::GetOneChar(char *c)
{
char readstr[4];
DWORD i=0;
while (!com.Read(readstr, 1))
{
Sleep(10);
if(i++>200)return FALSE;
};
*c=readstr[0];
return TRUE;
}
BOOL CMYAPP1Dlg::SetLength(DWORD len)
{
com.ClearRecvBuff();
char lenstr[10]="s",readstr[4];
ltoa(len,lenstr+1,10);
strcat(lenstr,"\r");
int n=strlen(lenstr);
for (int i=0;i<n;i++)
{
com.Write(lenstr+i,1);
readstr[0]=XOFF;
do
{
if(!GetOneChar(readstr))return FALSE;
}
while(readstr[0]==XON);
}
return TRUE;
}
void CMYAPP1Dlg::OnButton4() //讀按鈕
{
// TODO: Add your control notification handler code here
CButton* ReadButton=(CButton*)GetDlgItem(IDC_BUTTON4);
CButton* WButton=(CButton*)GetDlgItem(IDC_BUTTON2);
WButton->EnableWindow(FALSE);
ReadButton->EnableWindow(FALSE);
//AfxGetMainWnd()->EnableWindow(FALSE);
char str[60];
com.ClearRecvBuff();
DWORD plen;
switch(m_radio1)
{
case 0: plen=2048; break;
case 1: plen=4096; break;
case 2: plen=4096*1;break;
case 3: plen=4096*2;break;
case 4: plen=4096*5;break;
default:plen=4096*1;break;
}
if(!SetLength(plen))
{
DisplayMessage("設(shè)定程序長度超時!");
ReadButton->EnableWindow();
WButton->EnableWindow();
return;
};
//
if(m_radio1>1)
{
com.ClearRecvBuff();
DisplayMessage("檢查程序長度!");
char c='p';
com.Write(&c,1);
if(com.GetStrWait(str,10,6000)<10)
{
DisplayMessage("檢查程序長度超時!");
ReadButton->EnableWindow();
WButton->EnableWindow();
return;
}
int ei=0;
while(str[strlen(str)-1]!='>')
{
if(!com.GetCharWait(&c) || ei>20)
{
DisplayMessage("檢查程序長度超時!");
ReadButton->EnableWindow();
WButton->EnableWindow();
return;
}
char l=strlen(str);
str[l]=c;
str[l+1]='\0';
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -