Esempio n. 1
0
 public static System.Data.DataTable getDataFromXLS(string strFilePath)
 {
     try
     {
         string strConnectionString = string.Empty;
         strConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFilePath + @";Extended Properties=""Excel 12.0 Macro;HDR=Yes;""";
         OleDbConnection cnCSV = new OleDbConnection(strConnectionString);
         cnCSV.Open();
         OleDbCommand     cmdSelect = new OleDbCommand(@"SELECT * FROM [symboldata$]", cnCSV);
         OleDbDataAdapter daCSV     = new OleDbDataAdapter();
         daCSV.SelectCommand = cmdSelect;
         System.Data.DataTable dtCSV = new System.Data.DataTable();
         daCSV.Fill(dtCSV);
         cnCSV.Close();
         daCSV = null;
         return(dtCSV);
     }
     catch (Exception ex)
     {
         frmInfoBox info = new frmInfoBox("Error failed OleDbConnection");
         logger.Debug(ex, "Error failed OldDbConnection");
         return(null);
     }
     finally { }
 }
Esempio n. 2
0
        private void ImportExcelSymbol(string symbolname, string filename)
        {
            bool issixteenbit = false;
            System.Data.DataTable dt = getDataFromXLS(openFileDialog2.FileName);
            if (isSixteenBitTable(symbolname)) issixteenbit = true;
            int symbollength = GetSymbolLength(m_symbols, symbolname);
            int datalength = symbollength;
            if (issixteenbit) datalength /= 2;
            int[] buffer = new int[datalength];
            int bcount = 0;
            //            for (int rtel = 1; rtel < dt.Rows.Count; rtel++)
            for (int rtel = dt.Rows.Count; rtel >= 1; rtel--)
            {
                try
                {
                    int idx = 0;
                    foreach (object o in dt.Rows[rtel].ItemArray)
                    {
                        if (idx > 0)
                        {
                            if (o != null)
                            {
                                if (o != DBNull.Value)
                                {
                                    if (bcount < buffer.Length)
                                    {
                                        buffer.SetValue(Convert.ToInt32(o), bcount++);
                                    }
                                    else
                                    {
                                        frmInfoBox info = new frmInfoBox("Too much information in file, abort");
                                        return;
                                    }
                                }
                            }
                        }
                        idx++;
                    }
                }
                catch (Exception E)
                {
                    logger.Debug("ImportExcelSymbol: " + E.Message);
                }

            }
            if (bcount >= datalength)
            {
                byte[] data = new byte[symbollength];
                int cellcount = 0;
                if (issixteenbit)
                {
                    for (int dcnt = 0; dcnt < buffer.Length; dcnt++)
                    {
                        string bstr1 = "0";
                        string bstr2 = "0";
                        int cellvalue = Convert.ToInt32(buffer.GetValue(dcnt));
                        string svalue = cellvalue.ToString("X4");

                        bstr1 = svalue.Substring(svalue.Length - 4, 2);
                        bstr2 = svalue.Substring(svalue.Length - 2, 2);
                        data.SetValue(Convert.ToByte(bstr1, 16), cellcount++);
                        data.SetValue(Convert.ToByte(bstr2, 16), cellcount++);
                    }
                }
                else
                {
                    for (int dcnt = 0; dcnt < buffer.Length; dcnt++)
                    {
                        int cellvalue = Convert.ToInt32(buffer.GetValue(dcnt));
                        data.SetValue(Convert.ToByte(cellvalue.ToString()), cellcount++);
                    }
                }
                savedatatobinary((int)GetSymbolAddress(m_symbols, symbolname), symbollength, data, m_currentfile, true);
                verifychecksum(false);
            }
        }
Esempio n. 3
0
 private void GetSRAMSnapshot()
 {
     if (CheckCANConnectivity())
     {
         m_prohibitReading = true;
         bool _success = false;
         SetProgress("Starting snapshot download");
         string filename = Path.GetDirectoryName(m_currentfile) + "\\SRAM" + DateTime.Now.Year.ToString("D4") + DateTime.Now.Month.ToString("D2") + DateTime.Now.Day.ToString("D2") + DateTime.Now.Hour.ToString("D2") + DateTime.Now.Minute.ToString("D2") + DateTime.Now.Second.ToString("D2") + DateTime.Now.Millisecond.ToString("D3") + ".RAM";
         if (m_CurrentWorkingProject != "")
         {
             if (!Directory.Exists(m_appSettings.ProjectFolder + "\\" + m_CurrentWorkingProject + "\\Snapshots")) Directory.CreateDirectory(m_appSettings.ProjectFolder + "\\" + m_CurrentWorkingProject + "\\Snapshots");
             filename = m_appSettings.ProjectFolder + "\\" + m_CurrentWorkingProject + "\\Snapshots\\Snapshot" + DateTime.Now.ToString("MMddyyyyHHmmss") + ".RAM";
         }
         if (trionic7.GetSRAMSnapshot(filename))
         {
             frmInfoBox info = new frmInfoBox("Snapshot downloaded and saved to: " + filename);
         }
         m_prohibitReading = false;
         SetProgressIdle();
     }
     else
     {
         // not connected to ECU
         frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to download a snapshot");
     }
 }
Esempio n. 4
0
        private static SIDICollection GetSidCollectionFromBinary(string m_currentfile)
        {
            SIDICollection m_sidcollection = new SIDICollection();
            FileStream stream = new FileStream(m_currentfile, FileMode.Open, FileAccess.Read);
            stream.Position = 0L;
            long num2 = 0L;
            bool flag = false;
            byte[] buffer = new byte[] { 0x41, 100, 0x70, 0x4e, 0, 0, 0 };
            do
            {
                if (((byte)stream.ReadByte()) == buffer[0])
                {
                    long position = stream.Position;
                    if (((byte)stream.ReadByte()) == buffer[1])
                    {
                        if ((((((byte)stream.ReadByte()) == buffer[2]) && (((byte)stream.ReadByte()) == buffer[3])) && ((((byte)stream.ReadByte()) == buffer[4]) && (((byte)stream.ReadByte()) == buffer[5]))) && (((byte)stream.ReadByte()) == buffer[6]))
                        {
                            flag = true;
                            num2 = stream.Position - 7L;
                        }
                    }
                    else
                    {
                        stream.Position = position;
                    }
                }
            }
            while (!flag && (stream.Position != 0x80000));
            if (!flag)
            {
                frmInfoBox info = new frmInfoBox("This T7 file is not compatible with the SIDI function in T7Suite!");
                return m_sidcollection;
            }
            stream.Position -= 7L;

            long start_pos = stream.Position;
            byte[] bytes = new byte[12];
            uint num4 = 0x53;           //?? fixed length?
            //int num5 = 0;
            for (int i = 0; i <= num4; i++)
            {
                //logger.Debug("*****" + i.ToString());
                /*if (i == 65)
                {
                    logger.Debug("65");
                }*/
                for (int j = 0; j <= 3; j++)
                {
                    bytes[j] = (byte)stream.ReadByte();
                }
                // set text
                SIDIHelper sidihelper = new SIDIHelper();
                sidihelper.Symbol = Encoding.Default.GetString(bytes, 0, 4);
                sidihelper.Symbol = sidihelper.Symbol.Replace((char)0x00, (char)0x20);
                //logger.Debug(i.ToString() + " = " + Encoding.Default.GetString(bytes, 0, 4));
                stream.Position += 3L;
                for (int k = 0; k <= 2; k++)
                {
                    bytes[k] = (byte)stream.ReadByte();
                }
                sidihelper.AddressSRAM = Convert.ToInt32(BitConverter.ToString(bytes, 0, 3).Replace("-", ""), 16);
                for (int m = 0; m <= 0; m++)
                {
                    bytes[m] = (byte)stream.ReadByte();
                }
                sidihelper.Value = BitConverter.ToString(bytes, 0, 1).Replace("-", "");
                m_sidcollection.Add(sidihelper);
                stream.Position += 1L; // skip one
            }
            if (stream != null)
            {
                stream.Close();
            }
            return m_sidcollection;
        }
Esempio n. 5
0
        private void File_EditTuningPackage(object sender, ItemClickEventArgs e)
        {
            if (tunpackeditWindow != null)
            {
                frmInfoBox info = new frmInfoBox("You have another tuning package edit window open, please close that first");
                return;
            }
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Trionic 7 packages|*.t7p";
            ofd.Multiselect = false;
            char[] sep = new char[1];
            sep.SetValue(',', 0);

            SymbolCollection scToImport = new SymbolCollection();
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("Map");
            dt.Columns.Add("Length");
            dt.Columns.Add("Data");

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //TODO: create a list of maps to import .. maybe?
                using (StreamReader sr = new StreamReader(ofd.FileName))
                {
                    string line = string.Empty;
                    SymbolHelper sh_Import = new SymbolHelper();
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("symbol="))
                        {
                            //
                            sh_Import = new SymbolHelper();
                            sh_Import.Varname = line.Replace("symbol=", "");
                        }
                        else if (line.StartsWith("length="))
                        {
                            sh_Import.Length = Convert.ToInt32(line.Replace("length=", ""));
                        }
                        else if (line.StartsWith("data="))
                        {
                            //
                            try
                            {
                                string dataBytes = line.Replace("data=", "");
                                // split using ','
                                string[] bytesInStrings = dataBytes.Split(sep);
                                byte[] dataToInsert = new byte[sh_Import.Length];
                                for (int t = 0; t < sh_Import.Length; t++)
                                {
                                    byte b = Convert.ToByte(bytesInStrings[t], 16);
                                    dataToInsert.SetValue(b, t);
                                }
                                int addressInFile = (int)GetSymbolAddress(m_symbols, sh_Import.Varname);
                                if (addressInFile > 0)
                                {
                                    //savedatatobinary(addressInFile, sh_Import.Length, dataToInsert, m_currentfile, true);
                                    // add successful
                                    dt.Rows.Add(sh_Import.Varname, sh_Import.Length.ToString(), dataBytes);
                                }
                                else
                                {
                                    // add failure
                                    dt.Rows.Add(sh_Import.Varname, sh_Import.Length.ToString(), dataBytes);
                                }
                            }
                            catch (Exception E)
                            {
                                // add failure
                                dt.Rows.Add(sh_Import.Varname, sh_Import.Length.ToString(), "");
                                logger.Debug(E.Message);
                            }
                        }
                    }
                }
                tunpackeditWindow = new frmEditTuningPackage();
                tunpackeditWindow.FormClosed += new FormClosedEventHandler(edit_FormClosed);
                tunpackeditWindow.onMapSelected += new frmEditTuningPackage.MapSelected(edit_onMapSelected);
                tunpackeditWindow.SetFilename(ofd.FileName);
                tunpackeditWindow.SetDataTable(dt);
                tunpackeditWindow.Show();

            }
        }
Esempio n. 6
0
        private void ExportToExcel(string mapname, int address, int length, byte[] mapdata, int cols, int rows, bool isSixteenbit, int[] xaxisvalues, int[] yaxisvalues)
        {
            //en-US
            CultureInfo tci = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentCulture = tci;

            try
            {
                bool isupsidedown = GetMapUpsideDown(mapname);
                try
                {
                    if (xla == null)
                    {
                        xla = new Microsoft.Office.Interop.Excel.Application();
                    }
                }
                catch (Exception xlaE)
                {
                    frmInfoBox info = new frmInfoBox("Failed to create office application interface");
                    logger.Debug("Failed to create office application interface: " + xlaE.Message);
                }

                // turn mapdata upside down
                if (isupsidedown)
                {
                    mapdata = TurnMapUpsideDown(mapdata, cols, rows, isSixteenbit);
                }

                xla.Visible = true;
                Microsoft.Office.Interop.Excel.Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
                Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)xla.ActiveSheet;
                ws.Name = "symboldata";

                // Now create the chart.
                ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
                ChartObject chartObj = chartObjs.Add(100, 400, 400, 300);
                Microsoft.Office.Interop.Excel.Chart xlChart = chartObj.Chart;

                int nRows = rows;
                if (isSixteenbit) nRows /= 2;
                int nColumns = cols;
                string upperLeftCell = "B3";
                int endRowNumber = System.Int32.Parse(upperLeftCell.Substring(1)) + nRows - 1;
                char endColumnLetter = System.Convert.ToChar(Convert.ToInt32(upperLeftCell[0]) + nColumns - 1);
                string upperRightCell = System.String.Format("{0}{1}", endColumnLetter, System.Int32.Parse(upperLeftCell.Substring(1)));
                string lowerRightCell = System.String.Format("{0}{1}", endColumnLetter, endRowNumber);
                // Send single dimensional array to Excel:

                Range rg1 = ws.get_Range("B2", "Z2");
                double[] xarray = new double[nColumns];
                double[] yarray = new double[nRows];
                ws.Cells[1, 1] = "Data for " + mapname;
                for (int i = 0; i < xarray.Length; i++)
                {
                    if (xaxisvalues.Length > i)
                    {
                        xarray[i] = (int)xaxisvalues.GetValue(i);
                    }
                    else
                    {
                        xarray[i] = i;
                    }
                    //ws.Cells[i + 3, 1] = xarray[i];
                    ws.Cells[2, 2 + i] = xarray[i];
                }
                for (int i = 0; i < yarray.Length; i++)
                {
                    if (yaxisvalues.Length > i)
                    {
                        if (isupsidedown)
                        {
                            yarray[i] = (int)yaxisvalues.GetValue((yarray.Length - 1) - i);
                        }
                        else
                        {
                            yarray[i] = (int)yaxisvalues.GetValue(i);
                        }
                    }
                    else
                    {
                        yarray[i] = i;
                    }
                    ws.Cells[i + 3, 1] = yarray[i];
                    //ws.Cells[2, 2 + i] = yarray[i];
                }

                string xaxisdescr = "x-axis";
                string yaxisdescr = "y-axis";
                string zaxisdescr = "z-axis";
                //GetAxisDescriptions(m_currentfile, m_symbols, mapname, out xaxisdescr, out yaxisdescr, out zaxisdescr);
                SymbolAxesTranslator axestrans = new SymbolAxesTranslator();
                string x_axis = string.Empty;
                string y_axis = string.Empty;
                axestrans.GetAxisSymbols(mapname, out x_axis, out y_axis, out xaxisdescr, out yaxisdescr, out zaxisdescr);

                Range rg = ws.get_Range(upperLeftCell, lowerRightCell);
                rg.Value2 = AddData(nRows, nColumns, mapdata, isSixteenbit);

                Range chartRange = ws.get_Range("A2", lowerRightCell);

                xlChart.SetSourceData(chartRange, Type.Missing);
                if (yarray.Length > 1)
                {
                    xlChart.ChartType = XlChartType.xlSurface;
                }

                // Customize axes:
                Axis xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory,
                    XlAxisGroup.xlPrimary);
                xAxis.HasTitle = true;
                xAxis.AxisTitle.Text = yaxisdescr;
                try
                {
                    Axis yAxis = (Axis)xlChart.Axes(XlAxisType.xlSeriesAxis,
                        XlAxisGroup.xlPrimary);
                    yAxis.HasTitle = true;
                    yAxis.AxisTitle.Text = xaxisdescr;
                }
                catch (Exception E)
                {
                    logger.Debug("Failed to set y axis: " + E.Message);
                }

                Axis zAxis = (Axis)xlChart.Axes(XlAxisType.xlValue,
                    XlAxisGroup.xlPrimary);
                zAxis.HasTitle = true;
                zAxis.AxisTitle.Text = zaxisdescr;

                // Add title:
                xlChart.HasTitle = true;

                xlChart.ChartTitle.Text = TranslateSymbolName(mapname);

                // Remove legend:
                xlChart.HasLegend = false;
                // add 3d shade
                xlChart.SurfaceGroup.Has3DShading = true;
                /*if (File.Exists(m_currentfile + "~" + mapname + ".xls"))
                {

                }*/
                try
                {
                    wb.SaveAs(m_currentfile + "~" + mapname + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, false, null, null, null, null);
                }
                catch (Exception sE)
                {
                    logger.Debug("Failed to save workbook: " + sE.Message);
                }

                /* This following code is used to create Excel default color indices:
                for (int i = 0; i < 14; i++)
                {
                    string cellString = "A" + (i + 1).ToString();
                    ws.get_Range(cellString, cellString).Interior.ColorIndex = i + 1;
                    ws.get_Range(cellString, cellString).Value2 = i + 1;
                    cellString = "B" + (i + 1).ToString();
                    ws.get_Range(cellString, cellString).Interior.ColorIndex = 14 + i + 1;
                    ws.get_Range(cellString, cellString).Value2 = 14 + i + 1;
                    cellString = "C" + (i + 1).ToString();
                    ws.get_Range(cellString, cellString).Interior.ColorIndex = 2 * 14 + i + 1;
                    ws.get_Range(cellString, cellString).Value2 = 2 * 14 + i + 1;
                    cellString = "D" + (i + 1).ToString();
                    ws.get_Range(cellString, cellString).Interior.ColorIndex = 3 * 14 + i + 1;
                    ws.get_Range(cellString, cellString).Value2 = 3 * 14 + i + 1;
                }*/
            }
            catch (Exception E)
            {
                logger.Debug("Failed to export to excel: " + E.Message);
            }
            tci = new CultureInfo("nl-NL");
            Thread.CurrentThread.CurrentCulture = tci;
        }
Esempio n. 7
0
        private void ConvertFileToDif(string filename, bool AutoExport)
        {
            System.Windows.Forms.Application.DoEvents();
            DateTime startDate = DateTime.MaxValue;
            DateTime endDate = DateTime.MinValue;
            try
            {
                SymbolCollection sc = new SymbolCollection();
                string[] alllines = File.ReadAllLines(filename);
                //using (StreamReader sr = new StreamReader(filename))
                {
                    //string line = string.Empty;
                    char[] sep = new char[1];
                    char[] sep2 = new char[1];
                    //int linecount = 0;
                    sep.SetValue('|', 0);
                    sep2.SetValue('=', 0);
                    //while ((line = sr.ReadLine()) != null)

                    foreach(string line in alllines)
                    {
                        string[] values = line.Split(sep);
                        if (values.Length > 0)
                        {
                            try
                            {
                                //dd/MM/yyyy HH:mm:ss
                                //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|";

                                string dtstring = (string)values.GetValue(0);
                                DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2)));
                                if (dt > endDate) endDate = dt;
                                if (dt < startDate) startDate = dt;
                                for (int t = 1; t < values.Length; t++)
                                {
                                    string subvalue = (string)values.GetValue(t);
                                    string[] subvals = subvalue.Split(sep2);
                                    if (subvals.Length == 2)
                                    {
                                        string varname = (string)subvals.GetValue(0);
                                        bool sfound = false;
                                        foreach (SymbolHelper sh in sc)
                                        {
                                            if (sh.Varname == varname || sh.Userdescription == varname)
                                            {
                                                sfound = true;
                                            }
                                        }
                                        SymbolHelper nsh = new SymbolHelper();
                                        nsh.Varname = varname;
                                        if (!sfound) sc.Add(nsh);
                                    }
                                }
                            }
                            catch (Exception pE)
                            {
                                logger.Debug(pE.Message);
                            }
                        }
                    }
                }

                if (AutoExport)
                {
                    foreach (SymbolHelper sh in sc)
                    {
                        sh.Color = GetColorFromRegistry(sh.Varname);
                    }
                    DifGenerator difgen = new DifGenerator();
                    difgen.AppSettings = m_appSettings;

                    //difgen.LowAFR = m_appSettings.WidebandLowAFR;
                    //difgen.HighAFR = m_appSettings.WidebandHighAFR;
                    //difgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage;
                    //difgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage;
                    difgen.WidebandSymbol = m_appSettings.WideBandSymbol;
                    //difgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol;
                    difgen.UseWidebandInput = false;

                    difgen.onExportProgress += new DifGenerator.ExportProgress(difgen_onExportProgress);
                    frmProgressLogWorks = new frmProgress();
                    frmProgressLogWorks.SetProgress("Exporting to LogWorks");
                    frmProgressLogWorks.Show();
                    System.Windows.Forms.Application.DoEvents();
                    try
                    {
                        difgen.ConvertFileToDif(filename, sc, startDate, endDate, m_appSettings.InterpolateLogWorksTimescale, m_appSettings.InterpolateLogWorksTimescale);
                    }
                    catch (Exception expE1)
                    {
                        logger.Debug(expE1.Message);
                    }
                    frmProgressLogWorks.Close();
                }
                else
                {

                    // show selection screen
                    frmPlotSelection plotsel = new frmPlotSelection();
                    foreach (SymbolHelper sh in sc)
                    {
                        plotsel.AddItemToList(sh.Varname);
                    }
                    plotsel.Startdate = startDate;
                    plotsel.Enddate = endDate;
                    plotsel.SelectAllSymbols();
                    if (plotsel.ShowDialog() == DialogResult.OK)
                    {
                        sc = plotsel.Sc;
                        endDate = plotsel.Enddate;
                        startDate = plotsel.Startdate;
                        DifGenerator difgen = new DifGenerator();
                        LogFilters filterhelper = new LogFilters();
                        difgen.SetFilters(filterhelper.GetFiltersFromRegistry());
                        difgen.AppSettings = m_appSettings;
                        //difgen.LowAFR = m_appSettings.WidebandLowAFR;
                        //difgen.HighAFR = m_appSettings.WidebandHighAFR;
                        //difgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage;
                        //difgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage;
                        difgen.WidebandSymbol = m_appSettings.WideBandSymbol;
                        //difgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol;
                        difgen.UseWidebandInput = false;

                        difgen.onExportProgress += new DifGenerator.ExportProgress(difgen_onExportProgress);
                        frmProgressLogWorks = new frmProgress();
                        frmProgressLogWorks.SetProgress("Exporting to LogWorks");
                        frmProgressLogWorks.Show();
                        System.Windows.Forms.Application.DoEvents();
                        try
                        {
                            if (difgen.ConvertFileToDif(filename, sc, startDate, endDate, m_appSettings.InterpolateLogWorksTimescale, m_appSettings.InterpolateLogWorksTimescale))
                            {
                                StartLogWorksWithCurrentFile(Path.GetDirectoryName(filename) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".dif");
                            }
                            else
                            {
                                frmInfoBox info = new frmInfoBox("No data was found to export!");
                            }
                        }
                        catch (Exception expE2)
                        {
                            logger.Debug(expE2.Message);
                        }
                        frmProgressLogWorks.Close();
                    }
                    TimeSpan ts = new TimeSpan(endDate.Ticks - startDate.Ticks);
                    //MessageBox.Show("LogFile should be " + ts.ToString());
                }
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
        }
Esempio n. 8
0
 private void btnUploadTuningPackage_ItemClick(object sender, ItemClickEventArgs e)
 {
     // upload a t7p file to the ECU
     if (m_currentfile != "")
     {
         if (CheckCANConnectivity())
         {
             OpenFileDialog ofd = new OpenFileDialog();
             ofd.Filter = "Trionic 7 packages|*.t7p";
             ofd.Multiselect = false;
             char[] sep = new char[1];
             sep.SetValue(',', 0);
             SymbolCollection scToImport = new SymbolCollection();
             if (ofd.ShowDialog() == DialogResult.OK)
             {
                 //TODO: create a list of maps to import .. maybe?
                 frmProgress progress = new frmProgress();
                 progress.SetProgress("Uploading tuning package...");
                 progress.Show();
                 using (StreamReader sr = new StreamReader(ofd.FileName))
                 {
                     string line = string.Empty;
                     SymbolHelper sh_Import = new SymbolHelper();
                     while ((line = sr.ReadLine()) != null)
                     {
                         if (line.StartsWith("symbol="))
                         {
                             //
                             sh_Import = new SymbolHelper();
                             sh_Import.Varname = line.Replace("symbol=", "");
                         }
                         else if (line.StartsWith("length="))
                         {
                             sh_Import.Length = Convert.ToInt32(line.Replace("length=", ""));
                         }
                         else if (line.StartsWith("data="))
                         {
                             //
                             try
                             {
                                 string dataBytes = line.Replace("data=", "");
                                 // split using ','
                                 string[] bytesInStrings = dataBytes.Split(sep);
                                 byte[] dataToInsert = new byte[sh_Import.Length];
                                 for (int t = 0; t < sh_Import.Length; t++)
                                 {
                                     byte b = Convert.ToByte(bytesInStrings[t], 16);
                                     dataToInsert.SetValue(b, t);
                                 }
                                 int addressInFile = (int)GetSymbolAddress(m_symbols, sh_Import.Varname);
                                 if (addressInFile > 0)
                                 {
                                     if (sh_Import.Varname != "MapChkCal.ST_Enable")
                                     {
                                         progress.SetProgress("Uploading: " + sh_Import.Varname);
                                         WriteMapToSRAM(sh_Import.Varname, dataToInsert, false);
                                         System.Windows.Forms.Application.DoEvents();
                                         Thread.Sleep(1);
                                     }
                                 }
                             }
                             catch (Exception E)
                             {
                                 // add failure
                                 logger.Debug(E.Message);
                             }
                         }
                     }
                 }
                 if (progress != null) progress.Close();
             }
         }
         else
         {
             frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to upload a tuning package");
         }
     }
 }
Esempio n. 9
0
        private void barButtonItem61_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (m_appSettings.Read_ecubatchfile != string.Empty)
            {
                try
                {
                    if (File.Exists(m_appSettings.Read_ecubatchfile))
                    {
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo(m_appSettings.Read_ecubatchfile);
                        process.Start();
                        process.WaitForExit();
                        // now, import the resulting S19 file
                        string fromfile = Path.GetDirectoryName(m_appSettings.Read_ecubatchfile) + "\\FROM_ECU.S19";
                        string destfile = Path.GetDirectoryName(m_currentfile) + "\\FROM_ECU" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".S19";
                        File.Copy(fromfile, destfile, true);
                        if (m_appSettings.TargetECUReadFile != string.Empty)
                        {
                            CloseProject();
                            m_appSettings.Lastprojectname = "";
                            File.Copy(fromfile, m_appSettings.TargetECUReadFile, true);
                            OpenFile(m_appSettings.TargetECUReadFile, false);
                            m_appSettings.LastOpenedType = 0;
                        }
                        else
                        {
                            CloseProject();
                            m_appSettings.Lastprojectname = "";
                            OpenFile(destfile, false);
                            m_appSettings.LastOpenedType = 0;

                        }
                    }
                    else
                    {
                        frmInfoBox info = new frmInfoBox("Batch file not found. Check parameters");
                    }
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message);
                }
            }
        }
Esempio n. 10
0
 private void barButtonItem41_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (m_currentfile != "")
     {
         openFileDialog1.Multiselect = false;
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             frmBinCompare bincomp = new frmBinCompare();
             //bincomp.SetSymbolCollection(m_symbols);
             //bincomp.OutsideSymbolBoundary = true;
             bincomp.SetCurrentFilename(m_currentfile);
             bincomp.SetCompareFilename(openFileDialog1.FileName);
             bincomp.CompareFiles();
             bincomp.ShowDialog();
         }
     }
     else
     {
         frmInfoBox info = new frmInfoBox("No file is currently opened, you need to open a binary file first to compare it to another one!");
     }
 }
Esempio n. 11
0
 private void barButtonItem16_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         if (File.Exists(System.Windows.Forms.Application.StartupPath + "//Trionic 7.pdf"))
         {
             System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "//Trionic 7.pdf");
         }
         else
         {
             frmInfoBox info = new frmInfoBox("Trionic 7 documentation could not be found or opened!");
         }
     }
     catch (Exception E2)
     {
         logger.Debug(E2.Message);
     }
 }
Esempio n. 12
0
 private void barButtonItem15_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         //T7_manual.pdf with user manual content
         if (File.Exists(System.Windows.Forms.Application.StartupPath + "//T7_manual.pdf"))
         {
             System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "//T7_manual.pdf");
         }
         else
         {
             frmInfoBox info = new frmInfoBox("T7Suite user manual could not be found or opened!");
         }
     }
     catch (Exception E2)
     {
         logger.Debug(E2.Message);
     }
 }
Esempio n. 13
0
        private bool verifychecksum(bool showinterface)
        {
            //Verify checksums and show result

            bool m_checksums_ok = true;
            if (File.Exists(m_currentfile))
            {
                T7FileHeader t7InfoHeader = null;
                t7InfoHeader = new T7FileHeader();
                t7InfoHeader.init(m_currentfile, m_appSettings.AutoFixFooter);

                ChecksumHandler csHandler = new ChecksumHandler();
                csHandler.SramOffset = m_currentSramOffsett;
                int fwLength = t7InfoHeader.getFWLength();
                int calculatedFWChecksum = csHandler.calculateFWChecksum(m_currentfile);

                uint calculatedF2Checksum = csHandler.calculateF2Checksum(m_currentfile, 0, fwLength);
                int calculatedFBChecksum = csHandler.calculateFBChecksum(m_currentfile, 0, fwLength);

                int readF2checksum = t7InfoHeader.getChecksumF2();
                int readFBchecksum = t7InfoHeader.getChecksumFB();

                if (readF2checksum != 0)
                {
                    if (t7InfoHeader.getChecksumF2() != (int)calculatedF2Checksum)
                    {
                        m_checksums_ok = false;
                    }
                }

                if (t7InfoHeader.getChecksumFB() != calculatedFBChecksum)
                {
                    m_checksums_ok = false;
                }
                if (csHandler.getFWChecksum(m_currentfile) != calculatedFWChecksum)
                {
                    m_checksums_ok = false;
                }
                if (m_checksums_ok)
                {
                    if (showinterface)
                    {
                        frmInfoBox info = new frmInfoBox("Checksums verified and all matched!");
                    }
                }
                else
                {
                    if (m_appSettings.AutoChecksum)
                    {
                        logger.Debug("calculatedF2Checksum = " + calculatedF2Checksum.ToString("X8") + " readF2checksum = " + readF2checksum.ToString("X8"));
                        logger.Debug("calculatedFBChecksum = " + calculatedFBChecksum.ToString("X8") + " readFBchecksum = " + readFBchecksum.ToString("X8"));
                        logger.Debug("calculatedFWChecksum = " + calculatedFWChecksum.ToString("X8") + " csHandler.getFWChecksum(m_currentfile) = " + csHandler.getFWChecksum(m_currentfile).ToString("X8"));

                        csHandler.setFWChecksum(m_currentfile, calculatedFWChecksum);
                        t7InfoHeader.setChecksumF2((int)calculatedF2Checksum);
                        t7InfoHeader.setChecksumFB(calculatedFBChecksum);
                        t7InfoHeader.save(m_currentfile);
                        if (showinterface)
                        {
                            frmInfoBox info = new frmInfoBox("Checksums did not verify ok, but were recalculated.");
                        }

                    }
                    else
                    {
                        if (MessageBox.Show("Checksums did not verify ok, do you want to recalculate and update the checksums?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            csHandler.setFWChecksum(m_currentfile, calculatedFWChecksum);
                            t7InfoHeader.setChecksumF2((int)calculatedF2Checksum);
                            t7InfoHeader.setChecksumFB(calculatedFBChecksum);
                            t7InfoHeader.save(m_currentfile);
                        }
                    }
                }
            }
            else
            {
                if (showinterface)
                {
                    frmInfoBox info = new frmInfoBox("Current file does not exsist, please re-open the file.");
                }
            }
            return m_checksums_ok;
        }
Esempio n. 14
0
 void tabdet_onWriteToSRAM(object sender, IMapViewer.WriteToSRAMEventArgs e)
 {
     // write data to SRAM, check for valid connection first
     bool writepossible = false;
     try
     {
         //if (flash != null)
         {
             if (CheckCANConnectivity())
             {
                 writepossible = true;
                 m_prohibitReading = true;
                 try
                 {
                     WriteMapToSRAM(e.Mapname, e.Data, true);
                 }
                 catch (Exception E)
                 {
                     logger.Debug("Failed to write to SRAM: " + E.Message);
                 }
             }
         }
         if (!writepossible)
         {
             frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to write data to the ECU");
         }
     }
     catch (Exception E)
     {
         logger.Debug("Failed to write map to SRAM: " + E.Message);
     }
     m_prohibitReading = false;
 }
Esempio n. 15
0
        void tabdet_onReadFromSRAM(object sender, IMapViewer.ReadFromSRAMEventArgs e)
        {
            // read data from SRAM through CAN bus and refresh the viewer with it
            bool writepossible = false;
            try
            {
                m_prohibitReading = true;
                //if (flash != null)
                {
                    if (CheckCANConnectivity())
                    {
                        writepossible = true;
                        //T5 byte[] resulttemp = tcan.readRAM((ushort)GetSymbolAddressSRAM(m_symbols, e.Mapname), (uint)GetSymbolLength(m_symbols, e.Mapname) + 1);
                        int symbolindex = GetSymbolNumberFromRealtimeList(GetSymbolNumber(m_symbols, e.Mapname), e.Mapname);
                        if (symbolindex >= 0)
                        {
                            //logger.Debug("Reading " + symbolindex.ToString() + " " + e.Mapname);
                            System.Windows.Forms.Application.DoEvents();
                            foreach (SymbolHelper shs in m_symbols)
                            {
                                if (shs.Varname == e.Mapname || shs.Userdescription == e.Mapname)
                                {
                                    try
                                    {
                                        byte[] result = ReadMapFromSRAM(shs, true);
                                        int rows = 0;
                                        int cols = 0;
                                        foreach (DockPanel pnl in dockManager1.Panels)
                                        {
                                            if (pnl.Text.StartsWith("Symbol: ") || pnl.Text.StartsWith("SRAM"))
                                            {
                                                foreach (Control c in pnl.Controls)
                                                {
                                                    if (c is IMapViewer)
                                                    {
                                                        IMapViewer vwr = (IMapViewer)c;
                                                        if (vwr.Map_name == e.Mapname)
                                                        {
                                                            vwr.Map_content = result;
                                                            GetTableMatrixWitdhByName(m_currentfile, m_symbols, e.Mapname, out cols, out rows);
                                                            if ((m_connectedToECU && !m_appSettings.UseNewMapViewer))
                                                            {
                                                                vwr.IsRAMViewer = true;
                                                            }
                                                            else
                                                            {
                                                                vwr.IsRAMViewer = false;
                                                            }

                                                            vwr.ShowTable(cols, isSixteenBitTable(e.Mapname));
                                                            if ((m_connectedToECU && m_appSettings.UseNewMapViewer) /*|| m_appSettings.DebugMode*/)
                                                            {
                                                                vwr.OnlineMode = true;
                                                                vwr.IsRAMViewer = true;
                                                            }
                                                            else
                                                            {
                                                                vwr.IsRAMViewer = false;
                                                            }
                                                        }
                                                    }
                                                    else if (c is DockPanel)
                                                    {
                                                        DockPanel tpnl = (DockPanel)c;
                                                        foreach (Control c2 in tpnl.Controls)
                                                        {
                                                            if (c2 is IMapViewer)
                                                            {
                                                                IMapViewer vwr2 = (IMapViewer)c2;
                                                                if (vwr2.Map_name == e.Mapname)
                                                                {
                                                                    vwr2.Map_content = result;
                                                                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, e.Mapname, out cols, out rows);
                                                                    if ((m_connectedToECU && !m_appSettings.UseNewMapViewer))
                                                                    {
                                                                        vwr2.IsRAMViewer = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        vwr2.IsRAMViewer = false;
                                                                    }

                                                                    vwr2.ShowTable(cols, isSixteenBitTable(e.Mapname));
                                                                    if ((m_connectedToECU && m_appSettings.UseNewMapViewer) /*|| m_appSettings.DebugMode*/)
                                                                    {
                                                                        vwr2.OnlineMode = true;
                                                                        vwr2.IsRAMViewer = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        vwr2.IsRAMViewer = false;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else if (c is ControlContainer)
                                                    {
                                                        ControlContainer cntr = (ControlContainer)c;
                                                        foreach (Control c3 in cntr.Controls)
                                                        {
                                                            if (c3 is IMapViewer)
                                                            {
                                                                IMapViewer vwr3 = (IMapViewer)c3;
                                                                if (vwr3.Map_name == e.Mapname)
                                                                {
                                                                    vwr3.Map_content = result;
                                                                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, e.Mapname, out cols, out rows);
                                                                    if ((m_connectedToECU && !m_appSettings.UseNewMapViewer))
                                                                    {
                                                                        vwr3.IsRAMViewer = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        vwr3.IsRAMViewer = false;
                                                                    }

                                                                    vwr3.ShowTable(cols, isSixteenBitTable(e.Mapname));
                                                                    if ((m_connectedToECU && m_appSettings.UseNewMapViewer) /*|| m_appSettings.DebugMode*/)
                                                                    {
                                                                        vwr3.OnlineMode = true;
                                                                        vwr3.IsRAMViewer = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        vwr3.IsRAMViewer = false;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                        }
                                    }
                                    catch (Exception E)
                                    {
                                        logger.Debug("Refresh viewer with SRAM data error: " + E.Message);
                                    }
                                    break;
                                }
                            }

                            /*byte[] result = ReadSymbolFromSRAM((uint)symbolindex);
                            string debugstring = "Data: ";
                            foreach (byte b in result)
                            {
                                debugstring += b.ToString("X2") + " ";
                            }
                            logger.Debug(debugstring);*/
                            //TODO: remove this line
                            //byte[] result = readdatafromfile(m_currentfile, (int)GetSymbolAddress(m_symbols, e.Mapname), (int)GetSymbolLength(m_symbols, e.Mapname));
                            //TODO: remove this line ^^
                            //MessageBox.Show("Data refreshed for symbol: " + e.Mapname);
                        }
                    }
                    /*else if(m_appSettings.DebugMode)
                    {
                        // only if debug
                        writepossible = true;
                        byte[] result = new byte[GetSymbolLength(m_symbols, e.Mapname)];
                        int rows = 0;
                        int cols = 0;
                        foreach (DevExpress.XtraBars.Docking.DockPanel pnl in dockManager1.Panels)
                        {
                            if (pnl.Text.StartsWith("Symbol: ") || pnl.Text.StartsWith("SRAM"))
                            {
                                foreach (Control c in pnl.Controls)
                                {
                                    if (c is IMapViewer)
                                    {
                                        IMapViewer vwr = (IMapViewer)c;
                                        if (vwr.Map_name == e.Mapname)
                                        {
                                            vwr.Map_content = result;
                                            GetTableMatrixWitdhByName(m_currentfile, m_symbols, e.Mapname, out cols, out rows);
                                            vwr.ShowTable(cols, isSixteenBitTable(e.Mapname));
                                        }
                                    }
                                    else if (c is DevExpress.XtraBars.Docking.DockPanel)
                                    {
                                        DevExpress.XtraBars.Docking.DockPanel tpnl = (DevExpress.XtraBars.Docking.DockPanel)c;
                                        foreach (Control c2 in tpnl.Controls)
                                        {
                                            if (c2 is IMapViewer)
                                            {
                                                IMapViewer vwr2 = (IMapViewer)c2;
                                                if (vwr2.Map_name == e.Mapname)
                                                {
                                                    vwr2.Map_content = result;
                                                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, e.Mapname, out cols, out rows);
                                                    vwr2.ShowTable(cols, isSixteenBitTable(e.Mapname));
                                                }
                                            }
                                        }
                                    }
                                    else if (c is DevExpress.XtraBars.Docking.ControlContainer)
                                    {
                                        DevExpress.XtraBars.Docking.ControlContainer cntr = (DevExpress.XtraBars.Docking.ControlContainer)c;
                                        foreach (Control c3 in cntr.Controls)
                                        {
                                            if (c3 is IMapViewer)
                                            {
                                                IMapViewer vwr3 = (IMapViewer)c3;
                                                if (vwr3.Map_name == e.Mapname)
                                                {
                                                    vwr3.Map_content = result;
                                                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, e.Mapname, out cols, out rows);
                                                    vwr3.ShowTable(cols, isSixteenBitTable(e.Mapname));
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }*/
                }
                if (!writepossible)
                {
                    frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to get data from the ECU");
                }
            }
            catch (Exception E)
            {
                logger.Debug("Failed to read MAP from SRAM: " + E.Message);
            }
            m_prohibitReading = false;
        }
 private void simpleButton2_Click(object sender, EventArgs e)
 {
     // show the details for this transaction (including data, meaning 2 mapviewers showing the details)
     frmInfoBox info = new frmInfoBox("Still needs to be implemented");
 }
Esempio n. 17
0
        private void btnTuneBinary_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (ValidateFile())
            {
                // read tuned marker to see if binary has been tuned before
                T7FileHeader fh = new T7FileHeader();
                fh.init(m_currentfile, m_appSettings.AutoFixFooter);
                PartNumberConverter pnc = new PartNumberConverter();
                ECUInformation ecuinfo = pnc.GetECUInfo(fh.getPartNumber().Trim(), "");
                //<GS-05102010> Need to validate the type of binary file loaded (which engine type and turbo type, A/M transmission)
                // and base the initially targeted torque and power figures on that
                frmTuningWizard tunWiz = new frmTuningWizard();

                string msg = "Partnumber not recognized, tuning will continue anyway, please verify settings afterwards";
                //msg += Environment.NewLine + " desired airmass " + maxairmass.ToString() + " mg/c and peak torque " + peaktorque.ToString() + " Nm";
                if (ecuinfo.Valid)
                {
                    msg = "Partnumber " + fh.getPartNumber() + ", carmodel " + ecuinfo.Carmodel.ToString() + ", engine " + ecuinfo.Enginetype.ToString();
                    //msg += Environment.NewLine + " desired airmass " + maxairmass.ToString() + " mg/c and peak torque " + peaktorque.ToString() + " Nm";
                }
                tunWiz.ExtraInfo = msg;

                if (ecuinfo.Stage1torque != 0)
                {
                    tunWiz.PeakTorque = Convert.ToInt32(ecuinfo.Stage1torque);
                }
                if (tunWiz.ShowDialog() == DialogResult.OK)
                {
                    int desiredHP = tunWiz.DesiredHP;
                    bool carRunsE85 = tunWiz.CarRunsE85;

                    // convert HP to torque and airmass
                    //int torque = PowerToTorque(desiredHP, 6000);
                    //int peaktorque = (110 * torque) / 100;
                    int peaktorque = tunWiz.PeakTorque;
                    int maxairmass = TorqueToAirmass(peaktorque, carRunsE85);

                    // give user a warning if airmass/c > 1300 mg/c
                    if (maxairmass > 1300)
                    {
                        frmInfoBox info = new frmInfoBox("Your maximum requested airmass exceeds 1300 mg/c [" + maxairmass.ToString() + " mg/c]. Please make sure all your other maps will support this airflow!");
                    }

                    TuneToStageNew(1, maxairmass, peaktorque, desiredHP, ecuinfo.Enginetype, carRunsE85);
                    TuningReport tuningrep = new TuningReport();
                    tuningrep.DataSource = resumeTuning;
                    tuningrep.CreateReport();
                    tuningrep.ShowPreview(defaultLookAndFeel1.LookAndFeel);
                }

                // start window to ask user for desired horses (depending on E85 usage?)
                /*frmTuneBinary frmTune = new frmTuneBinary();
                if (ecuinfo.Stage1torque != 0)
                {
                    frmTune.PeakTorque = Convert.ToInt32(ecuinfo.Stage1torque);
                }
                if (frmTune.ShowDialog() == DialogResult.OK)
                {
                    int desiredHP = frmTune.DesiredHP;
                    bool carRunsE85 = frmTune.CarRunsE85;

                    // convert HP to torque and airmass
                    //int torque = PowerToTorque(desiredHP, 6000);
                    //int peaktorque = (110 * torque) / 100;
                    int peaktorque = frmTune.PeakTorque;
                    int maxairmass = TorqueToAirmass(peaktorque, carRunsE85);

                    // give user a warning if airmass/c > 1300 mg/c
                    if (maxairmass > 1300)
                    {
                        MessageBox.Show("Your maximum requested airmass exceeds 1300 mg/c [" + maxairmass.ToString() + " mg/c]. Please make sure all your other maps will support this airflow!", "Warning!", MessageBoxButtons.OK);
                    }

                    string msg = "Partnumber not recognized, tuning will continue anyway, please verify settings afterwards";
                    msg += Environment.NewLine + " desired airmass " + maxairmass.ToString() + " mg/c and peak torque " + peaktorque.ToString() + " Nm";
                    if (ecuinfo.Valid)
                    {
                        msg = "Partnumber " + fh.getPartNumber() + ", carmodel " + ecuinfo.Carmodel.ToString() + ", engine " + ecuinfo.Enginetype.ToString();
                        msg += Environment.NewLine + " desired airmass " + maxairmass.ToString() + " mg/c and peak torque " + peaktorque.ToString() + " Nm";
                    }
                    PSTaskDialog.cTaskDialog.ForceEmulationMode = false;
                    PSTaskDialog.cTaskDialog.EmulatedFormWidth = 600;
                    PSTaskDialog.cTaskDialog.UseToolWindowOnXP = false;
                    PSTaskDialog.cTaskDialog.VerificationChecked = true;
                    PSTaskDialog.cTaskDialog.ShowTaskDialogBox("Tune me up™ wizard", "This wizard will tune your binary.", "Several maps will be altered" + Environment.NewLine + msg, "Happy driving!!!\nDilemma © 2009", "The author does not take responsibility for any damage done to your car or other objects in any form!", "Show me a summary after tuning", "", "Yes, tune me up!|No thanks!", eTaskDialogButtons.None, eSysIcons.Information, eSysIcons.Warning);
                    switch (PSTaskDialog.cTaskDialog.CommandButtonResult)
                    {
                        case 0:
                            // tune to stage x
                            // must use fixed maps, scaled to be good for the current airmass (e.g. pedalrequest map)
                            TuneToStageNew(1, maxairmass, peaktorque, desiredHP, ecuinfo.Enginetype, carRunsE85);
                            break;
                        case 1:
                            // cancel
                            break;
                    }
                    if (PSTaskDialog.cTaskDialog.VerificationChecked && PSTaskDialog.cTaskDialog.CommandButtonResult != 1)
                    {
                        TuningReport tuningrep = new TuningReport();
                        tuningrep.DataSource = resumeTuning;
                        tuningrep.CreateReport();
                        tuningrep.ShowPreview(defaultLookAndFeel1.LookAndFeel);
                    }
                }*/
            }
        }
Esempio n. 18
0
        private void barButtonItem62_ItemClick(object sender, ItemClickEventArgs e)
        {
            // write the required file for flashing the ECU
            // this is the current file, exported to S19 format in the directory that contains
            // the selected batchfile
            if (m_appSettings.Write_ecubatchfile != string.Empty)
            {
                try
                {
                    if (File.Exists(m_appSettings.Write_ecubatchfile))
                    {

                        if (!verifychecksum(false))
                        {
                            frmChecksumIncorrect check = new frmChecksumIncorrect();
                            if (m_appSettings.AutoChecksum)
                            {
                                UpdateChecksum(m_currentfile);
                                if (m_fileiss19)
                                {
                                    // automatisch terugschrijven
                                    srec2bin cnvrt = new srec2bin();
                                    cnvrt.ConvertBinToSrec(m_currentfile);
                                }

                            }
                            //else if (MessageBox.Show("Checksum invalid, auto correct?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            else if (check.ShowDialog() == DialogResult.Yes)
                            {
                                UpdateChecksum(m_currentfile);
                                if (m_fileiss19)
                                {
                                    // automatisch terugschrijven
                                    srec2bin cnvrt = new srec2bin();
                                    cnvrt.ConvertBinToSrec(m_currentfile);
                                }
                            }
                        }

                        srec2bin sr = new srec2bin();
                        sr.ConvertBinToSrec(m_currentfile);
                        // and copy it to the target directory
                        string fromfile = Path.GetDirectoryName(m_currentfile) + "\\" + Path.GetFileNameWithoutExtension(m_currentfile) + ".S19";
                        string destfile = Path.GetDirectoryName(m_appSettings.Write_ecubatchfile) + "\\TO_ECU.S19";
                        File.Copy(fromfile, destfile, true);
                        System.Diagnostics.Process.Start(m_appSettings.Write_ecubatchfile);
                    }
                    else
                    {
                        frmInfoBox info = new frmInfoBox("Batch file not found. Check parameters");
                    }
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message);
                }
            }
        }
Esempio n. 19
0
        private void btnViewMatrixFromLog_ItemClick(object sender, ItemClickEventArgs e)
        {
            // let the user select x axis, y axis and z axis symbols from the logfile
            //
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Trionic 7 logfiles|*.t7l";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                avgTable = null;
                string[] alllines = File.ReadAllLines(ofd.FileName);
                System.Windows.Forms.Application.DoEvents();
                DateTime startDate = DateTime.MaxValue;
                DateTime endDate = DateTime.MinValue;
                SymbolCollection sc = new SymbolCollection();
                try
                {
                    // using (StreamReader sr = new StreamReader(ofd.FileName))
                    {
                        //string line = string.Empty;

                        char[] sep = new char[1];
                        char[] sep2 = new char[1];
                        //int linecount = 0;
                        sep.SetValue('|', 0);
                        sep2.SetValue('=', 0);
                        //while ((line = sr.ReadLine()) != null)
                        foreach (string line in alllines)
                        {
                            string[] values = line.Split(sep);
                            if (values.Length > 0)
                            {
                                try
                                {
                                    //dd/MM/yyyy HH:mm:ss
                                    //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|";

                                    string dtstring = (string)values.GetValue(0);
                                    DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2)));
                                    if (dt > endDate) endDate = dt;
                                    if (dt < startDate) startDate = dt;
                                    for (int t = 1; t < values.Length; t++)
                                    {
                                        string subvalue = (string)values.GetValue(t);
                                        string[] subvals = subvalue.Split(sep2);
                                        if (subvals.Length == 2)
                                        {
                                            string varname = (string)subvals.GetValue(0);
                                            bool sfound = false;
                                            foreach (SymbolHelper sh in sc)
                                            {
                                                if (sh.Varname == varname)
                                                {
                                                    sfound = true;
                                                }
                                            }
                                            SymbolHelper nsh = new SymbolHelper();
                                            nsh.Varname = varname;
                                            if (!sfound) sc.Add(nsh);
                                        }
                                    }
                                }
                                catch (Exception pE)
                                {
                                    logger.Debug(pE.Message);
                                }
                            }
                        }
                    }
                }
                catch (Exception E)
                {
                    logger.Debug(E.Message);
                }
                frmMatrixSelection sel = new frmMatrixSelection();
                sel.SetSymbolList(sc);
                sel.SetXSelection(m_appSettings.LastXAxisFromMatrix);
                sel.SetYSelection(m_appSettings.LastYAxisFromMatrix);
                sel.SetZSelection(m_appSettings.LastZAxisFromMatrix);
                if (sel.ShowDialog() == DialogResult.OK)
                {
                    // get selected for x, y and z
                    int type = sel.GetViewType(); // <GS-31032011> 0 = mean values, 1 = minimum values, 2 = maximum values
                    string x = sel.GetXAxisSymbol();
                    string y = sel.GetYAxisSymbol();
                    string z = sel.GetZAxisSymbol();
                    m_appSettings.LastXAxisFromMatrix = x;
                    m_appSettings.LastYAxisFromMatrix = y;
                    m_appSettings.LastZAxisFromMatrix = z;
                    double xmin = Double.MaxValue;
                    double xmax = Double.MinValue;
                    double ymin = Double.MaxValue;
                    double ymax = Double.MinValue;
                    double zmin = Double.MaxValue;
                    double zmax = Double.MinValue;
                    //using (StreamReader sr = new StreamReader(ofd.FileName))
                    {
                        // string line = string.Empty;
                        char[] sep = new char[1];
                        char[] sep2 = new char[1];
                        //int linecount = 0;
                        sep.SetValue('|', 0);
                        sep2.SetValue('=', 0);
                        //while ((line = sr.ReadLine()) != null)

                        foreach (string line in alllines)
                        {
                            string[] values = line.Split(sep);
                            if (values.Length > 0)
                            {
                                try
                                {
                                    //dd/MM/yyyy HH:mm:ss
                                    //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|";

                                    string dtstring = (string)values.GetValue(0);
                                    DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2)));
                                    if (dt > endDate) endDate = dt;
                                    if (dt < startDate) startDate = dt;
                                    for (int t = 1; t < values.Length; t++)
                                    {
                                        string subvalue = (string)values.GetValue(t);
                                        string[] subvals = subvalue.Split(sep2);
                                        if (subvals.Length == 2)
                                        {
                                            string varname = (string)subvals.GetValue(0);
                                            double value = ConvertToDouble((string)subvals.GetValue(1));

                                            if (value > 65535) value = 0;
                                            if (value < -65535) value = 0;
                                            if (varname == x)
                                            {
                                                // get max and min

                                                if (value > xmax) xmax = value;
                                                if (value < xmin) xmin = value;
                                            }
                                            else if (varname == y)
                                            {
                                                // get max and min
                                                if (value > ymax) ymax = value;
                                                if (value < ymin) ymin = value;
                                            }
                                            else if (varname == z)
                                            {
                                                // get max and min
                                                if (value > zmax) zmax = value;
                                                if (value < zmin) zmin = value;
                                            }

                                        }
                                    }
                                }
                                catch (Exception pE)
                                {
                                    logger.Debug(pE.Message);
                                }
                            }
                        }
                    }
                    // now we have it all
                    if (xmin == xmax || ymin == ymax)
                    {
                        frmInfoBox info = new frmInfoBox("No data to display ... x or y axis contains no differentiated values");
                        return;
                    }
                    frmMatrixResult result = new frmMatrixResult();
                    result.SetViewType(type); // <GS-31032011> 0 = mean values, 1 = minimum values, 2 = maximum values

                    // parse the file again and add the points
                    System.Data.DataTable dtresult = new System.Data.DataTable();
                    // xmin = -0.8
                    // xmin = 2.01
                    double[] x_values = new double[16];
                    double[] y_values = new double[16];

                    // fill x and y axis
                    for (int i = 0; i < 16; i++)
                    {

                        double xvalue = xmin;
                        if (i > 0) xvalue = xmin + i * ((xmax - xmin) / (15));
                        //logger.Debug("Adding: " + xvalue.ToString());
                        try
                        {
                            dtresult.Columns.Add(xvalue.ToString(), Type.GetType("System.Double"));
                        }
                        catch (Exception E)
                        {
                            logger.Debug("Failed to add column: " + E.Message);
                        }
                        x_values.SetValue(xvalue, i); //    test: andersom?
                    }
                    for (int i = 0; i < 16; i++)
                    {
                        //double yvalue = ymin + ((ymax - ymin) / i);
                        double yvalue = ymin;
                        if (i > 0) yvalue = ymin + i * ((ymax - ymin) / (15));
                        y_values.SetValue(yvalue, i); //    test: andersom?
                    }
                    for (int i = 0; i < 16; i++)
                    {
                        try
                        {
                            dtresult.Rows.Add(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                        }
                        catch (Exception E)
                        {
                            logger.Debug("Failed to add empty row: " + E.Message);
                        }
                    }
                    // table filled
                    double _lastX = 0;
                    double _lastY = 0;
                    double _lastZ = 0;
                    //using (StreamReader sr = new StreamReader(ofd.FileName))
                    {
                        //string line = string.Empty;
                        char[] sep = new char[1];
                        char[] sep2 = new char[1];
                        //int linecount = 0;
                        sep.SetValue('|', 0);
                        sep2.SetValue('=', 0);
                        //while ((line = sr.ReadLine()) != null)
                        foreach (string line in alllines)
                        {
                            string[] values = line.Split(sep);
                            if (values.Length > 0)
                            {
                                try
                                {
                                    //dd/MM/yyyy HH:mm:ss
                                    //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|";

                                    string dtstring = (string)values.GetValue(0);
                                    DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2)));
                                    if (dt > endDate) endDate = dt;
                                    if (dt < startDate) startDate = dt;
                                    for (int t = 1; t < values.Length; t++)
                                    {
                                        string subvalue = (string)values.GetValue(t);
                                        string[] subvals = subvalue.Split(sep2);
                                        if (subvals.Length == 2)
                                        {
                                            string varname = (string)subvals.GetValue(0);
                                            double value = ConvertToDouble((string)subvals.GetValue(1));
                                            if (varname == x)
                                            {
                                                _lastX = value;
                                            }
                                            else if (varname == y)
                                            {
                                                _lastY = value;
                                            }
                                            else if (varname == z)
                                            {
                                                _lastZ = value;
                                            }

                                        }
                                    }
                                }
                                catch (Exception pE)
                                {
                                    logger.Debug(pE.Message);
                                }
                                // add point to the datatable
                                AddPointToDataTable(dtresult, _lastX, _lastY, _lastZ, xmin, xmax, ymin, ymax, zmin, zmax, type);
                            }
                        }
                    }
                    result.MaxValue = zmax;
                    result.MinValue = zmin;
                    result.SetXAxis(x_values);
                    result.SetYAxis(y_values);
                    result.SetXAxisName(x);
                    result.SetYAxisName(y);
                    result.SetZAxisName(z);
                    result.UseNewMapViewer = m_appSettings.UseNewMapViewer;
                    result.SetTable(dtresult);
                    string typedescr = " (Mean values)";
                    if (type == 1) typedescr = " (Minimum values)";
                    else if (type == 2) typedescr = " (Maximum values)";
                    result.Text = "Matrix [" + x + " : " + y + " : " + z + "]" + typedescr;
                    result.Show();
                }
            }
        }
Esempio n. 20
0
        private void barButtonItem81_ItemClick(object sender, ItemClickEventArgs e)
        {
            // read ECU
            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

                        SaveFileDialog sfd = new SaveFileDialog();
                        sfd.Filter = "Binary files|*.bin";
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {

                            mRecreateAllScriptResources(Path.GetDirectoryName(sfd.FileName));
                            barProgress.Visibility = BarItemVisibility.Always;
                            barProgress.EditValue = 0;
                            barProgress.Caption = "Dumping ECU";
                            System.Windows.Forms.Application.DoEvents();

                            _globalECUType = ecu_t.Trionic7;
                            fio_bytes = 0;
                            if (!BdmAdapter_DumpECU(sfd.FileName, ecu_t.Trionic7))
                            {
                                frmInfoBox info = new frmInfoBox("Failed to dump ECU");
                            }
                            DeleteScripts(Path.GetDirectoryName(sfd.FileName));
                        }

                    }
                }
                barProgress.Caption = "Dumping ECU";
                barProgress.EditValue = 0;
                barProgress.Visibility = BarItemVisibility.Never;
                System.Windows.Forms.Application.DoEvents();
            }
            catch (Exception BDMException)
            {
                logger.Debug("Failed to dump ECU: " + BDMException.Message);
                frmInfoBox info = new frmInfoBox("Failed to download firmware from ECU: " + BDMException.Message);
            }
        }
Esempio n. 21
0
 private void exportSymbollistAsCSVToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // export as CSV
     using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "CSV files|*.csv", Title = "Select a filename to save the symbollist" })
     {
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             using (StreamWriter sw = new StreamWriter(sfd.FileName, false))
             {
                 foreach (SymbolHelper sh in m_symbols)
                 {
                     sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6}", sh.Varname.Replace(',', '.'), sh.Flash_start_address, sh.Start_address, sh.Length, sh.Symbol_number, sh.Symbol_type, sh.Userdescription));
                 }
             }
             frmInfoBox info = new frmInfoBox("Export done");
         }
     }
 }
Esempio n. 22
0
        private void barButtonItem82_ItemClick(object sender, ItemClickEventArgs e)
        {
            // flash ECU
            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();
                        // program ECU through USB BDM
                        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;
                            barProgress.Visibility = BarItemVisibility.Always;
                            barProgress.Caption = "Erasing ECU";
                            System.Windows.Forms.Application.DoEvents();
                            _globalECUType = ecu_t.Trionic7;
                            BdmAdapter_EraseECU(ecu_t.Trionic7);
                            barProgress.Caption = "Flashing ECU";
                            System.Windows.Forms.Application.DoEvents();
                            Thread.Sleep(100);
                            BdmAdapter_FlashECU(ofd.FileName, ecu_t.Trionic7);
                            barProgress.Caption = "Resetting ECU";
                            System.Windows.Forms.Application.DoEvents();
                            Thread.Sleep(100);
                            DeleteScripts(Path.GetDirectoryName(ofd.FileName));
                        }

                    }
                }
                barProgress.EditValue = 0;
                barProgress.Caption = "Idle";
                barProgress.Visibility = BarItemVisibility.Never;
                System.Windows.Forms.Application.DoEvents();
            }
            catch (Exception BDMException)
            {
                logger.Debug("Failed to program ECU: " + BDMException.Message);
                frmInfoBox info = new frmInfoBox("Failed to program ECU: " + BDMException.Message);
            }
        }
Esempio n. 23
0
        private void File_CreateBackupFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (m_currentfile != string.Empty)
            {
                verifychecksum(false);

                if (File.Exists(m_currentfile))
                {
                    if (m_CurrentWorkingProject != "")
                    {
                        if (!Directory.Exists(m_appSettings.ProjectFolder + "\\" + m_CurrentWorkingProject + "\\Backups")) Directory.CreateDirectory(m_appSettings.ProjectFolder + "\\" + m_CurrentWorkingProject + "\\Backups");
                        string filename = m_appSettings.ProjectFolder + "\\" + m_CurrentWorkingProject + "\\Backups\\" + Path.GetFileNameWithoutExtension(GetBinaryForProject(m_CurrentWorkingProject)) + "-backup-" + DateTime.Now.ToString("MMddyyyyHHmmss") + ".BIN";
                        File.Copy(GetBinaryForProject(m_CurrentWorkingProject), filename);
                    }
                    else
                    {
                        File.Copy(m_currentfile, Path.GetDirectoryName(m_currentfile) + "\\" + Path.GetFileNameWithoutExtension(m_currentfile) + DateTime.Now.ToString("yyyyMMddHHmmss") + ".binarybackup", true);
                        frmInfoBox info = new frmInfoBox("Backup created: " + Path.GetDirectoryName(m_currentfile) + "\\" + Path.GetFileNameWithoutExtension(m_currentfile) + DateTime.Now.ToString("yyyyMMddHHmmss") + ".binarybackup");
                    }
                }
            }
        }
Esempio n. 24
0
 private void barButtonItem92_ItemClick(object sender, ItemClickEventArgs e)
 {
     // set E85.X_EthAct_Tech2
     if (SymbolExists("E85.X_EthAct_Tech2"))
     {
         ShowRealtimeMapFromECU("E85.X_EthAct_Tech2");
     }
     else
     {
         frmInfoBox info = new frmInfoBox("No E85 adaption symbol in this binary file");
     }
 }
Esempio n. 25
0
 private void File_SaveAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     //review all open editors and save the data still pending
     bool _datasaved = false;
     foreach (DockPanel pnl in dockManager1.Panels)
     {
         foreach (Control c in pnl.Controls)
         {
             if (c is IMapViewer)
             {
                 IMapViewer vwr = (IMapViewer)c;
                 if (vwr.SaveData()) _datasaved = true;
             }
             else if (c is DockPanel)
             {
                 DockPanel tpnl = (DockPanel)c;
                 foreach (Control c2 in tpnl.Controls)
                 {
                     if (c2 is IMapViewer)
                     {
                         IMapViewer vwr2 = (IMapViewer)c2;
                         if (vwr2.SaveData()) _datasaved = true;
                     }
                 }
             }
             else if (c is ControlContainer)
             {
                 ControlContainer cntr = (ControlContainer)c;
                 foreach (Control c3 in cntr.Controls)
                 {
                     if (c3 is IMapViewer)
                     {
                         IMapViewer vwr3 = (IMapViewer)c3;
                         if (vwr3.SaveData()) _datasaved = true;
                     }
                 }
             }
         }
     }
     if (_datasaved)
     {
         frmInfoBox info = new frmInfoBox("All pending changes saved to binary");
     }
     else
     {
         frmInfoBox info = new frmInfoBox("Binary was already up to date!");
     }
 }
Esempio n. 26
0
        private void barSyncToECU_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (m_currentfile != "")
            {
                if (MessageBox.Show("This will overwrite data in your ECU. Are you sure you want to proceed?", "Warning!", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    if (CheckCANConnectivity())
                    {
                        frmProgress progress = new frmProgress();
                        progress.Show();
                        progress.SetProgress("Start synchronization from binary to ECU");
                        System.Windows.Forms.Application.DoEvents();
                        int percentage = 0;
                        int symCnt = 0;
                        foreach (SymbolHelper sh in m_symbols)
                        {
                            // read from ECU, write to binary
                            if (sh.Start_address > 0x80000)
                            {
                                //if (sh.Varname.EndsWith("Map")) //TODO: <GS-28012011> REMOVE AFTER DEBUGGING
                                {
                                    string symbolname = sh.Varname;
                                    if (IsSymbolCalibration(symbolname))
                                    {
                                        if (symbolname.StartsWith("Symbolnumber") && sh.Userdescription != "") symbolname = sh.Userdescription;
                                        percentage = symCnt * 100 / m_symbols.Count;
                                        if (symCnt % 5 == 0)
                                        {
                                            progress.SetProgress("Sync to ECU: " + symbolname);
                                            progress.SetProgressPercentage(percentage);
                                        }
                                        byte[] mapdata = readdatafromfile(m_currentfile, (int)GetSymbolAddress(m_symbols, symbolname), sh.Length);
                                        // store in the ECU
                                        WriteMapToSRAM(symbolname, mapdata, false);
                                        Thread.Sleep(1);
                                    }
                                }

                            }
                            symCnt++;

                        }
                        if (progress != null) progress.Close();
                    }
                    else
                    {
                        frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to get data from the ECU");
                    }
                }
            }
        }
Esempio n. 27
0
 void frmfaults_onClearCurrentDTC(object sender, frmFaultcodes.ClearDTCEventArgs e)
 {
     // clear the currently selected DTC code from the ECU
     if (e.DTCCode.StartsWith("P"))
     {
         m_prohibitReading = true;
         try
         {
             int DTCCode = Convert.ToInt32(e.DTCCode.Substring(1, e.DTCCode.Length - 1), 16);
             if (CheckCANConnectivity())
             {
                 trionic7.ClearDTCCode(DTCCode);
             }
             if (sender is frmFaultcodes)
             {
                 frmFaultcodes frmfaults = (frmFaultcodes)sender;
                 bool _success = false;
                 frmfaults.ClearCodes();
                 int symbolnumber = GetSymbolNumber(m_symbols, "obdFaults");
                 if (symbolnumber == 0)
                 {
                     // not connected to ECU
                     frmInfoBox info = new frmInfoBox("Cannot find symbolnumber for symbol obdFaults, ECU binary must be loaded");
                 }
                 byte[] buffer = ReadSymbolFromSRAM((uint)symbolnumber, "obdFaults", (uint)GetSymbolAddressSRAM(m_symbols, "obdFaults"), GetSymbolLength(m_symbols, "obdFaults"), out _success);
                 if (_success)
                 {
                     for (int t = 0; t < buffer.Length; t += 2)
                     {
                         if (buffer[t] == 0x00 && buffer[t + 1] == 0x00)
                         {
                             break;
                         }
                         else
                         {
                             //faultCodes += "P" + buffer[t].ToString("X2") + buffer[t + 1].ToString("X2") + Environment.NewLine;
                             frmfaults.addFault("P" + buffer[t].ToString("X2") + buffer[t + 1].ToString("X2"));
                         }
                     }
                 }
             }
         }
         catch (Exception E)
         {
             logger.Debug(E.Message);
         }
         m_prohibitReading = false;
     }
 }
Esempio n. 28
0
        private void btnAutoTune_Click(object sender, EventArgs e)
        {
            //<GS-31012011> disable it immediately to prevent the user from multi-clicking the button and hence getting the system confused

            if (_currentEngineStatus.CurrentEngineTemp < 70)
            {
                frmInfoBox info = new frmInfoBox("Engine temperature of 70 degrees C not reached...");
                return;
            }

            btnAutoTune.Enabled = false;
            btnAutoTune.Text = "Wait...";
            System.Windows.Forms.Application.DoEvents();

            if (_autoTuning)
            {
                // switch OFF autotune
                //1. write data if needed?

                //2. Clear data that has been measured

                if (m_appSettings.DisableClosedLoopOnStartAutotune)
                {
                    SetLambdaControl(true);
                    SetE85Cal(true);
                    SetFCutCal(true);
                }

                SetStatusText("Autotune stopped.");
                btnAutoTune.ForeColor = Color.Empty;
                btnAutoTune.Text = "AutoTune";
                _autoTuning = false;
                ToggleRealtimePanel();

                if (m_appSettings.AutoUpdateFuelMap)
                {
                    //TODO: ask the user whether he wants to merge the altered fuelmap into ECU memory!
                    // if he replies NO: revert to the previous fuel map (we still need to preserve a copy!)
                    if (MessageBox.Show("Keep adjusted fuel map?", "Question", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        // save the original map back to the ECU
                        WriteMapToSRAM(m_appSettings.AutoTuneFuelMap, m_AFRMap.GetOriginalFuelmap(), true);
                    }
                    else
                    {
                        // save the altered map into the binary
                        foreach (SymbolHelper sh in m_symbols)
                        {
                            if (sh.Varname == m_appSettings.AutoTuneFuelMap || sh.Userdescription == m_appSettings.AutoTuneFuelMap)
                            {
                                //<GS-28012011>
                                if (IsSoftwareOpen())
                                {
                                    int symbolnumber = GetSymbolNumberFromRealtimeList(GetSymbolNumber(m_symbols, sh.Varname), sh.Varname);
                                    sh.Symbol_number = symbolnumber;
                                }

                                byte[] mapdata = ReadMapFromSRAM(sh, true);
                                savedatatobinary((int)GetSymbolAddress(m_symbols, sh.Varname), sh.Length, mapdata, m_currentfile, false);
                                UpdateChecksum(m_currentfile);
                            }
                        }
                    }
                    // init the afrmaps values
                    m_AFRMap.InitAutoTuneVars(true, 18, 16);
                }
                else
                {
                    //TODO: in that case, we've maintained the changes in the m_AFRMaps.FuelMapInformation struct
                    // we should now show the proposed changed (in percentages) to the user and let him/her
                    // decide which cells should be updated and which ones should be discarded
                    try
                    {
                        logger.Debug("Getting differences in percentages");
                        double[] diffinperc = m_AFRMap.GetPercentualDifferences();

                        System.Data.DataTable dt = new System.Data.DataTable();
                        for (int i = 0; i < 18; i++)
                        {
                            dt.Columns.Add(i.ToString(), Type.GetType("System.Double"));
                        }
                        for (int i = 15; i >= 0; i--)
                        {
                            object[] arr = new object[18];

                            for (int j = 0; j < 18; j++)
                            {
                                arr.SetValue(diffinperc[(i * 18) + j], j);
                            }
                            dt.Rows.Add(arr);
                        }
                        frmFuelMapAccept acceptMap = new frmFuelMapAccept();
                        acceptMap.Text = "Select percent mutations to accept for map " + m_appSettings.AutoTuneFuelMap;
                        acceptMap.onUpdateFuelMap += new frmFuelMapAccept.UpdateFuelMap(acceptMap_onUpdateFuelMap);
                        acceptMap.X_axisvalues = GetXaxisValues(m_currentfile, m_symbols, m_appSettings.AutoTuneFuelMap);
                        acceptMap.Y_axisvalues = GetYaxisValues(m_currentfile, m_symbols, m_appSettings.AutoTuneFuelMap);
                        acceptMap.AutoSizeColumns = m_appSettings.AutoSizeColumnsInWindows;
                        acceptMap.SetDataTable(dt);
                        acceptMap.ShowDialog();
                        System.Windows.Forms.Application.DoEvents();
                    }
                    catch (Exception E)
                    {
                        logger.Debug("Failed to stop autotune: " + E.Message);
                    }
                }
            }
            else
            {
                // switch ON autotune
                if (_softwareIsOpen)
                {
                    SetStatusText("Starting autotune...");
                    int _width = 18;
                    int _height = 16;
                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, m_appSettings.AutoTuneFuelMap, out _width, out _height);
                    if (m_AFRMap == null)
                    {
                        m_AFRMap = new AFRMap();
                        m_AFRMap.RpmYSP = GetSymbolAsIntArray("BFuelCal.RpmYSP");
                        m_AFRMap.AirXSP = GetSymbolAsIntArray("BFuelCal.AirXSP");
                        m_AFRMap.InitializeMaps(_width * _height, m_currentfile);
                    }

                    // fill BFuelCal.Map axis as integer values
                    m_AFRMap.RpmYSP = GetSymbolAsIntArray("BFuelCal.RpmYSP");
                    m_AFRMap.AirXSP = GetSymbolAsIntArray("BFuelCal.AirXSP");
                    m_AFRMap.InitAutoTuneVars(false, _width, _height); // this also clears the afr feedback map
                    // disable closed loop operation
                    if (m_appSettings.DisableClosedLoopOnStartAutotune)
                    {
                        // LambdaCal.ST_Enable?
                        SetLambdaControl(false);
                        SetE85Cal(false);
                        SetFCutCal(false);
                    }
                    // what's next?
                    // TODO: read the current fuel map into memory
                    byte[] fuelmap = new byte[18 * 16];
                    // is there something like spot adaption in T7?
                    bool _initOk = false;
                    foreach (SymbolHelper sh in m_symbols)
                    {
                        if (sh.Varname == m_appSettings.AutoTuneFuelMap || sh.Userdescription == m_appSettings.AutoTuneFuelMap)
                        {
                            fuelmap = ReadMapFromSRAM(sh, true);
                            //TODO: Fill AFRMaps with this?
                            m_AFRMap.SetCurrentFuelMap(fuelmap);
                            m_AFRMap.SetOriginalFuelMap(fuelmap);
                            m_AFRMap.AutoUpdateFuelMap = m_appSettings.AutoUpdateFuelMap;
                            m_AFRMap.CorrectionPercentage = m_appSettings.CorrectionPercentage;
                            m_AFRMap.AcceptableTargetErrorPercentage = m_appSettings.AcceptableTargetErrorPercentage;
                            m_AFRMap.CellStableTime_ms = m_appSettings.CellStableTime_ms;
                            m_AFRMap.MaximumAdjustmentPerCyclePercentage = m_appSettings.MaximumAdjustmentPerCyclePercentage;

                            _initOk = true;
                        }
                    }
                    if (_initOk)
                    {
                        _autoTuning = true;
                        SetStatusText("Autotune running...");
                        btnAutoTune.ForeColor = Color.Red;
                        btnAutoTune.Text = "Tuning...";
                    }
                    else
                    {
                        SetStatusText("Autotune init failed.");
                        // revert to closed loop
                        if (m_appSettings.DisableClosedLoopOnStartAutotune)
                        {
                            SetLambdaControl(true);
                            SetE85Cal(true);
                            SetFCutCal(true);
                        }
                    }
                }
                else
                {
                    frmInfoBox info = new frmInfoBox("Autotune is only available for OPEN binaries");
                }
            }
            btnAutoTune.Enabled = true;
            System.Windows.Forms.Application.DoEvents();
        }
Esempio n. 29
0
        private void Actions_btnCompareSRAMSnapshots_ItemClick(object sender, ItemClickEventArgs e)
        {
            // ask user to point out 2 SRAM files.
            OpenFileDialog ofd1 = new OpenFileDialog();

            ofd1.Title = "First SRAM dump...";
            ofd1.Filter = "SRAM dumps|*.ram";
            ofd1.Multiselect = false;
            if (ofd1.ShowDialog() == DialogResult.OK)
            {
                string filename_1 = ofd1.FileName;
                ofd1.Title = "Second SRAM dump...";
                if (ofd1.ShowDialog() == DialogResult.OK)
                {
                    string filename_2 = ofd1.FileName;
                    // now compare
                    System.Data.DataTable dt = new System.Data.DataTable();
                    dt.Columns.Add("SYMBOLNAME");
                    dt.Columns.Add("SRAMADDRESS", Type.GetType("System.Int32"));
                    dt.Columns.Add("FLASHADDRESS", Type.GetType("System.Int32"));
                    dt.Columns.Add("LENGTHBYTES", Type.GetType("System.Int32"));
                    dt.Columns.Add("LENGTHVALUES", Type.GetType("System.Int32"));
                    dt.Columns.Add("DESCRIPTION");
                    dt.Columns.Add("ISCHANGED", Type.GetType("System.Boolean"));
                    dt.Columns.Add("CATEGORY", Type.GetType("System.Int32")); //0
                    dt.Columns.Add("DIFFPERCENTAGE", Type.GetType("System.Double"));
                    dt.Columns.Add("DIFFABSOLUTE", Type.GetType("System.Int32"));
                    dt.Columns.Add("DIFFAVERAGE", Type.GetType("System.Double"));
                    dt.Columns.Add("CATEGORYNAME");
                    dt.Columns.Add("SUBCATEGORYNAME");
                    dt.Columns.Add("SymbolNumber1", Type.GetType("System.Int32"));
                    dt.Columns.Add("SymbolNumber2", Type.GetType("System.Int32"));
                    dt.Columns.Add("Userdescription");
                    int cnt = 0;
                    frmProgress progress = new frmProgress();
                    progress.SetProgress("Comparing SRAM snapshots");
                    progress.Show();
                    foreach (SymbolHelper sh in m_symbols)
                    {
                        int percentage = cnt * 100 / m_symbols.Count;
                        cnt++;
                        progress.SetProgressPercentage(percentage);
                        //SetTaskProgress(percentage, true);
                        string symbolname = sh.Varname;
                        if (symbolname.StartsWith("Symbol:")) symbolname = sh.Userdescription;
                        if (IsSymbolCalibration(symbolname))
                        {

                            byte[] data_1 = readdatafromSRAMfile(filename_1, (int)sh.Start_address, (int)sh.Length);
                            byte[] data_2 = readdatafromSRAMfile(filename_2, (int)sh.Start_address, (int)sh.Length);
                            if (data_1.Length != data_2.Length)
                            {
                                frmInfoBox info = new frmInfoBox("Sram data structure invalid... " + sh.Varname);
                                return;
                            }
                            else
                            {
                                double diffperc = 0;
                                int diffabs = 0;
                                double diffavg = 0;
                                bool isdifferent = false;
                                if (isSixteenBitTable(sh.Varname))
                                {
                                    for (int i = 0; i < data_1.Length; i += 2)
                                    {
                                        try
                                        {
                                            int value1 = (int)(byte)data_1.GetValue(i) * 256;
                                            value1 += (int)(byte)data_1.GetValue(i + 1);
                                            int value2 = (int)(byte)data_2.GetValue(i) * 256;
                                            value2 += (int)(byte)data_2.GetValue(i + 1);
                                            if (value1 != value2)
                                            {
                                                isdifferent = true;
                                                diffabs++;
                                            }
                                        }
                                        catch (Exception E)
                                        {
                                            logger.Debug(E.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < data_1.Length; i++)
                                    {
                                        if ((byte)data_1.GetValue(i) != (byte)data_2.GetValue(i))
                                        {
                                            isdifferent = true;
                                            diffabs++;
                                        }
                                    }
                                }
                                if (isdifferent)
                                {
                                    int lengthvalues = sh.Length;
                                    if (isSixteenBitTable(sh.Varname)) lengthvalues /= 2;
                                    diffperc = (diffabs * 100) / lengthvalues;
                                    dt.Rows.Add(sh.Varname, sh.Start_address, sh.Flash_start_address, sh.Length, lengthvalues, sh.Description, false, 0, diffperc, diffabs, diffavg, sh.Category.ToString().Replace("_", " "), sh.Subcategory.ToString().Replace("_", " "), sh.Symbol_number, sh.Symbol_number, sh.Userdescription);
                                }
                            }
                        }

                    }
                    progress.Close();
                    SymbolCollection compSymbols = new SymbolCollection();
                    //AddressLookupCollection compAddressLookup = new AddressLookupCollection();
                    dockManager1.BeginUpdate();
                    try
                    {
                        DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                        SRAMCompareResults tabdet = new SRAMCompareResults();
                        tabdet.Dock = DockStyle.Fill;
                        tabdet.Filename1 = filename_1;
                        tabdet.Filename2 = filename_2;
                        tabdet.onSRAMSymbolSelect += new SRAMCompareResults.NotifySRAMSelectSymbol(tabdet_onSRAMSymbolSelect);
                        dockPanel.Controls.Add(tabdet);
                        //dockPanel.DockAsTab(dockPanel1);
                        dockPanel.Text = "SRAM compare results: " + Path.GetFileName(filename_1) + " " + Path.GetFileName(filename_2);
                        bool isDocked = false;
                        foreach (DockPanel pnl in dockManager1.Panels)
                        {
                            if (pnl.Text.StartsWith("SRAM compare results: ") && pnl != dockPanel && (pnl.Visibility == DockVisibility.Visible))
                            {
                                dockPanel.DockAsTab(pnl, 0);
                                isDocked = true;
                                break;
                            }
                        }
                        if (!isDocked)
                        {
                            dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);
                            dockPanel.Width = 700;
                        }
                        //CompareSymbolTable(filename, compSymbols, compAddressLookup, tabdet.gridControl1);
                        tabdet.gridControl1.DataSource = dt;
                        //tabdet.CompareTrionic5Tools.SymbolCollection = compSymbols;
                        //tabdet.CompareAddressLookupCollection = compAddressLookup;
                        tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
                    }
                    catch (Exception E)
                    {
                        logger.Debug(E.Message);
                    }
                    dockManager1.EndUpdate();
                    SetStatusText("SRAM compare done");
                    //SetTaskProgress(0, false);

                }
            }
        }
Esempio n. 30
0
        private void btnGenerateTuningPackage_ItemClick(object sender, ItemClickEventArgs e)
        {
            // generate the default maps as a tuning package from the ECUs SRAM
            if (m_currentfile != "")
            {
                if (CheckCANConnectivity())
                {
                    frmProgress progress = new frmProgress();
                    progress.SetProgress("Downloading tuning package...");
                    progress.Show();
                    SymbolCollection scToExport = new SymbolCollection();
                    PackageExporter pe = new PackageExporter();
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Trionic 7 packages|*.t7p";
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        AddToSymbolCollection(scToExport, "LimEngCal.TurboSpeedTab"); // add axis
                        AddToSymbolCollection(scToExport, "LimEngCal.p_AirSP");
                        AddToSymbolCollection(scToExport, "AirCtrlCal.m_MaxAirTab"); // add axis
                        AddToSymbolCollection(scToExport, "TempLimPosCal.Airmass");
                        //AddToSymbolCollection(scToExport, "X_AccPedalAutSP");
                        AddToSymbolCollection(scToExport, "BoostCal.RegMap");   // add axis
                        AddToSymbolCollection(scToExport, "BoostCal.SetLoadXSP");
                        AddToSymbolCollection(scToExport, "BoostCal.n_EngSP");
                        AddToSymbolCollection(scToExport, "PedalMapCal.m_RequestMap");// add axis
                        AddToSymbolCollection(scToExport, "PedalMapCal.n_EngineMap");
                        AddToSymbolCollection(scToExport, "PedalMapCal.X_PedalMap");
                        AddToSymbolCollection(scToExport, "BstKnkCal.MaxAirmass");  // add axis
                        AddToSymbolCollection(scToExport, "BstKnkCal.OffsetXSP");
                        AddToSymbolCollection(scToExport, "BstKnkCal.n_EngYSP");
                        AddToSymbolCollection(scToExport, "BstKnkCal.MaxAirmassAu"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_EngMaxAutTab"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_EngMaxTab"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_EngMaxE85Tab"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_ManGearLim"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_CabGearLim"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.n_Eng5GearSP");
                        AddToSymbolCollection(scToExport, "TorqueCal.M_5GearLimTab"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_NominalMap"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.m_AirXSP");
                        AddToSymbolCollection(scToExport, "TorqueCal.n_EngYSP");
                        AddToSymbolCollection(scToExport, "TorqueCal.m_AirTorqMap"); // add axis
                        AddToSymbolCollection(scToExport, "TorqueCal.M_EngXSP");
                        AddToSymbolCollection(scToExport, "TorqueCal.m_PedYSP");
                        AddToSymbolCollection(scToExport, "FCutCal.m_AirInletLimit");
                        AddToSymbolCollection(scToExport, "BoosDiagCal.m_FaultDiff");
                        AddToSymbolCollection(scToExport, "BoosDiagCal.ErrMaxMReq");
                        AddToSymbolCollection(scToExport, "BFuelCal.Map");
                        AddToSymbolCollection(scToExport, "BFuelCal.StartMap");
                        AddToSymbolCollection(scToExport, "BFuelCal.E85Map");
                        AddToSymbolCollection(scToExport, "BFuelCal.AirXSP");
                        AddToSymbolCollection(scToExport, "BFuelCal.RpmYSP");
                        AddToSymbolCollection(scToExport, "InjCorrCal.InjectorConst");
                        AddToSymbolCollection(scToExport, "IgnNormCal.Map");
                        AddToSymbolCollection(scToExport, "IgnE85Cal.fi_AbsMap");
                        AddToSymbolCollection(scToExport, "IgnNormCal.m_AirXSP");
                        AddToSymbolCollection(scToExport, "IgnNormCal.n_EngYSP");
                        AddToSymbolCollection(scToExport, "IgnKnkCal.IndexMap");
                        AddToSymbolCollection(scToExport, "KnkFuelCal.fi_MapMaxOff");
                        AddToSymbolCollection(scToExport, "KnkFuelCal.m_AirXSP");
                        AddToSymbolCollection(scToExport, "BoostCal.PMap");
                        AddToSymbolCollection(scToExport, "BoostCal.IMap");
                        AddToSymbolCollection(scToExport, "BoostCal.DMap");
                        AddToSymbolCollection(scToExport, "BoostCal.PIDXSP");
                        AddToSymbolCollection(scToExport, "BoostCal.PIDYSP");
                        AddToSymbolCollection(scToExport, "TorqueCal.M_OverBoostTab");
                        AddToSymbolCollection(scToExport, "TorqueCal.n_EngYSP");
                        AddToSymbolCollection(scToExport, "KnkFuelCal.EnrichmentMap");
                        AddToSymbolCollection(scToExport, "IgnKnkCal.m_AirXSP");
                        AddToSymbolCollection(scToExport, "IgnKnkCal.n_EngYSP");
                        AddToSymbolCollection(scToExport, "KnkDetCal.RefFactorMap");
                        AddToSymbolCollection(scToExport, "KnkDetCal.m_AirXSP");
                        AddToSymbolCollection(scToExport, "KnkDetCal.n_EngYSP");
                        AddToSymbolCollection(scToExport, "MaxSpdCal.T_EngineSP");
                        AddToSymbolCollection(scToExport, "MaxSpdCal.n_EngLimAir");
                        AddToSymbolCollection(scToExport, "MaxVehicCal.v_MaxSpeed");
                        //pe.ExportPackage(scToExport, m_currentfile, sfd.FileName);
                        if (File.Exists(sfd.FileName)) File.Delete(sfd.FileName);
                        foreach (SymbolHelper sh in scToExport)
                        {
                            //<GS-28012011>

                            progress.SetProgress("Downloading: " + sh.Varname);
                            System.Windows.Forms.Application.DoEvents();
                            byte[] data = ReadMapFromSRAM(sh, false);
                            pe.ExportMap(sfd.FileName, sh.Varname, sh.Userdescription, sh.Length, data);
                            Thread.Sleep(1);
                        }
                    }
                    if (progress != null) progress.Close();
                }
                else
                {
                    frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to download a tuning package");
                }
            }
        }
Esempio n. 31
0
        private void ImportFileInExcelFormat()
        {
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string mapname = string.Empty;
                    int tildeindex = openFileDialog2.FileName.LastIndexOf("~");
                    bool symbolfound = false;
                    if (tildeindex > 0)
                    {
                        tildeindex++;
                        mapname = openFileDialog2.FileName.Substring(tildeindex, openFileDialog2.FileName.Length - tildeindex);
                        mapname = mapname.Replace(".xls", "");
                        mapname = mapname.Replace(".XLS", "");
                        mapname = mapname.Replace(".Xls", "");
                        // look if it is a valid symbolname
                        foreach (SymbolHelper sh in m_symbols)
                        {
                            if (sh.Varname == mapname || sh.Userdescription == mapname)
                            {
                                symbolfound = true;
                                if (MessageBox.Show("Found valid symbol for import: " + mapname + ". Are you sure you want to overwrite the map in the binary?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    // ok, overwrite info in binary
                                }
                                else
                                {
                                    mapname = string.Empty; // do nothing
                                }
                            }
                        }
                        if (!symbolfound)
                        {
                            // ask user for symbol designation
                            frmSymbolSelect frmselect = new frmSymbolSelect(m_symbols);
                            if (frmselect.ShowDialog() == DialogResult.OK)
                            {
                                mapname = frmselect.SelectedSymbol;
                            }
                        }

                    }
                    else
                    {
                        // ask user for symbol designation
                        frmSymbolSelect frmselect = new frmSymbolSelect(m_symbols);
                        if (frmselect.ShowDialog() == DialogResult.OK)
                        {
                            mapname = frmselect.SelectedSymbol;
                        }

                    }
                    if (mapname != string.Empty)
                    {
                        ImportExcelSymbol(mapname, openFileDialog2.FileName);
                    }

                }
                catch (Exception E)
                {
                    frmInfoBox info = new frmInfoBox("Failed to import map from excel: " + E.Message);
                }
            }
        }
Esempio n. 32
0
        private void btnReadFaultCodes_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (CheckCANConnectivity())
            {
                // 16 25 16 22 00 00 00 00 00 00 00 00
                frmFaultcodes frmfaults = new frmFaultcodes();
                frmfaults.onClearCurrentDTC += new frmFaultcodes.onClearDTC(frmfaults_onClearCurrentDTC);
                m_prohibitReading = true;
                bool _success = false;
                string faultCodes = string.Empty;
                int symbolnumber = GetSymbolNumber(m_symbols, "obdFaults");
                if (symbolnumber == 0)
                {
                    // not connected to ECU
                    frmInfoBox info = new frmInfoBox("Cannot find symbolnumber for symbol obdFaults, ECU binary must be loaded");
                }
                byte[] buffer = ReadSymbolFromSRAM((uint)symbolnumber, "obdFaults", (uint)GetSymbolAddressSRAM(m_symbols, "obdFaults"), GetSymbolLength(m_symbols, "obdFaults"), out _success);
                if (_success)
                {
                    for (int t = 0; t < buffer.Length; t += 2)
                    {
                        if (buffer[t] == 0x00 && buffer[t + 1] == 0x00)
                        {
                            break;
                        }
                        else
                        {
                            //faultCodes += "P" + buffer[t].ToString("X2") + buffer[t + 1].ToString("X2") + Environment.NewLine;
                            frmfaults.addFault("P" + buffer[t].ToString("X2") + buffer[t + 1].ToString("X2"));
                        }
                    }
                }

                frmfaults.Show();
                m_prohibitReading = false;

            }
            else
            {
                // not connected to ECU
                frmInfoBox info = new frmInfoBox("An active CAN bus connection is needed to read faultcodes");
            }
        }