/// <summary> /// Define output section of equipmet type template (trends) /// </summary> /// <param name="fieldParam"></param> /// <returns></returns> public static templateOutput GetEquipmentType_TrnOutputs(EquipmentTypeOutputParam fieldParam) { templateOutput templateOutput = new templateOutput { name = "TRN." + fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }), file = "trend.dbf", filter = @"'{equipment.type}={type.name}'" }; var outputFields = new List <templateOutputField> { new templateOutputField { name = "name", key = true, Value = string.Format("{0}_{{equipment.tagprefix}}{1}_Trn", fieldParam.Prefix, fieldParam.Suffix), keySpecified = true }, new templateOutputField { name = "expr", Value = string.Format("{0}_{{equipment.tagprefix}}{1}", fieldParam.Prefix, fieldParam.Suffix) }, new templateOutputField { name = "sampleper", Value = "" }, new templateOutputField { name = "files", Value = "" }, new templateOutputField { name = "time", Value = "" }, new templateOutputField { name = "period", Value = "" }, new templateOutputField { name = "comment", Value = fieldParam.Comment + " trend" }, new templateOutputField { name = "type", Value = "TRN_PERIODIC" }, new templateOutputField { name = "stormethod", Value = "Floating Point (8-byte samples)" }, new templateOutputField { name = "cluster", key = true, Value = fieldParam.Cluster, keySpecified = true }, new templateOutputField { name = "equip", Value = fieldParam.Equipment }, new templateOutputField { name = "item", Value = CapsFirstLetter(fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }).ToLower()) }, new templateOutputField { name = "taggenlink", load = true, Value = fieldParam.TagGenLink, loadSpecified = true }, new templateOutputField { name = "linked", Value = "1" }, new templateOutputField { name = "editcode", Value = "9" }, }; templateOutput.field = outputFields.ToArray(); return(templateOutput); }
/// <summary> /// Define Output section of Equipment Type xml template (digital variables) /// </summary> /// <param name="prefix"></param> /// <param name="suffix"></param> /// <param name="outputType"></param> /// <param name="comment"></param> /// <returns></returns> public static templateOutput GetEquipmentType_VarDiscreteOutputs(EquipmentTypeOutputParam fieldParam) { templateOutput templateOutput = new templateOutput { name = "Var." + fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }), file = "variable.dbf", filter = @"'{equipment.type}={type.name}'" }; var tagaddressvalue = "{equipment.BaseAddr[" + fieldParam.BaseAddressParam.ToString() + "]} + " + fieldParam.AddressOffset.ToString(); var templateOutputCalculator = new templateOutputCalculator { name = "TagAddress", Value = tagaddressvalue }; var outputFields = new List <templateOutputField> { new templateOutputField { name = "name", key = true, Value = string.Format("{0}_{{equipment.tagprefix}}{1}", fieldParam.Prefix, fieldParam.Suffix), keySpecified = true }, new templateOutputField { name = "type", Value = fieldParam.DataType }, new templateOutputField { name = "unit", Value = fieldParam.DeviceIO }, new templateOutputField { name = "comment", Value = "{equipment.tagprefix} " + fieldParam.Comment }, new templateOutputField { name = "cluster", key = true, Value = fieldParam.Cluster, keySpecified = true }, new templateOutputField { name = "equip", Value = fieldParam.Equipment }, new templateOutputField { name = "addr", Value = "%M{TagAddress}" }, new templateOutputField { name = "item", Value = CapsFirstLetter(fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }).ToLower()) }, new templateOutputField { name = "taggenlink", load = true, Value = fieldParam.TagGenLink, loadSpecified = true }, new templateOutputField { name = "linked", Value = "1" }, new templateOutputField { name = "editcode", Value = editcode }, }; templateOutput.calculator = templateOutputCalculator; templateOutput.field = outputFields.ToArray(); return(templateOutput); }
/// <summary> /// Define Output section of Equipment Type xml template (digalm) /// </summary> /// <param name="equipmenttype"></param> /// <param name="suffix"></param> /// <returns></returns> public static templateOutput GetEquipmentType_DigAlmOutputs(EquipmentTypeOutputParam fieldParam) { templateOutput templateOutput = new templateOutput { name = "Alm." + fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }), file = "digalm.dbf", filter = @"'{equipment.type}={type.name}'" }; var outputFields = new List <templateOutputField> { new templateOutputField { name = "tag", key = true, Value = string.Format("{0}_{{equipment.tagprefix}}{1}_Alm", fieldParam.Prefix, fieldParam.Suffix), keySpecified = true }, new templateOutputField { name = "name", Value = fieldParam.Equipment }, new templateOutputField { name = "desc", Value = fieldParam.Comment }, new templateOutputField { name = "VAR_A", Value = string.Format("{0}_{{equipment.tagprefix}}{1}", fieldParam.Prefix, fieldParam.Suffix) }, new templateOutputField { name = "comment", Value = "" }, new templateOutputField { name = "cluster", key = true, Value = fieldParam.Cluster, keySpecified = true }, new templateOutputField { name = "category", Value = fieldParam.AlmCategory }, new templateOutputField { name = "equip", Value = fieldParam.Equipment }, new templateOutputField { name = "item", Value = CapsFirstLetter(fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }).ToLower()) }, new templateOutputField { name = "taggenlink", load = true, Value = fieldParam.TagGenLink, loadSpecified = true }, new templateOutputField { name = "linked", Value = "1" }, new templateOutputField { name = "editcode", Value = "9" }, }; templateOutput.field = outputFields.ToArray(); return(templateOutput); }
/// <summary> /// define output section of equipment type for Calculated Variables /// 1. ensure the cicode unit is first defined in i/o devices /// 2. ensure cicode function (FuncName) is defined in cicode /// </summary> /// <param name="fieldParam"></param> /// <returns></returns> public static templateOutput GetEquipmentType_CalculatedCommandVariable(EquipmentTypeOutputParam fieldParam) { templateOutput templateOutput = new templateOutput { name = string.Format("Var.{0}Cmd", fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' })), file = "variable.dbf", filter = @"'{equipment.type}={type.name}'" }; var funcArgs = string.Format("C_{{equipment.tagprefix}}_{0}", fieldParam.Suffix); var tagaddressvalue = string.Format("{0}({1})", fieldParam.FuncName, funcArgs); var outputFields = new List <templateOutputField> { new templateOutputField { name = "name", key = true, Value = string.Format("{{equipment.tagprefix}}{0}Cmd", fieldParam.Suffix), keySpecified = true }, new templateOutputField { name = "type", Value = fieldParam.DataType }, new templateOutputField { name = "unit", Value = fieldParam.DeviceIO }, new templateOutputField { name = "comment", Value = "{equipment.tagprefix} " + fieldParam.Comment }, new templateOutputField { name = "equip", Value = fieldParam.Equipment }, new templateOutputField { name = "addr", Value = tagaddressvalue }, new templateOutputField { name = "item", Value = fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }) + "Cmd" }, new templateOutputField { name = "taggenlink", load = true, Value = fieldParam.TagGenLink + "Cmd", loadSpecified = true }, new templateOutputField { name = "linked", Value = "1" }, new templateOutputField { name = "editcode", Value = editcode } }; templateOutput.field = outputFields.ToArray(); return(templateOutput); }
/// <summary> /// Define Output section of Equipment Type xml template (analog variables) /// </summary> /// <param name="prefix"></param> /// <param name="suffix"></param> /// <param name="outputType"></param> /// <param name="comment"></param> /// <returns></returns> public static templateOutput GetEquipmentType_VarAnalogOutputs(EquipmentTypeOutputParam fieldParam) { templateOutput templateOutput = new templateOutput { name = "Var." + fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }), file = "variable.dbf", filter = @"'{equipment.type}={type.name}'" }; if (fieldParam.DeviceIO.Contains("IODEVICE") && fieldParam.AddressOffset >= 0) { var tagaddressvalue = "{equipment.BaseAddr[" + fieldParam.BaseAddressParam.ToString() + "]} + " + fieldParam.AddressOffset.ToString(); var templateOutputCalculator = new templateOutputCalculator { name = "TagAddress", Value = tagaddressvalue }; var outputFields = new List <templateOutputField> { new templateOutputField { name = "name", key = true, Value = string.Format("{0}_{{equipment.tagprefix}}{1}", fieldParam.Prefix, fieldParam.Suffix), keySpecified = true }, new templateOutputField { name = "type", Value = fieldParam.DataType }, new templateOutputField { name = "unit", Value = fieldParam.DeviceIO }, new templateOutputField { name = "eng_zero", Value = fieldParam.EngZero }, new templateOutputField { name = "eng_full", Value = fieldParam.EngFull }, new templateOutputField { name = "comment", Value = "{equipment.tagprefix} " + fieldParam.Comment }, new templateOutputField { name = "cluster", key = true, Value = fieldParam.Cluster, keySpecified = true }, new templateOutputField { name = "equip", Value = fieldParam.Equipment }, new templateOutputField { name = "addr", Value = "%MW{TagAddress}" }, new templateOutputField { name = "raw_zero", Value = fieldParam.RawZero }, new templateOutputField { name = "raw_full", Value = fieldParam.RawFull }, new templateOutputField { name = "eng_units", Value = fieldParam.Units }, new templateOutputField { name = "format", Value = fieldParam.Format }, new templateOutputField { name = "item", Value = CapsFirstLetter(fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }).ToLower()) }, new templateOutputField { name = "taggenlink", load = true, Value = fieldParam.TagGenLink, loadSpecified = true }, new templateOutputField { name = "linked", Value = "1" }, new templateOutputField { name = "editcode", Value = editcode }, }; templateOutput.calculator = templateOutputCalculator; templateOutput.field = outputFields.ToArray(); } else //without address calculation { var outputFields = new List <templateOutputField> { new templateOutputField { name = "name", key = true, Value = string.Format("{0}_{{equipment.tagprefix}}{1}", fieldParam.Prefix, fieldParam.Suffix), keySpecified = true }, new templateOutputField { name = "type", Value = fieldParam.DataType }, new templateOutputField { name = "unit", Value = fieldParam.DeviceIO }, new templateOutputField { name = "comment", Value = "{equipment.tagprefix} " + fieldParam.Comment }, new templateOutputField { name = "cluster", key = true, Value = fieldParam.Cluster, keySpecified = true }, new templateOutputField { name = "equip", Value = fieldParam.Equipment }, new templateOutputField { name = "eng_units", Value = fieldParam.Units }, new templateOutputField { name = "format", Value = fieldParam.Format }, new templateOutputField { name = "item", Value = CapsFirstLetter(fieldParam.Suffix.TrimStart(new char[] { ',', '_', '.' }).ToLower()) }, new templateOutputField { name = "taggenlink", load = true, Value = fieldParam.TagGenLink, loadSpecified = true }, new templateOutputField { name = "linked", Value = "1" }, new templateOutputField { name = "editcode", Value = editcode }, }; templateOutput.field = outputFields.ToArray(); } return(templateOutput); }
/// <summary> /// /// </summary> public bool ConvertTagsInExcelToTemplate(DataSet ds) { foreach (DataTable dtTable in ds.Tables) { //DEBUG if (dtTable.TableName.Contains("Chlo")) { log.Debug("stop"); } var equipmentTypeTemplate = new template { desc = dtTable.TableName }; //name of worksheet - equipment type name equipmentTypeTemplate.param = TomPriceEquipmentTemplate.GetEquipmentType_Param(dtTable.TableName, ""); equipmentTypeTemplate.input = TomPriceEquipmentTemplate.GetEquipmentType_Input(); var templateOutputs = new List <templateOutput>(); //get baseaddress? var baseAddressList = new Dictionary <string, int>(); foreach (DataRow row in dtTable.AsEnumerable().Take(4)) { baseAddressList.Add(row["Tag Name"].ToString(), int.Parse(row["Address"].ToString())); } //put the information into class var outputparams = new List <EquipmentTypeOutputParam>(); string equipment = ""; foreach (DataRow row in dtTable.AsEnumerable().Skip(4)) { //inner exception if (row.IsNull("Tag Name")) { continue; } string tagName = row["Tag Name"].ToString().Replace('.', '_'); equipment = row.IsNull("Equipment") ? equipment : row["Equipment"].ToString(); var nameSplit = tagName.Split(new char[] { '_', '.' }); try { int.TryParse(Regex.Match(row["Address"].ToString(), @"\d+").Value, out int plcNumericAddress); var outputparam = new EquipmentTypeOutputParam { EquipName = dtTable.TableName.Replace(" ", string.Empty), Comment = row["Comment"].ToString(), DataType = row["Data Type"].ToString(), Suffix = tagName.Substring(tagName.IndexOf(equipment) + equipment.Length).TrimStart(new char[] { '_', '.', ',', '|' }), //suffix is anything after equipment name string Prefix = nameSplit[0], BaseAddrPairs = baseAddressList, BaseAddressParam = !row.IsNull("Tag Type") ? (BaseAddr)Enum.Parse(typeof(BaseAddr), row["Tag Type"].ToString()):BaseAddr.None, TagAddress = plcNumericAddress, AlmCategory = row.IsNull("Category") ? "" : row["Category"].ToString(), RawZero = row.IsNull("Raw Zero Scale") ? "0" : row["Raw Zero Scale"].ToString(), RawFull = row.IsNull("Raw Full Scale") ? "0" : row["Raw Full Scale"].ToString(), EngZero = row.IsNull("Eng Zero Scale") ? "0" : row["Eng Zero Scale"].ToString(), EngFull = row.IsNull("Eng Full Scale") ? "0" : row["Eng Full Scale"].ToString(), SetTrends = row.IsNull("Set Trend") ? false : bool.Parse(row["Set Trend"].ToString()), Units = row.IsNull("Eng Units") ? string.Empty : row["Eng Units"].ToString(), Format = row.IsNull("Format") ? string.Empty : row["Format"].ToString() }; if (!row.IsNull(@"I/O Device")) { if (row["I/O Device"].ToString().Equals("CICODESVR")) { outputparam.DeviceIO = row["I/O Device"].ToString(); outputparam.FuncName = row["Address"].ToString(); outputparam.IsCalCulated = true; } else { outputparam.DeviceIO = row["I/O Device"].ToString(); } } outputparams.Add(outputparam); } catch (Exception ex) { log.ErrorFormat("ConvertTagToTemplate:{0},{1}", tagName, ex); } } //find duplicates in list? var result = outputparams.GroupBy(x => x.Suffix.TrimStart(new char[] { '_', '.', ',' })).Select(y => new { suffix = y.Key, count = y.Count() }); foreach (var rec in result.Where(a => a.count > 1)) { log.WarnFormat("Please correct tag list: possible duplication of tags, suffux: {0} for {1}", rec.suffix, dtTable.TableName); } //get xml formatted string from outputparams outputparams.ForEach(s => templateOutputs.AddRange(s.GetXmlTemplateOutput())); if (templateOutputs.Count > 0) { equipmentTypeTemplate.output = templateOutputs.ToArray(); } //add to list EquipmentTypeTemplates.Add(equipmentTypeTemplate); } //serialise to XML EquipmentTypeTemplates.ForEach(s => SerializeEquipmentTypeTemplate(s, s.desc)); return(EquipmentTypeTemplates.Count > 0); }