public override TiaAndSTep7DataBlockRow DeepCopy()
        {
            var newRow = new TIADataRow(this.Name, this.DataType, this.PlcBlock);
            newRow.Parent = this.Parent;
            newRow.ArrayStart = this.ArrayStart;
            newRow.ArrayStop = this.ArrayStop;
            newRow.IsArray = this.IsArray;
            newRow.WasFirstInArray = this.WasFirstInArray;
            newRow.WasArray = this.WasArray;
            newRow.WasNextHigherIndex = this.WasNextHigherIndex;
            newRow.DataTypeBlock = DataTypeBlock;
            
            newRow.Comment = this.Comment;
            newRow.DataTypeBlockNumber = this.DataTypeBlockNumber;
            newRow.ReadOnly = this.ReadOnly;
            newRow.StartValue = this.StartValue;
            newRow.StringSize = this.StringSize;
            newRow.isInOut = this.isInOut;
            newRow.isRootBlock = this.isRootBlock;
            newRow.Value = this.Value;

            //newRow.Attributes = this.Attributes;
            //newRow.TimeStampConflict = this.TimeStampConflict;
            

            if (Children != null)
                foreach (TIADataRow plcDataRow in Children)
                {
                    var copy = plcDataRow.DeepCopy();
                    copy.Parent = newRow;
                    newRow.Add(copy);
                }

            return newRow;
        }      
        public TIADataRow(XmlNode Node, Step7ProjectV11 Project, TIABlock Block)
        {
            this.node       = Node;
            this.tiaProject = Project;
            this.block      = Block;

            var    id     = this.node.Attributes["id"].Value;
            string instId = this.node.Attributes["instId"].Value;

            var arrayLowerBounds = this.node.SelectSingleNode("attribSet[@id='" + tiaProject.asId2Names.First(itm => itm.Value == "Siemens.Automation.DomainServices.CommonTypeSystem.IStructureItem").Key + "']/attrib[@name='LowerBounds']/array");

            if (arrayLowerBounds != null && (arrayLowerBounds.Attributes["nil"] == null || arrayLowerBounds.Attributes["nil"].Value != "1"))
            {
                ArrayStart = new List <int>();
                ArrayStop  = new List <int>();
                var arrayUpperBounds = node.SelectSingleNode("attribSet[@id='" + tiaProject.asId2Names.First(itm => itm.Value == "Siemens.Automation.DomainServices.CommonTypeSystem.IStructureItem").Key + "']/attrib[@name='UpperBounds']/array");
                this.IsArray = true;
                foreach (var low in arrayLowerBounds.InnerText.Split(','))
                {
                    ArrayStart.Add(int.Parse(low));
                }
                foreach (var high in arrayUpperBounds.InnerText.Split(','))
                {
                    ArrayStop.Add(int.Parse(high));
                }

                this.node = Project.xmlDoc.SelectSingleNode("root/objects/StorageObject[parentlink[@link='" + id + "-" + instId + "']]");
                id        = this.node.Attributes["id"].Value;
                instId    = this.node.Attributes["instId"].Value;
            }

            var idChildRow = Project.importTypeInfos.First(itm => itm.Value == "Siemens.Simatic.PlcLanguages.Model.StructureItemData").Key;



            var subNodes = Project.xmlDoc.SelectNodes("root/objects/StorageObject[parentlink[@link='" + id + "-" + instId + "']]");

            this.Children = new List <IDataRow>();
            foreach (XmlNode subNode in subNodes)
            {
                if (subNode.Attributes["id"].Value == idChildRow)
                {
                    var row = new TIADataRow(subNode, Project, Block);
                    row.Parent = this;
                    this.Children.Add(row);
                }
            }
        }
        public TIADataRow(XmlNode Node, Step7ProjectV11 Project, TIABlock Block)
        {
            this.node = Node;
            this.tiaProject = Project;
            this.block = Block;

            var id = this.node.Attributes["id"].Value;
            string instId = this.node.Attributes["instId"].Value;

            var arrayLowerBounds = this.node.SelectSingleNode("attribSet[@id='" + tiaProject.asId2Names.First(itm => itm.Value == "Siemens.Automation.DomainServices.CommonTypeSystem.IStructureItem").Key + "']/attrib[@name='LowerBounds']/array");
            if (arrayLowerBounds != null && (arrayLowerBounds.Attributes["nil"] == null || arrayLowerBounds.Attributes["nil"].Value != "1"))
            {
                ArrayStart = new List<int>();
                ArrayStop = new List<int>();
                var arrayUpperBounds = node.SelectSingleNode("attribSet[@id='" + tiaProject.asId2Names.First(itm => itm.Value == "Siemens.Automation.DomainServices.CommonTypeSystem.IStructureItem").Key + "']/attrib[@name='UpperBounds']/array");
                this.IsArray = true;
                foreach (var low in arrayLowerBounds.InnerText.Split(','))
                {
                    ArrayStart.Add(int.Parse(low));
                }
                foreach (var high in arrayUpperBounds.InnerText.Split(','))
                {
                    ArrayStop.Add(int.Parse(high));
                }

                this.node = Project.xmlDoc.SelectSingleNode("root/objects/StorageObject[parentlink[@link='" + id + "-" + instId + "']]");
                id = this.node.Attributes["id"].Value;
                instId = this.node.Attributes["instId"].Value;
            }

            var idChildRow = Project.importTypeInfos.First(itm => itm.Value == "Siemens.Simatic.PlcLanguages.Model.StructureItemData").Key;

            var subNodes = Project.xmlDoc.SelectNodes("root/objects/StorageObject[parentlink[@link='" + id + "-" + instId + "']]");
            this.Children = new List<IDataRow>();
            foreach (XmlNode subNode in subNodes)
            {
                if (subNode.Attributes["id"].Value == idChildRow)
                {
                    var row = new TIADataRow(subNode, Project, Block);
                    row.Parent = this;
                    this.Children.Add(row);
                }
            }
        }
예제 #4
0
        public override TiaAndSTep7DataBlockRow DeepCopy()
        {
            var newRow = new TIADataRow(this.Name, this.DataType, this.PlcBlock);

            newRow.Parent             = this.Parent;
            newRow.ArrayStart         = this.ArrayStart;
            newRow.ArrayStop          = this.ArrayStop;
            newRow.IsArray            = this.IsArray;
            newRow.WasFirstInArray    = this.WasFirstInArray;
            newRow.WasArray           = this.WasArray;
            newRow.WasNextHigherIndex = this.WasNextHigherIndex;
            newRow.DataTypeBlock      = DataTypeBlock;

            newRow.Comment             = this.Comment;
            newRow.DataTypeBlockNumber = this.DataTypeBlockNumber;
            newRow.ReadOnly            = this.ReadOnly;
            newRow.StartValue          = this.StartValue;
            newRow.StringSize          = this.StringSize;
            newRow.isInOut             = this.isInOut;
            newRow.isRootBlock         = this.isRootBlock;
            newRow.Value = this.Value;

            //newRow.Attributes = this.Attributes;
            //newRow.TimeStampConflict = this.TimeStampConflict;


            if (Children != null)
            {
                foreach (TIADataRow plcDataRow in Children)
                {
                    var copy = plcDataRow.DeepCopy();
                    copy.Parent = newRow;
                    newRow.Add(copy);
                }
            }

            return(newRow);
        }
        internal static void parseChildren(TIADataRow parentRow, XElement parentElement, TIAOpennessControllerFolder controllerFolder)
        {
            foreach (var xElement in parentElement.Elements())
            {
                if (xElement.Name.LocalName == "Comment")
                {
                    var text = xElement.Elements().FirstOrDefault(x => x.Attribute("Lang").Value == "de-DE");
                    if (text == null)
                        text = xElement.Elements().FirstOrDefault();
                    if (text != null)
                        parentRow.Comment = text.Value;
                }
                else if (xElement.Name.LocalName == "StartValue")
                {
                    parentRow.StartValue = xElement.Value;
                }
                else if (xElement.Name.LocalName == "Sections")
                {
                    var row = ParseTiaDbUdtSections(xElement, (TIADataBlock) parentRow.CurrentBlock, controllerFolder);
                    parentRow.AddRange(row.Children);
                }
                else if (xElement.Name.LocalName == "Member")
                {
                    var name = xElement.Attribute("Name").Value;
                    var datatype = xElement.Attribute("Datatype").Value;

                    var row = new TIADataRow(name, S7DataRowType.STRUCT, (TIABlock) parentRow.PlcBlock);
                    row.Parent = parentRow;

                    if (datatype.Contains("Array["))
                    {
                        List<int> arrayStart = new List<int>();
                        List<int> arrayStop = new List<int>();

                        int pos1 = datatype.IndexOf("[");
                        int pos2 = datatype.IndexOf("]", pos1);
                        string[] arrays = datatype.Substring(pos1 + 1, pos2 - pos1 - 1).Split(',');

                        foreach (string array in arrays)
                        {
                            string[] akar = array.Split(new string[] {".."}, StringSplitOptions.RemoveEmptyEntries);
                            arrayStart.Add(Convert.ToInt32(akar[0].Trim()));
                            arrayStop.Add(Convert.ToInt32(akar[1].Trim()));
                        }

                        row.ArrayStart = arrayStart;
                        row.ArrayStop = arrayStop;
                        row.IsArray = true;
                        datatype = datatype.Substring(pos2 + 5);
                    }

                    parentRow.Add(row);

                    parseChildren(row, xElement, controllerFolder);

                    if (datatype.StartsWith("\""))
                    {
                        var udt =
                            controllerFolder.PlcDatatypeFolder.GetBlock(datatype.Substring(1, datatype.Length - 2));
                        if (udt != null)
                        {
                            var tiaUdt = udt as TIADataBlock;
                            row.AddRange(((TIADataRow) tiaUdt.Structure).DeepCopy().Children);

                            row.DataTypeBlock = udt;
                        }
                        row.DataType = S7DataRowType.UDT;
                    }
                    else if (datatype == "Struct")
                    {

                    }
                    else if (datatype.StartsWith("String["))
                    {
                        row.DataType = S7DataRowType.STRING;
                        row.StringSize = int.Parse(datatype.Substring(7, datatype.Length - 8));
                    }
                    else
                    {
                        switch (datatype.ToLower())
                        {
                            case "byte":
                                row.DataType = S7DataRowType.BYTE;
                                break;
                            case "bool":
                                row.DataType = S7DataRowType.BOOL;
                                break;
                            case "int":
                                row.DataType = S7DataRowType.INT;
                                break;
                            case "uint":
                                row.DataType = S7DataRowType.DWORD;
                                break;
                            case "dint":
                                row.DataType = S7DataRowType.DINT;
                                break;
                            case "word":
                                row.DataType = S7DataRowType.WORD;
                                break;
                            case "dword":
                                row.DataType = S7DataRowType.DWORD;
                                break;
                            case "char":
                                row.DataType = S7DataRowType.CHAR;
                                break;
                            case "any":
                                row.DataType = S7DataRowType.ANY;
                                break;
                            case "date":
                                row.DataType = S7DataRowType.DATE;
                                break;
                            case "date_and_time":
                                row.DataType = S7DataRowType.DATE_AND_TIME;
                                break;
                            case "real":
                                row.DataType = S7DataRowType.REAL;
                                break;
                            case "s5time":
                                row.DataType = S7DataRowType.S5TIME;
                                break;
                            case "time_of_day":
                                row.DataType = S7DataRowType.TIME_OF_DAY;
                                break;
                            case "time":
                                row.DataType = S7DataRowType.TIME;
                                break;
                            default:
                                row.DataType = S7DataRowType.UNKNOWN;
                                Console.WriteLine("unkown Datatype: " + datatype);
                                break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("unkown XML Element");
                }
            }
        }
        internal static TIADataRow ParseTiaDbUdtSections(XElement sections, TIADataBlock block, TIAOpennessControllerFolder controllerFolder)
        {
            var parameterRoot = new TIADataRow("ROOTNODE", S7DataRowType.STRUCT, block);
            var parameterIN = new TIADataRow("IN", S7DataRowType.STRUCT, block);
            parameterIN.Parent = parameterRoot;
            var parameterOUT = new TIADataRow("OUT", S7DataRowType.STRUCT, block);
            parameterOUT.Parent = parameterRoot;
            var parameterINOUT = new TIADataRow("IN_OUT", S7DataRowType.STRUCT, block);
            parameterINOUT.Parent = parameterRoot;
            var parameterSTAT = new TIADataRow("STATIC", S7DataRowType.STRUCT, block);
            parameterSTAT.Parent = parameterRoot;
            var parameterTEMP = new TIADataRow("TEMP", S7DataRowType.STRUCT, block);
            parameterTEMP.Parent = parameterRoot;

            foreach (var xElement in sections.Elements())
            {
                TIADataRow useRow = parameterRoot;
                //var sectionName = xElement.Attribute("Name").Value;
                //if (sectionName == "None" || sectionName == "Static")
                //{
                //    useRow = parameterSTAT;
                //    parameterRoot.Add(useRow);
                //}
                //else if (sectionName == "In")
                //{
                //    useRow = parameterIN;
                //    parameterRoot.Add(useRow);
                //}

                parseChildren(useRow, xElement, controllerFolder);
            }

            return parameterRoot;
        }