コード例 #1
0
        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);
        }
コード例 #2
0
        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);
                            int      start = 0;
                            if (akar[0].StartsWith("\""))
                            {
                                start = (int)controllerFolder.VarTabFolder.FindConstant(akar[0].Substring(1, akar[0].Length - 2)).Value;
                            }
                            else
                            {
                                start = Convert.ToInt32(akar[0].Trim());
                            }

                            int stop = 0;
                            if (akar[1].StartsWith("\""))
                            {
                                stop = (int)controllerFolder.VarTabFolder.FindConstant(akar[1].Substring(1, akar[1].Length - 2)).Value;
                            }
                            else
                            {
                                stop = Convert.ToInt32(akar[1].Trim());
                            }

                            arrayStart.Add(start);
                            arrayStop.Add(stop);
                        }

                        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.WORD;
                            break;

                        case "dint":
                            row.DataType = S7DataRowType.DINT;
                            break;

                        case "udint":
                            row.DataType = S7DataRowType.DWORD;
                            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;

                            var udt = controllerFolder.PlcDatatypeFolder.GetBlock(datatype);
                            if (udt != null)
                            {
                                var tiaUdt = udt as TIADataBlock;
                                row.AddRange(((TIADataRow)tiaUdt.Structure).DeepCopy().Children);

                                row.DataTypeBlock = udt;
                                row.DataType      = S7DataRowType.UDT;
                            }

                            //Console.WriteLine("unkown Datatype: " + datatype);
                            break;
                        }
                    }
                }
                else if (xElement.Name.LocalName == "AttributeList")
                {
                }
                else if (xElement.Name.LocalName == "Subelement") //todo -> startwerte von arrays von UDTs
                {
                }
                else
                {
                    //Console.WriteLine("unkown XML Element");
                }
            }
        }