📄 ceprcmd.cpp
字号:
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0x20;
send[1] = 0x9f;
send[2] = 0x0f;
send[3] = 0xd0;
bResult = comObj.Write(send, 4);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult2 = !CheckState(&comObj, "erase");
GetSerialComm().SetTimeout(TIMEOUT5);
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0x20;
send[1] = 0x7f;
send[2] = 0x0f;
send[3] = 0xd0;
bResult = comObj.Write(send, 4);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult3 = !CheckState(&comObj, "erase");
if((!bResult0) && (!bResult1) &&(!bResult2) &&(!bResult3))
{
bResult = FALSE;
}
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
return bResult;
}
else
{
// Check box not make
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
GetSerialComm().SetTimeout(TIMEOUT5);
// add M16C/20 2Mhz end
}else{ // nomal
#if _DEBUG
printf("apple old \n");
#endif
//I acquire the communication object.
CSerialComm& comObj = GetSerialComm();
//It does status the clear.
send[0] = 0x50;
comObj.Write(&send[0], 1);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0xa7;
send[1] = 0xd0;
bResult = comObj.Write(send, 2);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult = !CheckState(&comObj, "erase");
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
return bResult;
}
else
{
// Check box not make
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
GetSerialComm().SetTimeout(TIMEOUT5);
// add M16C/20 2Mhz end
}
}
// Program Command
unsigned int nStartAddress = 0;
unsigned int nEndAddress = 0;
BOOL bIsEnd;
{
BOOL bResult = FALSE;
CM16CflshApp* pApp = (CM16CflshApp*)AfxGetApp();
MSG msg;
CSetCommDlg dlg2;
// Get Communication object.
CSerialComm& comObj = GetSerialComm();
// Get Programm address range.
// if(!GetFileAddress(&nStartAddress, &nEndAddress, ADDRESS_SIZE))
// {
// return FALSE;
// }
GetFileAddressOnly(&nStartAddress, &nEndAddress);
// get Intervals time
DWORD ndwintervals = 0;
if(!dlg2.GetIntervals(&ndwintervals))
{
return FALSE;
}
// If a start address is larger than an end address, it will end.
if(!ChkStartToEnd(nStartAddress, nEndAddress))
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_SMALESTART), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
return FALSE;
}
// write confirm.
// CPreWriteDlg dlg;
// dlg.SetAddress(HexToStr(nStartAddress), HexToStr(nEndAddress));
// int nResponse = dlg.DoModal();
// if(IDCANCEL == nResponse)
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_STOP_PROGRAM), GetResString(IDS_FLASH_TITLE));
// return FALSE;
//}
// Clear status
BYTE send = 0x50;
comObj.Write(&send, 1);
// Wait for Communication.
Sleep(SLEEP_IN);
// Prograss dialog setup.
CProgressDlg* pDlg;
BOOL bCancel = FALSE;
pDlg = CProgressDlg::Instance(&bCancel, NULL);
pDlg->InitialDialog("Program.", "Program",
0, (nEndAddress - nStartAddress - 0x0100) / TO_INT, 0);
// add 99.4.27 for M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_PRG);
// Write data.
for(int nSendAddress = nStartAddress; (long)nSendAddress < (long)nEndAddress; nSendAddress += 0x0100)
{
// Get hex data from file.
BYTE byteData[PAGE_SIZE];
ClearPage(byteData);
int nPage = nSendAddress / 0x0100;
GetPage(byteData, nPage);
// Prepare send data.
BYTE send[3 + PAGE_SIZE];
send[0] = 0x41;
ToSendStyle(nSendAddress, &send[2], &send[1]);
for(int nIndex = 0; nIndex < PAGE_SIZE; nIndex++)
{
send[nIndex + 3] = byteData[nIndex];
}
// Send data.
bResult = comObj.Write(send, 3 + PAGE_SIZE);
// Prograss Bar Update.
pDlg->SetProgressPos((nSendAddress - nStartAddress) / TO_INT);
// Implement the event.
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!pApp->PumpMessage()) {
::PostQuitMessage(0);
break;
}
}
if(bCancel)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_STOP_PROGRAM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
pDlg->Done();
return FALSE;
}
// Wait next Communicate.
//Sleep(SLEEP_IN); // change set Intervals time
Sleep(ndwintervals);
// add 99.4.27 for 20 2Mhz
// Check Status
bResult = !CheckState(&comObj, "program");
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
pDlg->Done();
return FALSE;
}
else
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
// add 99.4.27 for 20 2Mhz end
}
bIsEnd = bCancel;
pDlg->Done();// add 99.4.27 for 20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT5);
}
// Read Command
{
BOOL bResult = FALSE;
CM16CflshApp* pApp = (CM16CflshApp*)AfxGetApp();
MSG msg;
// Get Comm Object.
CSerialComm& comObj = GetSerialComm();
// Progress dialog setting.
CProgressDlg* pDlg;
BOOL bCancel = FALSE;
pDlg = CProgressDlg::Instance(&bCancel, NULL);
pDlg->InitialDialog("Read check.", "Read check.",
0, (nEndAddress - nStartAddress - 0x0100) / TO_INT, 0);
// verify address range.
for(int nSendAddress = nStartAddress; (long)nSendAddress < (long)nEndAddress;
nSendAddress += 0x0100)
{
// read data.
comObj.CleanUp(NULL);
BYTE receive[PAGE_SIZE];
if(!DoRead(&comObj, receive, nSendAddress))
{
pDlg->Done();
return FALSE;
}
// Get Hex Data.
BYTE byteData[PAGE_SIZE];
ClearPage(byteData);
int nPage = nSendAddress / 0x0100;
GetPage(byteData, nPage);
// verify
CString strOther;
for(int nIndex = 0; PAGE_SIZE > nIndex; nIndex++)
{
if( byteData[nIndex] != receive[nIndex])
{
// The difference was found.
CString strFindMsg = GetResString(IDS_FIND_NFILES);
strFindMsg += HexToStr(nSendAddress + nIndex);
AfxGetMainWnd()->MessageBox(strFindMsg, GetResString(IDS_FLASH_TITLE));
pDlg->Done();
return bResult;
}
}
// Progress Bar Update.
pDlg->SetProgressPos((nSendAddress - nStartAddress) / TO_INT);
// Event Loop
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!pApp->PumpMessage()) {
::PostQuitMessage(0);
break;
}
}
if(bCancel)
{
break;
}
Sleep(10);
}
pDlg->Done();
if(!bIsEnd)
{
// Check Status
bResult = !CheckState(&comObj, "program");
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
}
else
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
}
return bResult;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -