/// <summary> /// Export error stack to a XML file /// </summary> /// <param name="Filename">Target file name</param> public void XmlExport(string Filename) { 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 = true; try { xf = XmlWriter.Create(Filename, settings); xf.WriteStartElement("error_root"); xf.WriteStartElement("ECU"); xf.WriteStartElement("Serialnumber"); xf.WriteValue(mProtocol.SerialNumber); xf.WriteEndElement(); // S/N xf.WriteStartElement("Hardware"); xf.WriteValue(string.Format("{0}.{1}.{2}", mProtocol.HardwareVersion.Hauptversion, mProtocol.HardwareVersion.Nebenversion, mProtocol.HardwareVersion.Revision)); xf.WriteEndElement(); // HW V xf.WriteStartElement("Software"); xf.WriteValue(string.Format("{0}.{1}.{2}", mProtocol.SoftwareVersion.Hauptversion, mProtocol.SoftwareVersion.Nebenversion, mProtocol.SoftwareVersion.Revision)); xf.WriteEndElement(); // SW V xf.WriteStartElement("Configuration"); xf.WriteValue(string.Format("{0}.{1}.{2}", mProtocol.ConfigurationVersion.Hauptversion, mProtocol.ConfigurationVersion.Nebenversion, mProtocol.ConfigurationVersion.Revision)); xf.WriteEndElement(); // CFG V xf.WriteStartElement("Datamap"); xf.WriteValue(string.Format("{0}.{1}.{2}", mProtocol.DatamapVersion.Hauptversion, mProtocol.DatamapVersion.Nebenversion, mProtocol.DatamapVersion.Revision)); xf.WriteEndElement(); // KF V xf.WriteEndElement(); // ECU for (byte item = 0; item < 64; item++) { if (IsErrorOccured(item)) { xf.WriteStartElement("error"); xf.WriteAttributeString("number", String.Format("{0}", item)); xf.WriteStartElement("name"); xf.WriteValue(mProtocol.GetErrorName(item)); xf.WriteEndElement(); xf.WriteStartElement("type"); xf.WriteValue(mProtocol.IsEventOrError(item) ? "Event" : "Fehler"); xf.WriteEndElement(); xf.WriteStartElement("state"); xf.WriteValue(GetErrorState(item)); xf.WriteEndElement(); xf.WriteStartElement("first_appear"); xf.WriteValue(GetFirstAppear(item)); xf.WriteEndElement(); xf.WriteStartElement("last_appear"); xf.WriteValue(GetLastAppear(item)); xf.WriteEndElement(); xf.WriteStartElement("appeared_until"); xf.WriteValue(GetAppearedUntil(item)); xf.WriteEndElement(); xf.WriteStartElement("occurances"); xf.WriteValue(GetNumberOfAppearances(item)); xf.WriteEndElement(); xf.WriteEndElement(); // error } } for (byte item = 0; item < 16; item++) { if (IsErrorOccured(item)) { xf.WriteStartElement("behave"); xf.WriteAttributeString("number", String.Format("{0}", item)); xf.WriteStartElement("name"); xf.WriteValue(mProtocol.GetBehaveName(item)); xf.WriteEndElement(); xf.WriteStartElement("state"); xf.WriteValue(GetBehaveState(item)); xf.WriteEndElement(); xf.WriteEndElement(); // behave } } xf.WriteEndElement(); // root xf.Flush(); } catch (Exception ex) { Console.WriteLine("Exception during opening XML file: {0}", ex.Message); } finally { xf.Close(); } }