public static string buildFile(AlarmDefinitionList defs, string data_block, string connection) { XmlWriterSettings settings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Document, Encoding = Encoding.UTF8, Indent = true }; string filename; using (Stream stream = TempFile.Open("AlarmConst", "xml", out filename)) { XmlWriter w = XmlWriter.Create(stream, settings); HMITagTable table = new HMITagTable("Alarms"); foreach (AlarmDefinition a in defs) { HMITag t = new HMITag(a.Name, "String", "WString", data_block + ".Props[" + a.ID + "].Text", connection); table.Add(t); } table.write(w); } return(filename); }
public static string buildFile(string table_name, IEnumerable <Constant> constants) { XmlWriterSettings settings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Document, Encoding = Encoding.UTF8, Indent = true }; string filename; using (Stream stream = TempFile.Open("AlarmConst", "xml", out filename)) { int id = 0; XmlWriter w = XmlWriter.Create(stream, settings); w.WriteStartDocument(); w.WriteStartElement("Document"); w.WriteStartElement("DocumentInfo"); w.WriteEndElement(); // DocumentInfo w.WriteStartElement("SW.ControllerTagTable"); w.WriteAttributeString("ID", (id++).ToString()); w.WriteStartElement("AttributeList"); XMLUtil.SimpleValue(w, "Name", table_name); w.WriteEndElement(); // AttributeList w.WriteStartElement("ObjectList"); foreach (Constant c in constants) { w.WriteStartElement("SW.ControllerConstant"); w.WriteAttributeString("ID", (id++).ToString()); w.WriteAttributeString("AggregationName", "Constants"); w.WriteStartElement("AttributeList"); XMLUtil.SimpleValue(w, "Name", c.Name); XMLUtil.SimpleValue(w, "Value", c.Value.ToString()); w.WriteEndElement(); // AttributeList w.WriteStartElement("LinkList"); w.WriteStartElement("DataType"); w.WriteAttributeString("TargetID", "@OpenLink"); XMLUtil.SimpleValue(w, "Name", "Int"); w.WriteEndElement(); // DataType w.WriteEndElement(); // LinkList w.WriteStartElement("ObjectList"); w.WriteStartElement("MultilingualText"); w.WriteAttributeString("ID", (id++).ToString()); w.WriteAttributeString("AggregationName", "Comment"); w.WriteStartElement("AttributeList"); w.WriteStartElement("TextItems"); w.WriteStartElement("Value"); w.WriteAttributeString("lang", "sv-SE"); w.WriteString(c.Comment); w.WriteEndElement(); // Value w.WriteEndElement(); // TextItems w.WriteEndElement(); // AttributeList w.WriteEndElement(); // MultilingualText w.WriteEndElement(); // ObjectList w.WriteEndElement(); // SW.ControllerConstant } w.WriteEndElement(); // ObjectList w.WriteEndElement(); // SW.ControllerTagTable w.WriteEndElement(); // Document w.Close(); } return(filename); }
static public string buildFile(AlarmDefinitionList alarms) { XmlWriterSettings settings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Document, Encoding = Encoding.UTF8, Indent = true }; string filename; using (Stream stream = TempFile.Open("sDB_Larm", "xml", out filename)) { // Round up to multiples of 16, since HMI uses words to transfer alarm state int maxAlarmCount = ((alarms.Count() + 15) / 16) * 16; XmlWriter w = XmlWriter.Create(stream, settings); w.WriteStartDocument(); w.WriteStartElement("Document"); w.WriteStartElement("DocumentInfo"); w.WriteEndElement(); // DocumentInfo w.WriteStartElement("SW.DataBlock"); w.WriteAttributeString("ID", "0"); w.WriteStartElement("AttributeList"); XMLUtil.SimpleValue(w, "AutoNumber", "true"); XMLUtil.SimpleValue(w, "DatablockType", "SharedDB"); XMLUtil.SimpleValue(w, "HeaderVersion", "0.1"); w.WriteStartElement("Interface"); w.WriteStartElement("Sections", "http://www.siemens.com/automation/Openness/SW/Interface/v1"); w.WriteStartElement("Section"); w.WriteAttributeString("Name", "Static"); w.WriteStartElement("Member"); w.WriteAttributeString("Name", "Props"); w.WriteAttributeString("Remanence", "Classic"); w.WriteAttributeString("Datatype", "Array[1.." + maxAlarmCount + "] of \"AlarmProperties\""); w.WriteStartElement("AttributeList"); XMLUtil.BooleanAttribute(w, "HmiAccessible", true, XMLUtil.SystemDefined); XMLUtil.BooleanAttribute(w, "HmiVisible", true, XMLUtil.SystemDefined); w.WriteEndElement(); // AttributeList w.WriteStartElement("Sections"); w.WriteStartElement("Section"); w.WriteAttributeString("Name", "None"); // Silent member w.WriteStartElement("Member"); w.WriteAttributeString("Name", "Silent"); w.WriteAttributeString("Datatype", "Bool"); w.WriteStartElement("AttributeList"); w.WriteEndElement(); // AttributeList int index = 1; foreach (AlarmDefinition a in alarms) { StartValue(w, index.ToString(), (a.Options & AlarmDefinition.Option.Silent) != 0 ? "true" : "false"); index++; } w.WriteEndElement(); // Member // AutoAck member w.WriteStartElement("Member"); w.WriteAttributeString("Name", "AutoAck"); w.WriteAttributeString("Datatype", "Bool"); w.WriteStartElement("AttributeList"); w.WriteEndElement(); // AttributeList index = 1; foreach (AlarmDefinition a in alarms) { StartValue(w, index.ToString(), (a.Options & AlarmDefinition.Option.AutoAck) != 0 ? "true" : "false"); index++; } w.WriteEndElement(); // Member // Text member w.WriteStartElement("Member"); w.WriteAttributeString("Name", "Text"); w.WriteAttributeString("Datatype", "String[64]"); w.WriteStartElement("AttributeList"); w.WriteEndElement(); // AttributeList index = 1; foreach (AlarmDefinition a in alarms) { StartValue(w, index.ToString(), "'" + a.Text + "'"); index++; } w.WriteEndElement(); // Member w.WriteEndElement(); // Section w.WriteEndElement(); // Sections w.WriteEndElement(); // Member w.WriteEndElement(); // Section w.WriteEndElement(); // Sections w.WriteEndElement(); // Interface string now = DateTime.UtcNow.ToString("o"); XMLUtil.SimpleValue(w, "InterfaceModifiedDate", now, true); XMLUtil.SimpleValue(w, "IsKnowHowProtected", now, true); XMLUtil.SimpleValue(w, "IsOnlyStoredInLoadMemory", "false"); XMLUtil.SimpleValue(w, "IsPLCDB", "false", true); XMLUtil.SimpleValue(w, "IsWriteProtectedInAS", "false"); XMLUtil.SimpleValue(w, "MemoryLayout", "Standard"); XMLUtil.SimpleValue(w, "ModifiedDate", now, true); XMLUtil.SimpleValue(w, "Name", "sDB_LarmDefs"); XMLUtil.SimpleValue(w, "Number", "532"); XMLUtil.SimpleValue(w, "ParameterModified", now, true); XMLUtil.SimpleValue(w, "ProgrammingLanguage", "DB"); XMLUtil.SimpleValue(w, "StructureModified", now, true); XMLUtil.SimpleValue(w, "Type", "DB"); w.WriteEndElement(); // AttributeList w.WriteEndElement(); // SW.Datablock w.WriteEndElement(); // Document w.Close(); } return(filename); }