private void btnUSBBDMWriteECU_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { // program ECU through USB BDM bool _continue = true; try { if (!_globalBDMOpened) { if (!BdmAdapter_Open()) { frmInfoBox info = new frmInfoBox("Could not connect to the BDM adapter"); _continue = false; } } if (_continue) { _globalBDMOpened = true; if (BDMversion == 0) { if (!BdmAdapter_GetVersion(ref BDMversion)) { frmInfoBox info1 = new frmInfoBox("BDM adapter is not compatible"); _continue = false; } } if (_continue) { // adapter opened and version is compatible BdmAdapter_GetVerifyFlash(); // program ECU through USB BDM frmECUBDMTypeSelection typesel = new frmECUBDMTypeSelection(); if (typesel.ShowDialog() == DialogResult.OK) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Binary files|*.bin"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { mRecreateAllScriptResources(Path.GetDirectoryName(ofd.FileName)); fio_bytes = 0; SetStatusText("Erasing ECU"); _globalECUType = typesel.GetECUType(); BdmAdapter_EraseECU(typesel.GetECUType()); SetStatusText("Flashing ECU"); Thread.Sleep(100); BdmAdapter_FlashECU(ofd.FileName, typesel.GetECUType()); SetStatusText("Resetting ECU"); Thread.Sleep(100); DeleteScripts(Path.GetDirectoryName(ofd.FileName)); } } } } SetStatusText("Idle"); barEditItem1.EditValue = 0; System.Windows.Forms.Application.DoEvents(); } catch (Exception BDMException) { Console.WriteLine("Failed to program ECU: " + BDMException.Message); frmInfoBox info= new frmInfoBox("Failed to program ECU: " + BDMException.Message); } }
private void btnUSBBDMReadECU_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { // read the ECU through USB BDM bool _continue = true; try { if (!_globalBDMOpened) { if (!BdmAdapter_Open()) { frmInfoBox info = new frmInfoBox("Could not connect to the BDM adapter"); _continue = false; } } if (_continue) { _globalBDMOpened = true; if (BDMversion == 0) { if (!BdmAdapter_GetVersion(ref BDMversion)) { frmInfoBox info = new frmInfoBox("BDM adapter is not compatible"); _continue = false; } } if (_continue) { // adapter opened and version is compatible //BdmAdapter_GetVerifyFlash(); // read ECU through USB BDM frmECUBDMTypeSelection typesel = new frmECUBDMTypeSelection(); if (typesel.ShowDialog() == DialogResult.OK) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Binary files|*.bin"; if (sfd.ShowDialog() == DialogResult.OK) { mRecreateAllScriptResources(Path.GetDirectoryName(sfd.FileName)); barEditItem1.EditValue = 0; SetStatusText("Dumping ECU"); System.Windows.Forms.Application.DoEvents(); _globalECUType = typesel.GetECUType(); fio_bytes = 0; if (!BdmAdapter_DumpECU(sfd.FileName, typesel.GetECUType())) { frmInfoBox info = new frmInfoBox("Failed to dump ECU"); } DeleteScripts(Path.GetDirectoryName(sfd.FileName)); } } } } SetStatusText("Idle"); barEditItem1.EditValue = 0; System.Windows.Forms.Application.DoEvents(); } catch (Exception BDMException) { Console.WriteLine("Failed to dump ECU: " + BDMException.Message); frmInfoBox info = new frmInfoBox("Failed to download firmware from ECU: " + BDMException.Message); } }