📄 m16cflsh.cpp
字号:
// Check ID.
CIDCheckDlg startDlg;
nResponse = startDlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Please describe the cord in the time that the dialog was put out with <OK>.
}
else if (nResponse == IDCANCEL)
{
// TODO: Please describe the cord in the time that the dialog was put out with <Cancel>.
}
{
//Transmission the lead status command.
BYTE newsend = 0x70;
GetSerialComm().CleanUp(NULL);
GetSerialComm().Write(&newsend, 1);
BYTE receive[2];
if(!GetSerialComm().Read(receive, 2))
{
CommError();
return FALSE;
}
VDC_ON_OFF_STATUS = 1 & (receive[1] >> 0);
}
} else {
// Select Program/Download File.
CSelectDlg selectDlg;
int nResponse = selectDlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Please describe the cord in the time that the dialog was put out with <OK>.
}
else if (nResponse == IDCANCEL)
{
// TODO: Please describe the cord in the time that the dialog was put out with <Cancel>.
}
}
// Go to mainmenu.
CM16CflshDlg dlg;
m_pMainWnd = &dlg;
nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Please describe the cord in the time that the dialog was put out with <OK>.
dlg.checkComm();
}
else if (nResponse == IDCANCEL)
{
// TODO: Please describe the cord in the time that the dialog was put out with <Cancel>.
}
GetSerialComm().Close();
//Please return FALSE to end the application, than the message pump of the application
// is started after the dialog being closed.
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CM16CflshApp class menber fanction
// Initial setting serial communication.
void
CM16CflshApp::SetFirstSerialState(CSerialComm& objSerialComm,
DWORD dwBaudrate, BYTE btByteSize, BYTE btParity, BYTE btStopBits)
{
CSerialCommState commState;
commState.m_dwBaudRate = dwBaudrate; // boudrate
commState.m_byByteSize = btByteSize; // byte size
commState.m_byParity = btParity; // parity
commState.m_byStopBits = btStopBits; // stop bit
objSerialComm.SetState(&commState);
}
// Setting serial commuicartion palamator
DWORD
CM16CflshApp::SetSerialState(CSerialComm& objSerialComm,
DWORD dwBaudrate, BYTE btByteSize, BYTE btParity, BYTE btStopBits, int msgID)
{
CSerialCommState commState;
objSerialComm.GetState(&commState);
if(!ChengeBaudrate(commState.m_dwBaudRate, dwBaudrate))
{
AfxGetMainWnd()->MessageBox(GetResString(msgID), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
objSerialComm.GetState(&commState);
dwBaudrate = commState.m_dwBaudRate;
}
commState.m_dwBaudRate = dwBaudrate; // baudrate
// commState.m_byByteSize = btByteSize; // byte size
// commState.m_byParity = btParity; // parity
// commState.m_byStopBits = btStopBits; // stop bit
commState.m_byByteSize = DEFAULT_BYTESIZE; // byte size
commState.m_byParity = DEFAULT_PARITY; // parity
commState.m_byStopBits = DEFAULT_STOPBITS; // stop bit
objSerialComm.SetState(&commState);
//Communication confirmation
BYTE btSend = 0;
BYTE receive = 0;
btSend = baudrateToSendStyle(dwBaudrate);
objSerialComm.Write(&btSend, 1);
BOOL bReceive = objSerialComm.Read(&receive, 1);
if(!bReceive || receive != btSend)
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_NSETCOMM), NULL, MB_ICONERROR);
// return 0;
dwBaudrate = CommError();
}
return dwBaudrate;
}
// Last setting of serial communication parameter
void CM16CflshApp::SetLastSerialState(CSerialComm& objSerialComm)
{
CSerialCommState commState;
objSerialComm.GetState(&commState);
if(!ChengeBaudrate(commState.m_dwBaudRate, DEFAULT_BAUDRATE))
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_SET_BAUDRATE_LAST), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
return;
}
commState.m_dwBaudRate = DEFAULT_BAUDRATE; // baudrate
commState.m_byByteSize = DEFAULT_BYTESIZE; // byte size
commState.m_byParity = DEFAULT_PARITY; // parity
commState.m_byStopBits = DEFAULT_STOPBITS; // stop bit
objSerialComm.SetState(&commState);
//Communication confirmation
BYTE btSend = 0;
BYTE receive = 0;
btSend = baudrateToSendStyle(DEFAULT_BAUDRATE);
objSerialComm.Write(&btSend, 1);
BOOL bReceive = objSerialComm.Read(&receive, 1);
if(!bReceive || receive != btSend)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_SET_BAUDRATE_LAST), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
}
// fspr type
CString D_Type;
CSaveIni objInit;
if(NULL != objInit.LoadDType())
{
#if _DEBUG
printf("INI file setting before %s \n", D_Type);
#endif
objInit.GetDType(&D_Type);
}
objInit.SetDType(D_Type);
objInit.SaveDType();
}
//Transforme baudrate int transmission data.
const BYTE CM16CflshApp::baudrateToSendStyle(DWORD dwBaudrate)
{
BYTE btRet = 0;
if(dwBaudrate == CBR_9600)
{
btRet = 0xB0;
}
else if(dwBaudrate == CBR_19200)
{
btRet = 0xB1;
}
else if(dwBaudrate == CBR_38400)
{
btRet = 0xB2;
}
else if(dwBaudrate == CBR_57600)
{
btRet = 0xB3;
}
else if(dwBaudrate == CBR_115200)
{
btRet = 0xB4;
}
return btRet;
}
// Change baudrate.
BOOL CM16CflshApp::ChengeBaudrate(DWORD dwNowB, DWORD dwNewB)
{
BOOL bResult = FALSE;
BYTE btNowB = baudrateToSendStyle(dwNowB);
BYTE btNewB = baudrateToSendStyle(dwNewB);
// Cange baudrate.
GetSerialComm().CleanUp(NULL);
Sleep(SLEEP_IN);
BYTE receive = 0;
GetSerialComm().Write(&btNowB, 1);
bResult = GetSerialComm().Read(&receive, 1);
if(!bResult || receive != btNowB)
{
GetSerialComm().CleanUp(NULL);
return FALSE;
}
Sleep(SLEEP_ONE);
receive = 0;
GetSerialComm().Write(&btNewB, 1);
bResult = GetSerialComm().Read(&receive, 1);
if(!bResult || receive != btNewB)
{
GetSerialComm().CleanUp(NULL);
return FALSE;
}
Sleep(SLEEP_ONE);
return TRUE;
}
//Processing at the communication error.
DWORD CM16CflshApp::CommError(void)
{
DWORD dwResult = 0;
int status = 0;
m_objSerial.CleanUp(NULL);
if(m_objSerial.IsTimeout())
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_TIMEOUT), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
status = AfxGetMainWnd()->MessageBox(GetResString(IDS_TIMEOUT), GetResString(IDS_FLASH_TITLE), MB_ICONERROR | MB_OKCANCEL );
// status = AfxMessageBox(GetResString(IDS_TIMEOUT) ,MB_OKCANCEL | MB_OKCANCEL );
}
else
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_GIVE_UP), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
status = AfxGetMainWnd()->MessageBox(GetResString(IDS_GIVE_UP), GetResString(IDS_FLASH_TITLE), MB_ICONERROR | MB_OKCANCEL );
// status = AfxMessageBox(GetResString(IDS_GIVE_UP), MB_OKCANCEL | MB_OKCANCEL );
}
if( status == IDCANCEL ){
::CloseHandle(GetMutex());
GetSerialComm().Close();
PostQuitMessage(0);
// AfxGetApp()->HideApplication();
// AfxGetApp()->CloseAllDocuments(FALSE);
// AfxGetMainWnd()->PostMessage( WM_DESTROY );
return dwResult;
}
SetAcceptedComm(FALSE);
SetAcceptedID(FALSE);
// Reset communication setting to default.
CSaveIni objInit;
objInit.SetComm(DEF_BAUDRATE, DEF_BYTE_SIZE, DEF_STOP_BITS, DEF_PARITY);
objInit.SaveComm();
SetFirstSerialState(m_objSerial, DEF_BAUDRATE, DEF_BYTE_SIZE, DEF_STOP_BITS, DEF_PARITY);
// add 99.4.23 send 0x00 x16
{
CString Z_Type = "-Z";
CSaveIni objInit;
if(NULL != objInit.LoadZType())
{
objInit.GetZType(&Z_Type);
}
#if _DEBUG
printf(" func type = %s\n", Z_Type);
#endif
// BYTE BtSnd0 = 0xB0;
BYTE BtSnd0;
if( Z_Type == "+Z" )
{
BtSnd0 = 0xB0;
} else {
BtSnd0 = 0x00;
}
BYTE btCommChkR = 0;
GetSerialComm().Write(&BtSnd0, 1);
Sleep(SLEEP_IN);
for(int i = 0; i < SEND_00_TIMES ; i++)
{
BtSnd0 = 0x00;
GetSerialComm().Write(&BtSnd0, 1);
Sleep(20);
}
Sleep(SLEEP_IN);
BtSnd0 = 0xB0;
GetSerialComm().Write(&BtSnd0, 1);
Sleep(SLEEP_IN);
}
// add end
if (!GetFlashType())
{ //nomal
// start
//I make transmission data.
BYTE send[SEND_ID];
send[0] = 0xf5;
send[1] = 0x00;
send[2] = 0x00;
send[3] = 0x00;
send[4] = ID_SIZE;
send[5] = 0x00;
send[6] = 0x00;
send[7] = 0x00;
send[8] = 0x00;
send[9] = 0x00;
send[10] = 0x00;
send[11] = 0x00;
//A command is transmitted.
GetSerialComm().Write(send, 12);
Sleep(SLEEP_IN);
SetAcceptedID(FALSE);
// add end
{
//Transmission the lead status command.
//(VDC_ON_OFF_STATUS UPDATE)
BYTE newsend = 0x70;
GetSerialComm().CleanUp(NULL);
GetSerialComm().Write(&newsend, 1);
BYTE receive[2];
GetSerialComm().Read(receive, 2);
VDC_ON_OFF_STATUS = 1 & (receive[1] >> 0);
// UpdateData(FALSE);
}
}
else
{
// Flash Type = M16C/80 boot loader
}
CSettingCmd cmd;
// Implement setting command.
if(dwResult = cmd.exec())
{
}
else
{
// Processing when error.
}
return dwResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -