public static GroupEntity ImportFromXmlNode( DeviceEntity parent, XmlNode node) { GroupEntity rlt = null; if (node.Name.ToUpper() != "TAGGROUP") { return(rlt); } rlt = new GroupEntity(parent) { Name = XMLHelper.GetAttributeStringValue(node, "Name", "Unknown"), }; XmlNode child = node.FirstChild; while (child != null) { switch (child.Name.ToUpper()) { case "TAG": TagEntity tag = TagEntity.ImportFromXmlNode(rlt, child); if (tag != null) { rlt.Tags.Add(tag); } break; case "SUBTAGGROUP": SubGroupEntity sgroup = SubGroupEntity.ImportFromXmlNode(rlt, child); if (sgroup != null) { rlt.SubGroups.Add(sgroup); } break; } child = child.NextSibling; } return(rlt); }
public SubGroupEntity(XmlNode node, GroupEntity parent) : this(parent) { #region 从Xml节点属性中获取属性值 if (node.Attributes["Prefix"] != null) { prefix = node.Attributes["Prefix"].Value; } #endregion XmlNode childNode = node.FirstChild; while (childNode != null) { if (childNode.Name == "Tag") { TagEntity tag = new TagEntity(childNode, this); Tags.Add(tag); } childNode = childNode.NextSibling; } }
public static TagEntity ImportFromXmlNode(GroupEntity parent, XmlNode node) { if (node.Name.ToUpper() != "TAG") { return(null); } try { TagEntity rlt = new TagEntity(parent) { Name = XMLHelper.GetAttributeStringValue(node, "Name", "Unknown"), Offset = XMLHelper.GetAttributeStringValue(node, "Offset", "0"), }; Enum.TryParse( XMLHelper.GetAttributeStringValue(node, "Datatype", "Bool"), true, out TagDataType dataType); rlt.DataType = dataType; if (rlt.DataType == TagDataType.ArrayChar) { rlt.Length = XMLHelper.GetAttributeStringValue(node, "Length", "0.1"); } Enum.TryParse( XMLHelper.GetAttributeStringValue(node, "Type", "A"), true, out TagType type); rlt.Type = type; return(rlt); } catch { return(null); } }
public void Remove(GroupEntity group) { group.RemoveChildren(); groups.Remove(group.ID); DataHelper.Instance.AllEntities.Remove(group.ID); }
public DeviceEntity( XmlNode node, ProductionLineEntity parent, AddToWholeEntityQueueHandler addToWholeEntityQueueHandler) : this(parent) { this.addToWholeEntityQueueHandler = addToWholeEntityQueueHandler; #region 从Xml节点属性中获取属性值 if (node.Attributes["Name"] != null) { Name = node.Attributes["Name"].Value; } if (node.Attributes["T133LeafID"] != null) { if (int.TryParse(node.Attributes["T133LeafID"].Value, out int rlt)) { T133LeafID = rlt; } } if (node.Attributes["T216LeafID"] != null) { if (int.TryParse(node.Attributes["T216LeafID"].Value, out int rlt)) { T216LeafID = rlt; } } if (node.Attributes["T107LeafID"] != null) { if (int.TryParse(node.Attributes["T107LeafID"].Value, out int rlt)) { T107LeafID = rlt; } } if (node.Attributes["DBType"] != null) { try { DBType = (SiemensRegisterType)Enum.Parse( typeof(SiemensRegisterType), node.Attributes["DBType"].Value); } catch { string enumValues = ""; foreach (var value in Enum.GetValues(typeof(SiemensRegisterType))) { enumValues += $"[{value}]"; } throw new Exception( $"{node.Name}.{Name}节点中[DBType]属性值错误,只支持[{enumValues}]"); } } if (node.Attributes["DBNumber"] != null) { if (int.TryParse(node.Attributes["DBNumber"].Value, out int rlt)) { DBNumber = rlt; } } if (node.Attributes["CycleReadMode"] != null) { try { CycleReadMode = (CycleReadMode)Enum.Parse( typeof(CycleReadMode), node.Attributes["CycleReadMode"].Value); } catch { string enumValues = ""; foreach (var value in Enum.GetValues(typeof(CycleReadMode))) { enumValues += $"[{value}]"; } throw new Exception( $"{node.Name}.{Name}节点中[CycleReadMode]属性值错误,只支持[{enumValues}]"); } } if (node.Attributes["PLCType"] != null) { try { PLCType = (PLCType)Enum.Parse( typeof(PLCType), node.Attributes["PLCType"].Value); } catch { string enumValues = ""; foreach (var value in Enum.GetValues(typeof(PLCType))) { enumValues += $"[{value}]"; } throw new Exception( $"{node.Name}.{Name}节点中[PLCType]属性值错误,只支持[{enumValues}]"); } } if (node.Attributes["SplitterTime"] != null) { if (int.TryParse(node.Attributes["SplitterTime"].Value, out int rlt)) { SplitterTime = rlt; } } #endregion XmlNode childNode = node.FirstChild; while (childNode != null) { if (childNode.Name == "PLC") { BelongPLC.LoadFromXmlNode(childNode); } else if (childNode.Name == "TagGroup") { try { GroupEntity group = new GroupEntity(childNode, this); if (group != null) { Groups.Add(group); } } catch (Exception error) { XtraMessageBox.Show( error.Message, "出错啦", MessageBoxButtons.OK); } } childNode = childNode.NextSibling; } }