/// <summary> /// Get strings for actual values from language read by connection /// The text for unit is automatically alternative unit, if factor is set /// <param name="NoAltUnit">True to use original unit, false for alternative unit (if available)</param> /// </summary> public void RefreshLanguage(bool NoAltUnit) { mProtocol.SetValueAltUnitFlag(NoAltUnit); for (byte i = 0; i < mValueNumber; i++) { Item[i] = new ActualValueItem(); Item[i].Name = mProtocol.GetValueName(i); Item[i].Unit = mProtocol.GetValueUnit(i); Item[i].Hidden = mProtocol.GetValueHiddenFlag(i); Item[i].Display = mProtocol.GetValueDisplayFlag(i); } }
/// <summary>Export error ring data to a XML file</summary> /// <param name="Filename">Target file name</param> /// <param name="protocol">Reference to protocol to connected ECU</param> public void XmlExport(string Filename, ref ProtocolBase protocol) { XmlWriter xf = null; XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = false; settings.ConformanceLevel = ConformanceLevel.Document; settings.Encoding = System.Text.Encoding.UTF8; //"iso-8859-1"; settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineOnAttributes = false; try { xf = XmlWriter.Create(Filename, settings); xf.WriteStartElement("err_ring_root"); xf.WriteStartElement("ECU"); xf.WriteStartElement("Serialnumber"); xf.WriteValue(protocol.SerialNumber); xf.WriteEndElement(); // S/N xf.WriteStartElement("Hardware"); xf.WriteValue(string.Format("{0}.{1}.{2}", protocol.HardwareVersion.Hauptversion, protocol.HardwareVersion.Nebenversion, protocol.HardwareVersion.Revision)); xf.WriteEndElement(); // HW V xf.WriteStartElement("Software"); xf.WriteValue(string.Format("{0}.{1}.{2}", protocol.SoftwareVersion.Hauptversion, protocol.SoftwareVersion.Nebenversion, protocol.SoftwareVersion.Revision)); xf.WriteEndElement(); // SW V xf.WriteStartElement("Configuration"); xf.WriteValue(string.Format("{0}.{1}.{2}", protocol.ConfigurationVersion.Hauptversion, protocol.ConfigurationVersion.Nebenversion, protocol.ConfigurationVersion.Revision)); xf.WriteEndElement(); // CFG V //xf.WriteStartElement("Datamap"); //xf.WriteValue(string.Format("{0}.{1}.{2}", protocol.DatamapVersion.Hauptversion, protocol.DatamapVersion.Nebenversion, protocol.DatamapVersion.Revision)); //xf.WriteEndElement(); // KF V xf.WriteEndElement(); // ECU xf.WriteStartElement("ring_data"); for (int item = 0; item < mItem.Length; item++) { xf.WriteStartElement("item"); xf.WriteAttributeString("row", String.Format("{0}", item)); xf.WriteStartElement("date"); xf.WriteValue(mItem[item].Date); xf.WriteEndElement(); xf.WriteStartElement("error_no"); xf.WriteValue(mItem[item].ErrorNo); xf.WriteEndElement(); xf.WriteStartElement("error_name"); xf.WriteValue(protocol.GetErrorName(mItem[item].ErrorNo)); xf.WriteEndElement(); xf.WriteStartElement("error_type"); xf.WriteValue(protocol.IsEventOrError((UInt16)item) ? "Event" : "Fehler"); xf.WriteEndElement(); if (mItem[item].TaskId == 255) { // Verhalten aenderung xf.WriteStartElement("task"); xf.WriteValue(mItem[item].TaskId); xf.WriteEndElement(); xf.WriteStartElement("lfd_no"); xf.WriteValue(mItem[item].LfdNo); xf.WriteEndElement(); xf.WriteStartElement("mask"); xf.WriteValue(mItem[item].Wert1); xf.WriteEndElement(); } else { // Fehler / Event aufgetreten xf.WriteStartElement("task"); xf.WriteValue(mItem[item].TaskId); xf.WriteEndElement(); xf.WriteStartElement("lfd_no"); xf.WriteValue(mItem[item].LfdNo); xf.WriteEndElement(); if (mItem[item].ErrorNo > 63) { xf.WriteStartElement("value_1_value"); xf.WriteValue(mItem[item].Wert1); xf.WriteEndElement(); xf.WriteStartElement("value_2_value"); xf.WriteValue(mItem[item].Wert2); xf.WriteEndElement(); xf.WriteStartElement("value_3_value"); xf.WriteValue(mItem[item].Wert3); xf.WriteEndElement(); } else { xf.WriteStartElement("value_1_name"); xf.WriteValue(protocol.GetValueName(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 0)))); xf.WriteEndElement(); xf.WriteStartElement("value_1_value"); xf.WriteValue(protocol.GetValueString(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 0)), mItem[item].Wert1)); xf.WriteEndElement(); xf.WriteStartElement("value_1_unit"); xf.WriteValue(protocol.GetValueUnit(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 0)))); xf.WriteEndElement(); xf.WriteStartElement("value_2_name"); xf.WriteValue(protocol.GetValueName(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 1)))); xf.WriteEndElement(); xf.WriteStartElement("value_2_value"); xf.WriteValue(protocol.GetValueString(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 1)), mItem[item].Wert2)); xf.WriteEndElement(); xf.WriteStartElement("value_2_unit"); xf.WriteValue(protocol.GetValueUnit(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 1)))); xf.WriteEndElement(); xf.WriteStartElement("value_3_name"); xf.WriteValue(protocol.GetValueName(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 2)))); xf.WriteEndElement(); xf.WriteStartElement("value_3_value"); xf.WriteValue(protocol.GetValueString(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 2)), mItem[item].Wert3)); xf.WriteEndElement(); xf.WriteStartElement("value_3_unit"); xf.WriteValue(protocol.GetValueUnit(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 2)))); xf.WriteEndElement(); } } xf.WriteEndElement(); // item } xf.WriteEndElement(); // data xf.WriteEndElement(); // root xf.Flush(); } catch (Exception ex) { Console.WriteLine("Exception during opening XML file: {0}", ex.Message); } finally { xf.Close(); } }
/// <summary>Export error ring data to a CSV file</summary> /// <param name="Filename">Target file name</param> /// <param name="protocol">Reference to protocol to connected ECU</param> public void CsvExport(string Filename, ref ProtocolBase protocol) { System.IO.StreamWriter writer = new System.IO.StreamWriter(Filename, false); string _ProgDate = ""; if (protocol.LocalTime) { _ProgDate = protocol.DateOfProgramming.ToLocalTime().ToString("dd.MM.yyyy HH:mm"); } else { _ProgDate = protocol.DateOfProgramming.ToUniversalTime().ToString("dd.MM.yyyy HH:mm UTC"); } // string header = String.Format("Production date: {0} SN: {1} HW:V{2}.{3}.{4} SW:V{5}.{6}.{7} CFG:V{8}.{9}.{10}", _ProgDate, protocol.SerialNumber, protocol.HardwareVersion.Hauptversion, protocol.HardwareVersion.Nebenversion, protocol.HardwareVersion.Revision, protocol.SoftwareVersion.Hauptversion, protocol.SoftwareVersion.Nebenversion, protocol.SoftwareVersion.Revision, protocol.ConfigurationVersion.Hauptversion, protocol.ConfigurationVersion.Nebenversion, protocol.ConfigurationVersion.Revision ); writer.WriteLine(header); string title = String.Format("\"Datum/Zeit\"{0}\"Task No.\"{0}\"Lfd. No.\"{0}\"Fehler No.\"{0}\"Fehlername\"{0}\"Fehler/Ereignis\"{0}\"Zustand\"{0}\"Name 1\"{0}\"Wert 1\"{0}\"Einheit 1\"{0}\"Name 2\"{0}\"Wert 2\"{0}\"Einheit 2\"{0}\"Name 3\"{0}\"Wert 3\"{0}\"Einheit 3\"", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator); writer.WriteLine(title); string _row_start = ""; string _row_tail = ""; for (int item = 0; item < mItem.Length; item++) { if (protocol.LocalTime) { _ProgDate = mItem[item].Date.ToLocalTime().ToString("dd.MM.yyyy HH:mm"); } else { _ProgDate = mItem[item].Date.ToUniversalTime().ToString("dd.MM.yyyy HH:mm UTC"); } _row_start = String.Format("\"{1}\"{0}{2}{0}{3}{0}{4}{0}\"{5}\"{0}\"{6}\"", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator, _ProgDate, mItem[item].TaskId, mItem[item].LfdNo, mItem[item].ErrorNo, protocol.GetErrorName(mItem[item].ErrorNo), protocol.IsEventOrError(mItem[item].ErrorNo) ? "Event" : "Fehler"); if (mItem[item].TaskId == 255) { // Verhalten aenderung _row_tail = String.Format("{0}\"aktiv\"{0}\"Intern\"{0}\"{1}\"", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator, mItem[item].Wert1); } else { // Fehler / Event aufgetreten if (mItem[item].ErrorNo > 63) { _row_tail = String.Format("{0}\"sporadisch\"{0}\"\"{0}\"{1}\"{0}\"\"{0}\"\"{0}\"{2}\"{0}\"\"{0}\"\"{0}\"{3}\"{0}\"\"", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator, mItem[item].Wert1, mItem[item].Wert2, mItem[item].Wert3); } else { _row_tail = String.Format("{0}\"sporadisch\"{0}\"{1}\"{0}\"{2}\"{0}\"{3}\"{0}\"{4}\"{0}\"{5}\"{0}\"{6}\"{0}\"{7}\"{0}\"{8}\"{0}\"{9}\"", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator, protocol.GetValueName(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 0))), protocol.GetValueString(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 0)), mItem[item].Wert1), protocol.GetValueUnit(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 0))), protocol.GetValueName(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 1))), protocol.GetValueString(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 1)), mItem[item].Wert2), protocol.GetValueUnit(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 1))), protocol.GetValueName(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 2))), protocol.GetValueString(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 2)), mItem[item].Wert3), protocol.GetValueUnit(protocol.GetValuePosition(protocol.ErrorRingFigure(mItem[item].ErrorNo, 2)))); } } writer.WriteLine(String.Format("{0}{1}", _row_start, _row_tail)); } writer.Close(); }
/// <summary>Set acquisition configuration according to connected ECU</summary> /// <param name="protocol">Reference to protocol to connected ECU</param> public void SetConfiguration(ref ProtocolBase protocol) { mNumberOfBlocks = protocol.AcquisitionSectors; // Save mask byte NumOfCols = 0; mSaveMin = new bool[10]; mSaveAvg = new bool[10]; mSaveMax = new bool[10]; UInt32 Mask = 1; for (int i = 0; i < 10; i++) { if ((protocol.AcquisitionSaveMask & Mask) == 0) { mSaveMin[i] = false; } else { mSaveMin[i] = true; NumOfCols++; } Mask = (UInt32)(Mask * 2); if ((protocol.AcquisitionSaveMask & Mask) == 0) { mSaveAvg[i] = false; } else { mSaveAvg[i] = true; NumOfCols++; } Mask = (UInt32)(Mask * 2); if ((protocol.AcquisitionSaveMask & Mask) == 0) { mSaveMax[i] = false; } else { mSaveMax[i] = true; NumOfCols++; } Mask = (UInt32)(Mask * 2); } mSourceValues = new byte[10]; for (byte i = 0; i < 10; i++) { mSourceValues[i] = protocol.AcquisitionSource(i); } // row mHead = new string[NumOfCols + 1]; mHead[0] = "DateTime"; mValuePosition = new byte[NumOfCols + 1]; mRowLength = 1; for (int i = 0; i < 10; i++) { byte ValuePosition = protocol.GetValuePosition(mSourceValues[i]); string ValueName = protocol.GetValueName(ValuePosition); string ValueUnit = protocol.GetValueUnit(ValuePosition); if (ValueName != null) { if (mSaveMin[i] == true) { mHead[mRowLength] = String.Format("{0}_MIN_in_{1}", ValueName, ValueUnit); mValuePosition[mRowLength - 1] = ValuePosition; // Replace prohibited xml characters mHead[mRowLength] = mHead[mRowLength].Replace(@" ", @"_"); mHead[mRowLength] = mHead[mRowLength].Replace(@"@", @"at"); mHead[mRowLength] = mHead[mRowLength].Replace(@"%", @"_Pozent"); mRowLength++; } if (mSaveAvg[i] == true) { mHead[mRowLength] = String.Format("{0}_AVG_in_{1}", ValueName, ValueUnit); mValuePosition[mRowLength - 1] = ValuePosition; // Replace prohibited xml characters mHead[mRowLength] = mHead[mRowLength].Replace(@" ", @"_"); mHead[mRowLength] = mHead[mRowLength].Replace(@"@", @"at"); mHead[mRowLength] = mHead[mRowLength].Replace(@"%", @"_Pozent"); mRowLength++; } if (mSaveMax[i] == true) { mHead[mRowLength] = String.Format("{0}_MAX_in_{1}", ValueName, ValueUnit); mValuePosition[mRowLength - 1] = ValuePosition; // Replace prohibited xml characters mHead[mRowLength] = mHead[mRowLength].Replace(@" ", @"_"); mHead[mRowLength] = mHead[mRowLength].Replace(@"@", @"at"); mHead[mRowLength] = mHead[mRowLength].Replace(@"%", @"_Pozent"); mRowLength++; } } } mItem = new AcquisitionItem[0]; // calculate row length from amount of values to amount of bytes // all values are 2-byte-values mRowLength = (UInt16)(mRowLength * 2); // except date has 3 bytes mRowLength++; }