📄 scommdlg.cpp
字号:
UpdateData(FALSE);
}
}*/
//发送文件
void CSCOMMDlg::OnButtonSendfile()
{
// TODO: Add your control notification handler code here
CFile fp;
/*if(!(fp.Open((LPCTSTR)m_strSendFilePathName,CFile::modeRead)))
{
AfxMessageBox("Open file failed!");
return;
}
fp.SeekToEnd();
unsigned long fplength=fp.GetLength();
m_nFileLength=fplength;
char* fpBuff;
fpBuff=new char[fplength];
fp.SeekToBegin();
if(fp.Read(fpBuff,fplength)<1)
{
fp.Close();
return;
}
fp.Close();
CString strStatus;
if (m_Port.InitPort(this, m_nCom, m_nBaud, m_cParity, m_nDatabits, m_nStopbits, m_dwCommEvents, fplength))
{
m_Port.StartMonitoring();
strStatus.Format("STATUS:COM%d OPENED,%d,%c,%d,%d",m_nCom, m_nBaud,m_cParity,m_nDatabits,m_nStopbits);
m_ctrlIconOpenoff.SetIcon(m_hIconRed);
m_bSendFile=TRUE;
m_strTempSendFilePathName=m_strSendFilePathName;
//m_ctrlEditSendFile.SetWindowText("正在发送......");
//发送文件时,以下功能不能使用
m_ctrlManualSend.EnableWindow(FALSE);
m_ctrlAutoSend.EnableWindow(FALSE);
m_ctrlSendFile.EnableWindow(FALSE);
m_Port.WriteToPort((LPCTSTR)fpBuff,fplength);
}
else
{
AfxMessageBox("Failed to send file!");
m_ctrlIconOpenoff.SetIcon(m_hIconOff);
}
delete fpBuff;*/
}
//检测文件是否发送完毕
LONG CSCOMMDlg::OnFileSendingEnded(WPARAM wParam,LPARAM port)
{
/*if(m_bSendFile)
{
//m_ctrlEditSendFile.SetWindowText("发送完毕!");//m_strSendFilePathName
TX_count+=m_nFileLength;
SetTimer(3,3000,NULL);
CString strTemp;
strTemp.Format("TX:%d",TX_count);
m_ctrlTXCount.SetWindowText(strTemp);
m_bSendFile=FALSE;
}*/
return 0;
}
void CSCOMMDlg::OnButtonPushpin()
{
// TODO: Add your control notification handler code here
m_ctrlPushPin.ProcessClick();
m_bVisible=!m_bVisible;
if(m_bVisible)
{
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
}
else
{
SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW);
BringWindowToTop();
}
}
void CSCOMMDlg::OnDestroy()
{
CDialog::OnDestroy();
//m_ctrlAutoSend.SetCheck(0); //强行关闭自动发送
KillTimer(1); //关闭定时器
KillTimer(4);
m_Port.ClosePort(); //关闭串口
m_ReceiveDatalist.Empty(); //清空接收数据字符串
}
void CSCOMMDlg::OnButtonHelp()
{
// TODO: Add your control notification handler code here
TCHAR exeFullPath[MAX_PATH];
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
CString strlpPath;
strlpPath.Format("%s",exeFullPath);
strlpPath.MakeUpper();
strlpPath.Replace("串口调试助手V2.2.EXE","");
ShellExecute(NULL,NULL,_T("help.htm"),NULL,strlpPath,SW_SHOW);
}
void CSCOMMDlg::DownId()
{
CString tmp,str;
writeid = _T("");
if(m_Status != M_IN_UBOOT){
AfxMessageBox("设备未在UBOOT状态,请重启设备\n");
m_Status = M_INIT;
return;
}
GetDlgItem(IDC_EDIT_TYPE)->GetWindowText(str);
writeid += str;
GetDlgItem(IDC_EDIT_PID)->GetWindowText(str);
writeid += str;
GetDlgItem(IDC_EDIT_HDID)->GetWindowText(str);
str.Format("%02d",atoi((LPCTSTR)str));
writeid += str;
//GetDlgItem(IDC_EDIT_SFID)->GetWindowText(str);
//str.Format("%02d",atoi((LPCTSTR)str));
//writeid += str;
GetDlgItem(IDC_EDIT_SERIAL)->GetWindowText(str);
str.Format("%02d",atoi((LPCTSTR)str));
writeid += str;
if(devid.Compare("90110100010101")){
str = _T("该设备已经有ID:");
str += devid;
str += _T(",是否要改写为:");
str += writeid;
}else{
str = _T("请您确认下载设备ID:");
str += devid;
}
str += _T("?");
int cChoice = MessageBox(str,"确认",MB_OKCANCEL| MB_ICONQUESTION);
if(cChoice != IDOK) return;
tmp = _T("setenv devid ");
tmp += writeid;
tmp += _T("\n");
m_Port.WriteToPort((LPCTSTR)tmp); //发送数据
//AfxMessageBox(tmp);
Sleep(100);
tmp = _T("saveenv\n");
m_Port.WriteToPort((LPCTSTR)tmp); //发送数据
}
void CSCOMMDlg::OnButtonDown()
{
// TODO: Add your control notification handler code here
CString tmp;
if(m_User == UNKNOW_USER){
AfxMessageBox("浏览用户无法使用此功能!请先登陆\n");
return;
}
m_Indown = TRUE;
if(m_Status != M_IN_UBOOT){
AfxMessageBox("设备未在UBOOT状态,请重启设备\n");
m_Status = M_INIT;
return;
}
m_ReceiveData = _T("");
tmp = _T("print devid\n");
m_Port.WriteToPort((LPCTSTR)tmp); //发送数据
m_bWaitACK = WAIT_DEVID;
}
BOOL CSCOMMDlg::InitConfigFile()
{
CFile MyFile;
CString tmp;
if (!MyFile.Open(m_sIniPath,CFile::modeRead)){
if (!MyFile.Open(m_sIniPath,CFile::modeCreate)){
AfxMessageBox( "创建配置文件失败!");
return FALSE;
}
}
MyFile.Close();
m_sIniPath = _T("C:\\Program Files\\ID.ini");
GetPrivateProfileString("Config","ID_Type","901",tmp.GetBuffer(5),5,(LPCTSTR)m_sIniPath);
GetDlgItem(IDC_EDIT_TYPE)->SetWindowText(tmp);
GetPrivateProfileString("Config","ID_ProId","100001",tmp.GetBuffer(10),10,(LPCTSTR)m_sIniPath);
GetDlgItem(IDC_EDIT_PID)->SetWindowText(tmp);
GetPrivateProfileString("Config","ID_HardId","D",tmp.GetBuffer(2),2,(LPCTSTR)m_sIniPath);
GetDlgItem(IDC_EDIT_HDID)->SetWindowText(tmp);
//GetPrivateProfileString("Config","ID_SoftId","1",tmp.GetBuffer(5),5,(LPCTSTR)m_sIniPath);
//GetDlgItem(IDC_EDIT_SFID)->SetWindowText(tmp);
GetPrivateProfileString("Config","ID_Serial","1",tmp.GetBuffer(5),5,(LPCTSTR)m_sIniPath);
GetDlgItem(IDC_EDIT_SERIAL)->SetWindowText(tmp);
GetPrivateProfileString("Config","WriteCount","0",tmp.GetBuffer(10),10,(LPCTSTR)m_sIniPath);
WriteCount = atoi((LPCTSTR)tmp);
tmp.Format("已成功烧写:%d个",WriteCount);
m_ctrlTXCount.SetWindowText(tmp);
UpdateData(FALSE);
return TRUE;
}
int CSCOMMDlg::SaveID()
{
CFile fp;
CString str;
WriteCount++;
str.Format("已烧写成功:%d个",WriteCount);
m_ctrlTXCount.SetWindowText(str);
str.Format("%d",WriteCount);
WritePrivateProfileString("Config","WriteCount",(LPCTSTR)str,(LPCTSTR)m_sIniPath);
if(!(fp.Open((LPCTSTR)m_sIDpath,CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate)))
{
AfxMessageBox("设备ID文件打开失败!");
return FALSE;
}
//AfxMessageBox(writeid);
CTime t = CTime::GetCurrentTime();
str = t.Format("%Y年%m月%d日%H时%M分 , ");
fp.SeekToEnd();
fp.Write((LPCTSTR)str,str.GetLength());
fp.Write((LPCTSTR)writeid,writeid.GetLength());
fp.Write((LPCTSTR)"\r\n",2);
fp.Flush();
fp.Close();
return TRUE;
}
int CSCOMMDlg::CheckACK()
{
BOOL suc = FALSE,getACK = FALSE;
if(!m_bWaitACK) return FALSE;
while(!suc){
if(m_ReceiveData.Compare(ack_str[m_bWaitACK]))
break;
else
getACK = TRUE;
if(!(getACK && !m_ReceiveData.Right(1).Compare("\n"))) break;
switch(m_bWaitACK){
case WAIT_DEVID:
AfxMessageBox(m_ReceiveData);
break;
case WAIT_UBOOT:
break;
}
suc = TRUE;
}
m_bWaitACK = FALSE;
return suc;
}
int CSCOMMDlg::SendToPort(CString cmd,int timeout,int action)
{
//m_ReceiveData = _T("");
m_Port.WriteToPort((LPCTSTR)cmd); //发送数据
m_bWaitACK = action;
//SetTimer(10,timeout,NULL);
return 1;
}
void CSCOMMDlg::OnButtonRead()
{
// TODO: Add your control notification handler code here
CString tmp;
m_Indown = FALSE;
if(m_Status != M_IN_UBOOT){
AfxMessageBox("设备未在UBOOT状态,请重启设备\n");
m_Status = M_INIT;
return;
}
m_ReceiveData = _T("");
tmp = _T("print devid\n");
m_Port.WriteToPort((LPCTSTR)tmp); //发送数据
m_bWaitACK = WAIT_DEVID;
}
void CSCOMMDlg::OnCheckAutoup()
{
// TODO: Add your control notification handler code here
CString tmp;
m_bAutoMake = !m_bAutoMake;
tmp.Format("%d",m_bAutoMake);
WritePrivateProfileString("Config","AutoNextId",(LPCTSTR)tmp,(LPCTSTR)m_sIniPath);
}
void CSCOMMDlg::OnKillfocusEditType()
{
// TODO: Add your control notification handler code here
int value = 0;
CString str;
GetDlgItem(IDC_EDIT_TYPE)->GetWindowText(str);
value = atoi((LPCTSTR)(str));
if(value < 101 || value > 999){
AfxMessageBox("产品型号必须为101-999");
GetDlgItem(IDC_EDIT_TYPE)->SetFocus();
return;
}
GetDlgItem(IDC_EDIT_TYPE)->GetWindowText(str);
WritePrivateProfileString("Config","ID_Type",(LPCTSTR)str,(LPCTSTR)m_sIniPath);
}
void CSCOMMDlg::OnKillfocusEditPid()
{
// TODO: Add your control notification handler code here
int value = 0;
CString str;
GetDlgItem(IDC_EDIT_PID)->GetWindowText(str);
value = atoi((LPCTSTR)(str));
if(value < 1000001 || value > 9999999){
AfxMessageBox("产品ID必须为1000001-9999999");
GetDlgItem(IDC_EDIT_PID)->SetFocus();
return;
}
GetDlgItem(IDC_EDIT_PID)->GetWindowText(str);
WritePrivateProfileString("Config","ID_ProId",(LPCTSTR)str,(LPCTSTR)m_sIniPath);
}
void CSCOMMDlg::OnKillfocusEditHdid()
{
// TODO: Add your control notification handler code here
int value = 0;
CString str;
GetDlgItem(IDC_EDIT_HDID)->GetWindowText(str);
value = atoi((LPCTSTR)(str));
if(value < 1 || value > 99){
AfxMessageBox("硬件版本必须为01-99");
GetDlgItem(IDC_EDIT_HDID)->SetFocus();
return;
}
GetDlgItem(IDC_EDIT_HDID)->GetWindowText(str);
WritePrivateProfileString("Config","ID_HardId",(LPCTSTR)str,(LPCTSTR)m_sIniPath);
}
/*void CSCOMMDlg::OnKillfocusEditSfid()
{
// TODO: Add your control notification handler code here
int value = 0;
CString str;
GetDlgItem(IDC_EDIT_SFID)->GetWindowText(str);
value = atoi((LPCTSTR)(str));
if(value < 1 || value > 99){
AfxMessageBox("软件代码必须为1-99");
GetDlgItem(IDC_EDIT_SFID)->SetFocus();
return;
}
}*/
void CSCOMMDlg::OnKillfocusEditSerial()
{
// TODO: Add your control notification handler code here
int value = 0;
CString str;
GetDlgItem(IDC_EDIT_SERIAL)->GetWindowText(str);
value = atoi((LPCTSTR)(str));
if(value < 1 || value > 99){
AfxMessageBox("生产批次必须为01-99");
GetDlgItem(IDC_EDIT_SERIAL)->SetFocus();
return;
}
GetDlgItem(IDC_EDIT_SERIAL)->GetWindowText(str);
WritePrivateProfileString("Config","ID_Serial",(LPCTSTR)str,(LPCTSTR)m_sIniPath);
}
void CSCOMMDlg::OnButtonReadidfile()
{
// TODO: Add your control notification handler code here
CFile fp;
if(!(fp.Open((LPCTSTR)m_sIDpath,CFile::modeRead)))
{
AfxMessageBox("设备ID文件打开失败!");
return;
}
fp.SeekToEnd();
unsigned long fplength=fp.GetLength();
m_nFileLength=fplength;
char* fpBuff;
fpBuff=new char[fplength+1];
fp.SeekToBegin();
if(fp.Read(fpBuff,fplength)<0)
{
fp.Close();
return;
}
fp.Close();
fpBuff[fplength] = '\0';
m_ReceiveDatalist.Empty();
m_ReceiveDatalist += fpBuff;
UpdateData(FALSE);
delete fpBuff;
}
void CSCOMMDlg::OnButtonBrowfile()
{
// TODO: Add your control notification handler code here
LPCSTR lpszPath = "c:\\";
SetCurrentDirectory( lpszPath );
static char BASED_CODE szFilter[] = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||";
CFileDialog FileDlg( TRUE, NULL, NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szFilter );
FileDlg.m_ofn.lpstrInitialDir = lpszPath ;
if( FileDlg.DoModal() ==IDOK )
{
CString strFileName = FileDlg.GetFileName( );
CString strFileExt = FileDlg.GetFileExt( );
CString lpstrName = FileDlg.GetPathName( );
m_sIDpath=lpstrName;
UpdateData(FALSE);
}
}
void CSCOMMDlg::OnButtonCleardown()
{
// TODO: Add your control notification handler code here
CFile fp;
if(!(fp.Open((LPCTSTR)m_sIDpath,CFile::modeCreate | CFile::modeWrite)))
{
AfxMessageBox("清除失败!");
return;
}
fp.Close();
m_ReceiveDatalist.Empty();
UpdateData(FALSE);
AfxMessageBox("清除成功!");
}
void CSCOMMDlg::OnChangeEditType()
{
// 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
}
void CSCOMMDlg::OnChangeEditPw()
{
// TODO: Add your control notification handler code here
CString strStatus;
UpdateData(TRUE);
if(!m_sPassW.Compare(_T("999999"))){
m_User = SUPER_USER;
m_ID_TYPE.SetReadOnly(FALSE);
m_ID_PID.SetReadOnly(FALSE);
m_ID_SERIAL.SetReadOnly(FALSE);
m_ID_HDID.SetReadOnly(FALSE);
strStatus.Format("状态:COM%d:打开 , 用户:%s",m_nCom,cur_user[m_User]);
m_ctrlPortStatus.SetWindowText(strStatus);
}else if(!m_sPassW.Compare(_T("123456"))){
m_User = NORMAL_USER;
m_ID_TYPE.SetReadOnly(TRUE);
m_ID_PID.SetReadOnly(FALSE);
m_ID_SERIAL.SetReadOnly(FALSE);
m_ID_HDID.SetReadOnly(TRUE);
strStatus.Format("状态:COM%d:打开 , 用户:%s",m_nCom,cur_user[m_User]);
m_ctrlPortStatus.SetWindowText(strStatus);
}
}
void CSCOMMDlg::OnMaxtextEditPw()
{
// TODO: Add your control notification handler code here
//AfxMessageBox(m_sPassW);
}
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CSCOMMDlg::OnButtonLogout()
{
// TODO: Add your control notification handler code here
CString strStatus;
m_User = UNKNOW_USER;
m_ID_TYPE.SetReadOnly(TRUE);
m_ID_PID.SetReadOnly(TRUE);
m_ID_SERIAL.SetReadOnly(TRUE);
m_ID_HDID.SetReadOnly(TRUE);
strStatus.Format("状态:COM%d:打开 , 用户:%s",m_nCom,cur_user[m_User]);
m_ctrlPortStatus.SetWindowText(strStatus);
m_sPassW = _T("");
UpdateData(FALSE);
}
void CSCOMMDlg::OnButtonTime()
{
// TODO: Add your control notification handler code here
int cChoice = MessageBox("机器将退出UBOOT,请确定已烧好ID","确认",MB_OKCANCEL| MB_ICONQUESTION);
if(cChoice != IDOK) return;
m_Port.WriteToPort((LPCTSTR)"run bootcmd\n"); //发送数据
m_Status = M_INIT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -