コード例 #1
0
        /// <summary>
        /// 获取所有的报警变量
        /// </summary>
        /// <returns></returns>
        public static List <VarAlarm_Modbus> GetListVarAlarm()
        {
            if (!File.Exists(pathVarAlarm))
            {
                return(null);
            }

            List <VarAlarm_Modbus> listVarAlarm = new List <VarAlarm_Modbus>();

            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(pathVarAlarm);
            XmlNode noodroot = xdoc.SelectSingleNode("//Root");

            foreach (XmlNode nood in noodroot.ChildNodes)
            {
                if (nood.Name == "VariableAlarm")
                {
                    //封装报警变量对象
                    VarAlarm_Modbus objVar = new VarAlarm_Modbus();
                    objVar.VarName    = GetValueByAttribute(nood, "VarName");
                    objVar.Priority   = Convert.ToInt32(GetValueByAttribute(nood, "Priority"));
                    objVar.AlarmType  = GetValueByAttribute(nood, "AlarmType");
                    objVar.AlarmValue = float.Parse(GetValueByAttribute(nood, "AlarmValue"));
                    objVar.Note       = GetValueByAttribute(nood, "Note");
                    //将对象存入集合
                    listVarAlarm.Add(objVar);
                }
            }

            return(listVarAlarm);
        }
コード例 #2
0
 /// <summary>
 /// 装载XML文件:根据路径返回LIST集合
 /// </summary>
 /// <param name="xmlpath"></param>
 /// <returns></returns>
 public static List <VarAlarm_Modbus> LoadAlarmXML(string xmlpath)
 {
     VarAlarmModbusList.Clear();
     if (!File.Exists(xmlpath))
     {
         MessageBox.Show("IO配置变量的XML文件不存在!");
     }
     else
     {
         XmlDocument xdoc = new XmlDocument();
         xdoc.Load(xmlpath);
         foreach (XmlNode noodroot in xdoc.ChildNodes)
         {
             if (noodroot.Name == "Root")
             {
                 foreach (XmlNode noodtool in noodroot.ChildNodes)
                 {
                     if (noodtool.Name == "VariableAlarm")
                     {
                         VarAlarm_Modbus objVar = new VarAlarm_Modbus();
                         objVar.VarName    = XMLAttributeGetValue(noodtool, "VarName");
                         objVar.Priority   = Convert.ToInt32(XMLAttributeGetValue(noodtool, "Priority"));
                         objVar.AlarmType  = XMLAttributeGetValue(noodtool, "AlarmType");
                         objVar.AlarmValue = float.Parse(XMLAttributeGetValue(noodtool, "AlarmValue"));
                         objVar.Note       = XMLAttributeGetValue(noodtool, "Note");
                         VarAlarmModbusList.Add(objVar);
                     }
                 }
             }
         }
     }
     return(VarAlarmModbusList);
 }