Ejemplo n.º 1
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     node = xml.CreateElement("Device");

            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T133LeafID", T133LeafID.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T216LeafID", T216LeafID.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T107LeafID", T107LeafID.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "PLCType", PLCType.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBType", DBType.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBNumber", DBNumber.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "CycleReadMode", CycleReadMode.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "SplitterTime", SplitterTime.ToString()));

            node.AppendChild(xml.ImportNode(BelongPLC.GenerateXmlNode(), true));
            foreach (GroupEntity group in Groups)
            {
                node.AppendChild(xml.ImportNode(group.GenerateXmlNode(), true));
            }

            return(node);
        }
Ejemplo n.º 2
0
        public void ExportToXml(string filePath)
        {
            XmlDocument xml = new XmlDocument();

            xml.AppendChild(xml.CreateXmlDeclaration("1.0", "utf-8", "no"));

            XmlNode root = xml.CreateElement("root");

            xml.AppendChild(root);

            XmlNode plcNode = null;

            if (PLCType == PLCType.SIEMENS)
            {
                plcNode = xml.CreateElement("SiemensPLC");
                plcNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "IPAddress", BelongPLC.IPAddress));
                plcNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Rack", BelongPLC.Rack));
                plcNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Slot", BelongPLC.Slot));
            }
            root.AppendChild(plcNode);

            XmlNode deviceNode = xml.CreateElement("Device");

            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "T133LeafID", T133LeafID));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "T216LeafID", T216LeafID));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "T107LeafID", T107LeafID));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBType", DBType.ToString()));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBNumber", DBNumber));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "CycleReadMode", CycleReadMode.ToString()));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "SplitterTime", SplitterTime));

            foreach (GroupEntity group in Groups)
            {
                XmlNode groupNode = xml.CreateElement("TagGroup");
                groupNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", group.Name));

                foreach (TagEntity tag in group.Tags)
                {
                    XmlNode tagNode = xml.CreateElement("Tag");
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", tag.Name));
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Datatype", tag.DataType.ToString()));
                    if (tag.DataType == TagDataType.ArrayChar)
                    {
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Length", tag.Length));
                    }
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Offset", tag.Offset));
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Type", tag.Type.ToString()));
                    groupNode.AppendChild(tagNode);
                }

                foreach (SubGroupEntity sgroup in group.SubGroups)
                {
                    XmlNode sgroupNode = xml.CreateElement("SubTagGroup");
                    sgroupNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Prefix", sgroup.Prefix));

                    foreach (TagEntity tag in sgroup.Tags)
                    {
                        XmlNode tagNode = xml.CreateElement("Tag");
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", tag.Name));
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Datatype", tag.DataType.ToString()));
                        if (tag.DataType == TagDataType.ArrayChar)
                        {
                            tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Length", tag.Length));
                        }
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Offset", tag.Offset));
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Type", tag.Type.ToString()));
                        sgroupNode.AppendChild(tagNode);
                    }

                    groupNode.AppendChild(sgroupNode);
                }

                deviceNode.AppendChild(groupNode);
            }

            plcNode.AppendChild(deviceNode);

            xml.Save(filePath);
        }