From 9d5c6170994c632413caa0915e98131dea515abc Mon Sep 17 00:00:00 2001 From: mattiasclaesson Date: Sat, 16 Jan 2016 10:14:58 +0100 Subject: [PATCH] Corrected flash change mistake --- TrionicCANFlasher/frmMain.cs | 68 +++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/TrionicCANFlasher/frmMain.cs b/TrionicCANFlasher/frmMain.cs index 6de5e851..0af7f90f 100644 --- a/TrionicCANFlasher/frmMain.cs +++ b/TrionicCANFlasher/frmMain.cs @@ -86,9 +86,14 @@ private void AddLogItem(string item) private void btnFlashEcu_Click(object sender, EventArgs e) { DialogResult result = DialogResult.Cancel; - if(cbxEcuType.SelectedIndex == (int)ECU.TRIONIC8) - result = MessageBox.Show("Power on ECU", - "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); + if (cbxEcuType.SelectedIndex == (int)ECU.TRIONIC8 || cbxEcuType.SelectedIndex == (int)ECU.MOTRONIC96) + result = MessageBox.Show("Attach a charger. Now turn key to ON to wakeup ECU.", + "Critical Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); + else if (cbxEcuType.SelectedIndex == (int)ECU.TRIONIC7) + { + result = MessageBox.Show("Attach a charger. Turn key to ON wait a few seconds, turn to LOCK. Wait 15 to 20 seconds then initiate the flash operation in car.", + "Critical Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); + } if (result == DialogResult.Cancel) { return; @@ -100,7 +105,30 @@ private void btnFlashEcu_Click(object sender, EventArgs e) { if (checkFileSize(ofd.FileName)) { - if (cbxEcuType.SelectedIndex == (int)ECU.TRIONIC8) + if (cbxEcuType.SelectedIndex == (int)ECU.TRIONIC7) + { + SetGenericOptions(trionic7); + trionic7.UseFlasherOnDevice = cbUseFlasherOnDevice.Checked; + + AddLogItem("Opening connection"); + EnableUserInput(false); + if (trionic7.openDevice()) + { + Thread.Sleep(1000); + AddLogItem("Update FLASH content"); + Application.DoEvents(); + dtstart = DateTime.Now; + trionic7.WriteFlash(ofd.FileName); + } + else + { + AddLogItem("Unable to connect to Trionic 7 ECU"); + trionic7.Cleanup(); + EnableUserInput(true); + AddLogItem("Connection terminated"); + } + } + else if (cbxEcuType.SelectedIndex == (int)ECU.TRIONIC8) { ChecksumResult checksum = ChecksumT8.VerifyChecksum(ofd.FileName); if (checksum != ChecksumResult.Ok) @@ -122,7 +150,37 @@ private void btnFlashEcu_Click(object sender, EventArgs e) Application.DoEvents(); BackgroundWorker bgWorker; bgWorker = new BackgroundWorker(); - bgWorker.DoWork += new DoWorkEventHandler(trionic8.RestoreT8); + bgWorker.DoWork += new DoWorkEventHandler(trionic8.WriteFlash); + bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted); + bgWorker.WorkerReportsProgress = true; + bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged); + bgWorker.RunWorkerAsync(ofd.FileName); + } + else + { + AddLogItem("Unable to connect to Trionic 8 ECU"); + trionic8.Cleanup(); + EnableUserInput(true); + AddLogItem("Connection terminated"); + } + } + else if (cbxEcuType.SelectedIndex == (int)ECU.MOTRONIC96) + { + SetGenericOptions(trionic8); + + EnableUserInput(false); + AddLogItem("Opening connection"); + trionic8.SecurityLevel = AccessLevel.AccessLevel01; + trionic8.ECU = ECU.MOTRONIC96; + if (trionic8.openDevice(false)) + { + Thread.Sleep(1000); + dtstart = DateTime.Now; + AddLogItem("Update FLASH content"); + Application.DoEvents(); + BackgroundWorker bgWorker; + bgWorker = new BackgroundWorker(); + bgWorker.DoWork += new DoWorkEventHandler(trionic8.WriteFlashME96); bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted); bgWorker.WorkerReportsProgress = true; bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged);