public static void LoadBatStatConfig(string strFileName, string strSubNode1, string strSubNode2, string strSubNode3, ICollection <BitStatInfo> listSwitch, string strByteInfo) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strFileName); XmlElement root = xmlDoc.DocumentElement; XmlNode subNode1 = root.SelectNodes(strSubNode1)[0]; // "master_function_switch" string strRegister = subNode1.SelectSingleNode("address").InnerText; string strDesc = subNode1.SelectSingleNode("description").InnerText; string strRegCount = subNode1.SelectSingleNode("register_num").InnerText; foreach (XmlNode byNode in subNode1.SelectNodes(strSubNode2)) // "master_function_switch_node" { int nByteIndex = 0; string byteInfo = byNode.SelectSingleNode("byte_info").InnerText; if (byteInfo != strByteInfo) { continue; } string byteIndex = byNode.SelectSingleNode("byte_index").InnerText; if (!string.IsNullOrEmpty(byteIndex)) { nByteIndex = int.Parse(byteIndex); } string strInnerText = null; foreach (XmlNode btNode in byNode.SelectNodes(strSubNode3)) { BitStatInfo bitNodeInfo = new BitStatInfo(); bitNodeInfo.ByteIndex = nByteIndex; bitNodeInfo.BitInfo = btNode.SelectSingleNode("bit_info").InnerText; //strInnerText = node.SelectSingleNode("byte_index").InnerText; //if (!string.IsNullOrEmpty(strInnerText)) //{ // nodeInfo.ByteIndex = int.Parse(strInnerText); //} strInnerText = btNode.SelectSingleNode("bit_index").InnerText; if (!string.IsNullOrEmpty(strInnerText)) { bitNodeInfo.BitIndex = int.Parse(strInnerText); } listSwitch.Add(bitNodeInfo); } } //LogXmlHelp.Info("节点数 ... listAdjust: " + listMaster.Count); } catch (Exception ex) { //LogXmlHelp.Error("加载 " + strFileName + " 错误!\n" + ex.Message + ex.StackTrace); } //return nByteCount; }
public static void LoadDdBatStatConfig(string strFileName, string strSubNode, ICollection <BitStatInfo> listSwitch, string strByteInfo) { try { if (!File.Exists(strFileName)) { return; } string[] arrNodes = strSubNode.Split('/'); string strSubNode1 = arrNodes[0]; string strSubNode2 = arrNodes[1]; string strSubNode3 = arrNodes[2]; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strFileName); XmlElement root = xmlDoc.DocumentElement; XmlNode subNode1 = root.SelectNodes(strSubNode1)[0]; // "master_function_switch" string strRegister = subNode1.SelectSingleNode("address").InnerText; string strDesc = subNode1.SelectSingleNode("description").InnerText; string strRegCount = subNode1.SelectSingleNode("register_num").InnerText; foreach (XmlNode byNode in subNode1.SelectNodes(strSubNode2)) // "master_function_switch_node" { int nByteIndex = 0; string byteInfo = byNode.SelectSingleNode("byte_info").InnerText; if (byteInfo != strByteInfo) { continue; } string byteIndex = byNode.SelectSingleNode("byte_index").InnerText; if (!string.IsNullOrEmpty(byteIndex)) { nByteIndex = int.Parse(byteIndex); } string strInnerText = null; foreach (XmlNode btNode in byNode.SelectNodes(strSubNode3)) { BitStatInfo bitNodeInfo = new BitStatInfo(); bitNodeInfo.ByteIndex = nByteIndex; bitNodeInfo.BitInfo = btNode.SelectSingleNode("bit_info").InnerText; strInnerText = btNode.SelectSingleNode("bit_index").InnerText; if (!string.IsNullOrEmpty(strInnerText)) { bitNodeInfo.BitIndex = int.Parse(strInnerText); } strInnerText = btNode.SelectSingleNode("is_warning").InnerText; if (!string.IsNullOrEmpty(strInnerText)) { if ("true" == strInnerText) { bitNodeInfo.IsWarning = true; } else { bitNodeInfo.IsWarning = false; } } strInnerText = btNode.SelectSingleNode("is_protect").InnerText; if (!string.IsNullOrEmpty(strInnerText)) { if ("true" == strInnerText) { bitNodeInfo.IsProtect = true; } else { bitNodeInfo.IsProtect = false; } } listSwitch.Add(bitNodeInfo); } } } catch (Exception ex) { } }