📄 lcddlg.cpp
字号:
}
strtemp.Format("%04X:",Index);
datumpkt+=strtemp;
}
ReadBuffer[Index++]=bt;
if (Index%256==0)
{
m_progress1.SetPos(Index);
}
if (Index==4096)
{
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
static1->SetWindowText("读取4K完成!");
OperationType=0xff;
m_progress1.SetPos(0);
}
}
strtemp.Format("%02X ",bt); //将字符以十六进制方式送入临时变量strtemp存放,注意这里加入一个空隔
datumpkt+=strtemp;
}
//if ((OperationType!=KEY_Program)&&(OperationType!=KEY_Read64)&&(OperationType!=KEY_Read4))
{
int nLength =pEditSend->GetWindowTextLength();
pEditSend->SetSel(nLength,nLength);
cf.crTextColor=RGB(0,0,0);
pEditSend->SetSelectionCharFormat(cf);
pEditSend->ReplaceSel(datumpkt);
}
}
//UpdateData(FALSE); //更新编辑框内容
}
void CLCDDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CByteArray hexdata;
CString datumpkt,strtemp;
hexdata.SetSize(34);
if (nIDEvent==2)
{
CTime currenttime=CTime::GetCurrentTime();
unsigned char hour,minute,second;
hour=currenttime.GetHour();
minute=currenttime.GetMinute();
second=currenttime.GetSecond();
strtemp.Format("%02d",hour);
datumpkt+=strtemp;
datumpkt+=":";
strtemp.Format("%02d",minute);
datumpkt+=strtemp;
datumpkt+=":";
strtemp.Format("%02d",second);
datumpkt+=strtemp;
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC1);
if (OperationType==KEY_Program)
{
second0++;
datumpkt.Format("%02d",second0);
}
static1->SetWindowText(datumpkt);
}
///////////////////////////////////////////////////////////////////////////////////
if (nIDEvent==1)
{
if (flag)
{
flag=false;
}
else
{
return;
}
if (NoOf32Bytes>=FileLen)
{
m_progress1.SetPos(0);
hexdata[0]='@';
hexdata[1]='E';
for(int i=2;i<34;i++)
{
hexdata[i]=i;
}
m_ctrlComm.SetOutput(COleVariant(hexdata)); //发送十六进制数据
m_ctrlbtn_port.EnableWindow(true);
KillTimer(1);
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
static1->SetWindowText("下载完成!");
OperationType=0xff;
}
else
{
m_progress1.SetPos(NoOf32Bytes);
hexdata[0]='@';
hexdata[1]='D';
for(unsigned char i=0;i<32;i++)
{
hexdata[i+2]=LcdByte[NoOf32Bytes+i];
}
m_ctrlComm.SetOutput(COleVariant(hexdata)); //发送十六进制数据
NoOf32Bytes+=32;
}
}
CDialog::OnTimer(nIDEvent);
}
void CLCDDlg::OnBUTTONopenport()
{
// TODO: Add your control notification handler code here
CString Buffer;
CWnd * m_pMainWnd=AfxGetMainWnd();
portopenflag=!portopenflag;
if (portopenflag)
{
UpdateData(TRUE);
if (m_port=="COM1")
{
m_ctrlComm.SetCommPort(1); //选择com1
}
else if (m_port=="COM2")
{
m_ctrlComm.SetCommPort(2); //选择com2
}
else if (m_port=="COM3")
{
m_ctrlComm.SetCommPort(3); //选择com3
}
m_ctrlComm.SetPortOpen(TRUE);//打开串口
m_ctrlcombo_port.EnableWindow(false);
m_ctrlcombo_comportsetting.EnableWindow(false);
m_ctrlbtn_port.SetWindowText("关闭串口");
m_ctrlComm.SetSettings(m_comportsetting);
m_ctrlComm.SetInputMode(1); //1:表示以二进制方式检取数据
m_ctrlComm.SetRThreshold(1);
//接收缓冲区有1个及1个以上字符时,将引发接收数据的OnComm事件
m_ctrlComm.SetInputLen(0); //设置当前接收区数据长度为0
m_ctrlComm.GetInput();//先预读缓冲区以清除残留数据
GetDlgItem(IDC_BUTTON_ISP)->EnableWindow(true);
}
else
{
KillTimer(3);
m_ctrlComm.SetPortOpen(false);//关闭串口
m_ctrlcombo_port.EnableWindow(true);
m_ctrlcombo_comportsetting.EnableWindow(true);
m_ctrlbtn_port.SetWindowText("打开串口");
m_pMainWnd->SetWindowText("串口调试");
GetDlgItem(IDC_BUTTON_ISP)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Erase)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Verify)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Read4)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_ExitISP)->EnableWindow(false);
}
}
void CLCDDlg::OnBUTTONclear()
{
// TODO: Add your control notification handler code here
CRichEditCtrl * pEditSend =(CRichEditCtrl *)GetDlgItem(IDC_EDIT_RXDATA);
int nLength =pEditSend->GetWindowTextLength();
pEditSend->SetSel(0,nLength);
pEditSend->ReplaceSel("");
}
void CLCDDlg::OnBUTTONopenfile()
{
// TODO: Add your control notification handler code here
CWnd * m_pMainWnd=AfxGetMainWnd();
//CFileDialog FileOpen( true, NULL, NULL,OFN_ALLOWMULTISELECT|OFN_HIDEREADONLY,"All Files (*.*)|*.*||", this);
//FileOpen.m_ofn.lpstrTitle = "My File Dialog";
// FileOpen.m_ofn.lpstrFilter="*.bin";
CFileDialog FileOpen(true,NULL,NULL,OFN_HIDEREADONLY,"二进制文件(*.bin)|*.bin|All Files(*.*)|*.*|");
if(FileOpen.DoModal()!=IDOK)
return;
OpenFileName=FileOpen.GetFileName();
CFile File1(OpenFileName, CFile::modeRead|CFile::typeBinary);
FileLen=File1.GetLength();
File1.Seek(0, CFile::begin);
int ReturnCharacters = File1.Read(LcdByte,FileLen);
File1.Close();
m_pMainWnd->SetWindowText("77E516/78E516 ISP--->"+FileOpen.GetPathName());
}
void CLCDDlg::OnBUTTONdownload()
{
// TODO: Add your control notification handler code here
if (OpenFileName=="")
{
AfxMessageBox("请选择下载文件名!",MB_OK|MB_ICONINFORMATION);
return;
}
OnBUTTONclear();
SendHex(KEY_Program);
SetTimer(1,1,NULL);//时间为1毫秒
flag=true;
OperationType=KEY_Program;
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
static1->SetWindowText("正在下载...");
second0=0;
NoOf32Bytes=0;
m_progress1.SetRange(0,FileLen);
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(false);
}
void CLCDDlg::OnBUTTONISP()
{
// TODO: Add your control notification handler code here
CByteArray hexdata;
hexdata.SetSize(4);
hexdata[0]='C';
hexdata[1]='M';
hexdata[2]='D';
hexdata[3]=KEY_ProgUpdata;
/*
CByteArray hexdata;
hexdata.SetSize(1);
hexdata[0]=0x66;
*/
m_ctrlComm.SetOutput(COleVariant(hexdata));
GetDlgItem(IDC_BUTTON_Erase)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_Verify)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_Read4)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_ExitISP)->EnableWindow(true);
Sleep(100);
m_ctrlcombo_comportsetting.SetWindowText("57600,n,8,1");
UpdateData(true);
m_ctrlComm.SetSettings(m_comportsetting);
}
void CLCDDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
//if (portopenflag)
//{
m_ctrlComm.SetPortOpen(false);//关闭串口
//}
CDialog::PostNcDestroy();
}
void CLCDDlg::OnBUTTONExitISP()
{
// TODO: Add your control notification handler code here
SendHex(KEY_ExitISP);
Sleep(100);
m_ctrlcombo_comportsetting.SetWindowText("9600,n,8,1");
UpdateData(true);
m_ctrlComm.SetSettings(m_comportsetting);
GetDlgItem(IDC_BUTTON_Erase)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Verify)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_Read4)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_ExitISP)->EnableWindow(false);
}
void CLCDDlg::OnBUTTONRead64()
{
// TODO: Add your control notification handler code here
OnBUTTONclear();
SendHex(KEY_Read64);
OperationType=KEY_Read64;
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
static1->SetWindowText("正在校验...");
Index=0;
m_progress1.SetRange32(0,65536);
}
void CLCDDlg::OnBUTTONRead4()
{
// TODO: Add your control notification handler code here
OnBUTTONclear();
SendHex(KEY_Read4);
OperationType=KEY_Read4;
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
static1->SetWindowText("正在读取4K...");
Index=0;
m_progress1.SetRange(0,4096);
}
void CLCDDlg::OnBUTTONErase()
{
// TODO: Add your control notification handler code here
OnBUTTONclear();
SendHex(KEY_Erase);
OperationType=KEY_Erase;
CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
static1->SetWindowText("正在擦除...");
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(true);
}
void CLCDDlg::OnBUTTONexit()
{
// TODO: Add your control notification handler code here
if (m_ctrlComm.GetPortOpen())
{
m_ctrlComm.SetPortOpen(false);//关闭串口
}
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -