コード例 #1
0
        private DigProvider CreateSingleDigitalObject(XmlNode node, HardwareType hw)
        {
            if (node == null)
            {
                return(null);
            }
            XmlNode item = node.SelectSingleNode(hw.ToString());

            if (item == null)
            {
                return(null);
            }
            if (hwLib.ContainsKey(hw) && hwLib[hw] is DigProvider)
            {
                return((DigProvider)hwLib[hw]);
            }
            try
            {
                XmlAttribute output  = item.Attributes["IsOutPut"];
                XmlAttribute mask    = item.Attributes["Mask"]; //获取名称
                XmlAttribute used    = item.Attributes["Used"];
                XmlAttribute status  = item.Attributes["Status"];
                DigProvider  adapter = new DigProvider();
                hwLib.Add(hw, adapter);
                uint index = 0;
                bool r     = false;
                if (bool.TryParse(output.Value, out r))
                {
                    adapter.IsOutput = r;
                }
                if (uint.TryParse(used.Value, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out index))
                {
                    adapter.Used = index;
                }
                if (uint.TryParse(status.Value, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out index))
                {
                    adapter.Status = index;
                }
                if (uint.TryParse(mask.Value, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out index))
                {
                    adapter.Mask = index;
                }
                return(adapter);
            }
            catch (Exception ex)
            {
                LogHelper.WriteDebugException(ex);
                return(null);
            }
        }
コード例 #2
0
        private XmlNode SaveSingleDigitalObject(HardwareType hwType, DigProvider item, XmlDocument document)
        {
            if (item == null)
            {
                return(null);
            }
            XmlNode      dig  = document.CreateElement(hwType.ToString());
            XmlAttribute attr = document.CreateAttribute("IsOutPut");

            attr.Value = item.IsOutput.ToString();
            dig.Attributes.Append(attr);
            attr       = document.CreateAttribute("Mask");
            attr.Value = item.Mask.ToString("X");
            dig.Attributes.Append(attr);
            attr       = document.CreateAttribute("Used");
            attr.Value = item.Used.ToString("X");
            dig.Attributes.Append(attr);
            attr       = document.CreateAttribute("Status");
            attr.Value = item.Status.ToString("X");
            dig.Attributes.Append(attr);
            return(dig);
        }