コード例 #1
0
        public string ToString(bool useSymbol, bool addSemicolonAfterCommand, bool useDataBlocksSymbolic)
        {
            if (Command == "NETWORK")
            {
                return((MnemonicLanguage == MnemonicLanguage.English ? "Network " : "Netzwerk ") + Parameter + " : " + NetworkName
                       + (string.IsNullOrEmpty(Comment) ? string.Empty : "\r\n\t Comment : " + Comment.Replace("\n", "\r\n\t           ")));
            }

            string retVal = "";

            if (Label == null || Label == "")
            {
                retVal += new string(' ', 6);
            }
            else
            {
                retVal += Label.PadRight(4) + ": ";
            }

            string cmt = "";

            if (Comment != null && Comment != "")
            {
                cmt = "//" + Comment;
            }

            string ext = "";

            if (ExtParameter != null && ExtParameter.Count > 0 && (Command == Mnemonic.opUC[(int)MnemonicLanguage] || Command == Mnemonic.opCC[(int)MnemonicLanguage]))
            {
                foreach (string myStr in ExtParameter)
                {
                    ext += "\r\n" + " ".PadLeft(12) + myStr;
                }
            }

            if (CallParameter != null && CallParameter.Count > 0 && (Command == Mnemonic.opCALL[(int)MnemonicLanguage]))
            {
                int i   = 0;
                int len = 0;
                foreach (var cpar in CallParameter)
                {
                    len = cpar.Name.Length > len ? cpar.Name.Length : len;
                }
                foreach (var cpar in CallParameter)
                {
                    i++;
                    ext += "\r\n" + " ".PadLeft(12) + cpar.Name.PadRight(len) + " := " + cpar.GetValue(useSymbol);
                    if (i < CallParameter.Count)
                    {
                        ext += ",";
                    }
                    else
                    {
                        ext += ")";
                    }
                    if (!string.IsNullOrEmpty(cpar.Comment))
                    {
                        ext += "  //" + cpar.Comment;
                    }
                }
            }

            if (ActualBlockStatus != null)
            {
                cmt += "     Status: " + ActualBlockStatus.ToString();
            }

            if (Command == "" && Parameter == "")
            {
                return(cmt);
            }

            string par = "";

            if (Parameter != null)
            {
                par = Parameter;
            }

            if (Command == "CALL" && !String.IsNullOrEmpty(DiName))
            {
                var nm = DiName.Replace("DI", "DB");
                if (useDataBlocksSymbolic && this.Parent != null)
                {
                    if ((this.Parent).SymbolTable != null)
                    {
                        var sym1 = this.Parent.SymbolTable.GetEntryFromOperand(par);
                        if (sym1 != null)
                        {
                            par = "\"" + sym1.Symbol + "\"";
                        }

                        if (!DiName.StartsWith("#"))
                        {
                            var sym2 = this.Parent.SymbolTable.GetEntryFromOperand(nm);
                            if (sym2 != null)
                            {
                                nm = "\"" + sym2.Symbol + "\"";
                            }
                        }
                    }
                }
                par += ", " + nm;
            }
            else if (useDataBlocksSymbolic && Parameter.StartsWith("DB") && Parameter[2] != '[' && Parameter[2] != 'D' && Parameter[2] != 'W' && Parameter[2] != 'B' && Parameter[2] != 'X' && this.Parent != null)
            {
                var paras = Parameter.Split(new[] { '.' });
                var fld   = (this.Parent).ParentFolder as BlocksOfflineFolder;
                if (fld != null)
                {
                    var sym = this.Parent.SymbolTable.GetEntryFromOperand(paras[0]);

                    if (sym != null)
                    {
                        par = "\"" + sym.Symbol + "\"";
                    }

                    if (paras.Length > 1)
                    {
                        var byteAdr = int.Parse(paras[1].Replace("DBX", "").Replace("DBB", "").Replace("DBW", "").Replace("DBD", ""));

                        var bitAdr = 0;
                        if (paras.Length > 2)
                        {
                            bitAdr = int.Parse(paras[2]);
                        }

                        var dbBlk = fld.GetBlock(paras[0]) as S7DataBlock;
                        if (dbBlk != null)
                        {
                            var row = dbBlk.GetDataRowWithAddress(new ByteBitAddress(byteAdr, bitAdr));
                            if (row != null)
                            {
                                if (sym != null)
                                {
                                    par = "\"" + sym.Symbol + "\"." + row.StructuredName;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                var sym = SymbolTableEntry;
                if (sym != null && useSymbol)
                {
                    par = "\"" + sym.Symbol + "\"";
                }
            }

            if (Command == "CALL")
            {
                if (ext != "")
                {
                    par += " (";
                }
            }

            if (!string.IsNullOrEmpty(cmt))
            {
                par = par.PadRight(14);
            }

            return(retVal + Command.PadRight(6) + par + (ext == "" && addSemicolonAfterCommand == true ? ";" : "") + cmt +
                   ext + (ext != "" && addSemicolonAfterCommand == true ? ";" : "")); // +"Sz:" + ByteSize.ToString();
        }
コード例 #2
0
        public string ToString(bool useSymbol, bool addSemicolonAfterCommand)
        {
            if (Command == "NETWORK")
            {
                return((MnemonicLanguage == MnemonicLanguage.English ? "Network " : "Netzwerk ") + Parameter + " : " + NetworkName
                       + (string.IsNullOrEmpty(Comment) ? string.Empty : "\r\n\t Comment : " + Comment.Replace("\n", "\r\n\t           ")));
            }

            string retVal = "";

            if (Label == null || Label == "")
            {
                retVal += new string(' ', 6);
            }
            else
            {
                retVal += Label.PadRight(4) + ": ";
            }

            string cmt = "";

            if (Comment != null && Comment != "")
            {
                cmt = "//" + Comment;
            }

            string ext = "";

            if (ExtParameter != null && ExtParameter.Count > 0 && (Command == "UC" || Command == "CC"))
            {
                foreach (string myStr in ExtParameter)
                {
                    ext += "\r\n" + " ".PadLeft(12) + myStr;
                }
            }

            if (CallParameter != null && CallParameter.Count > 0 && (Command == "CALL"))
            {
                int len = 0;
                foreach (var cpar in CallParameter)
                {
                    len = cpar.Name.Length > len ? cpar.Name.Length : len;
                }
                foreach (var cpar in CallParameter)
                {
                    ext += "\r\n" + " ".PadLeft(12) + cpar.Name.PadRight(len) + ":=" + cpar.Value;
                    if (!string.IsNullOrEmpty(cpar.Comment))
                    {
                        ext += "  //" + cpar.Comment;
                    }
                }
            }

            if (ActualBlockStatus != null)
            {
                cmt += "     Status: " + ActualBlockStatus.ToString();
            }

            if (Command == "" && Parameter == "")
            {
                return(cmt);
            }

            string par = "";

            if (Parameter != null)
            {
                par = Parameter;
            }
            if (_SymbolTableEntry != null && useSymbol)
            {
                par = SymbolTableEntry.Symbol;
            }

            if (!string.IsNullOrEmpty(cmt))
            {
                par = par.PadRight(14);
            }

            return(retVal + Command.PadRight(6) + par + (addSemicolonAfterCommand == true ? ";" : "") + cmt + ext); // +"Sz:" + ByteSize.ToString();
        }