public static int GetSize(S7FunctionBlockRow myCmd)
        {

            int MN = 0; //Memnoic still needs to be implemented!

            //This function is there, because for a Jump it sould not call GetMC7, because then we can get circular calls!
            //A Jump in GetMC7 will also call this, to callculate the distance to the jump mark!            
            if (Helper.IsJump(myCmd, MN)) return 4;
            else
                try
                {
                    if (myCmd.MC7 == null) myCmd.MC7 = GetMC7(myCmd);
                    return myCmd.MC7.Length;
                }
                catch (Exception)
                {
                    return 0;
                }
        }
 public S7FunctionBlockParameter(S7FunctionBlockRow Parent)
 {
     this.Parent = Parent;
 }
Exemple #3
0
 public static bool IsNetwork(S7FunctionBlockRow row)
 {
     return row.Command == "NETWORK";
 }
Exemple #4
0
 //Todo: Check if Jump label is used in the Block!
 public static bool IsJumpTarget(S7FunctionBlockRow myCmd, S7FunctionBlock myBlk)
 {
     if (!string.IsNullOrEmpty(myCmd.Label))
         return true;
     return false;
 }
Exemple #5
0
        public static bool IsJump(S7FunctionBlockRow myCmd, int akMemnoic)
        {
            if (myCmd == null)
                return false;

            int MN = akMemnoic;

            if (myCmd.Command == Mnemonic.opSPA[MN]
               || myCmd.Command == Mnemonic.opSPB[MN]
               || myCmd.Command == Mnemonic.opSPBB[MN]
               || myCmd.Command == Mnemonic.opSPBI[MN]
               || myCmd.Command == Mnemonic.opSPBIN[MN]
               || myCmd.Command == Mnemonic.opSPBN[MN]
               || myCmd.Command == Mnemonic.opSPBNB[MN]
               || myCmd.Command == Mnemonic.opSPL[MN]
               || myCmd.Command == Mnemonic.opSPM[MN]
               || myCmd.Command == Mnemonic.opSPMZ[MN]
               || myCmd.Command == Mnemonic.opSPN[MN]
               || myCmd.Command == Mnemonic.opSPO[MN]
               || myCmd.Command == Mnemonic.opSPP[MN]
               || myCmd.Command == Mnemonic.opSPPZ[MN]
               || myCmd.Command == Mnemonic.opSPS[MN]
               || myCmd.Command == Mnemonic.opSPU[MN]
               || myCmd.Command == Mnemonic.opSPZ[MN]
               || myCmd.Command == Mnemonic.opLOOP[MN])
                return true;
            return false;
        }
        public Block GetBlock(ProjectBlockInfo blkInfo, S7ConvertingOptions myConvOpt)
        {
            if (blkInfo._Block != null && ((blkInfo._Block) as S7Block).usedS7ConvertingOptions.Equals(myConvOpt)) 
                return blkInfo._Block;


            ProjectPlcBlockInfo plcblkifo = (ProjectPlcBlockInfo)blkInfo;
            tmpBlock myTmpBlk = GetBlockBytes(blkInfo);

            List<Step7Attribute> step7Attributes = null;

            if (myTmpBlk != null)
            {
                if (myTmpBlk.uda != null)
                {

                    int uPos = 2;
                    if (myTmpBlk.uda != null && myTmpBlk.uda.Length > 0 && myTmpBlk.uda[0] > 0)
                    {
                        step7Attributes = new List<Step7Attribute>();
                        for (int j = 0; j < myTmpBlk.uda[0]; j++)
                        {
                            string t1 = Project.ProjectEncoding.GetString(myTmpBlk.uda, uPos + 1, myTmpBlk.uda[uPos]);
                            uPos += myTmpBlk.uda[uPos] + 1;
                            string t2 = Project.ProjectEncoding.GetString(myTmpBlk.uda, uPos + 1, myTmpBlk.uda[uPos]);
                            uPos += myTmpBlk.uda[uPos] + 1;
                            step7Attributes.Add(new Step7Attribute(t1, t2));
                        }
                    }
                }

                //Begin with the Block Reading...
                if (blkInfo.BlockType == PLCBlockType.VAT)
                {
                    S7VATBlock retValBlock = new S7VATBlock(myTmpBlk.mc7code, myTmpBlk.comments, plcblkifo.BlockNumber, Project.ProjectEncoding);
                    retValBlock.Attributes = step7Attributes;

                    retValBlock.LastCodeChange = myTmpBlk.LastCodeChange;
                    retValBlock.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retValBlock.ParentFolder = this;
                    retValBlock.usedS7ConvertingOptions = myConvOpt;
                    blkInfo._Block = retValBlock;

                    return retValBlock;
                }
                else if (blkInfo.BlockType == PLCBlockType.DB || blkInfo.BlockType == PLCBlockType.UDT)
                {
                    List<string> tmpList = new List<string>();
                    S7DataBlock retVal = new S7DataBlock();
                    retVal.IsInstanceDB = myTmpBlk.IsInstanceDB; 
                    retVal.FBNumber = myTmpBlk.FBNumber;

                    if (myTmpBlk.mc7code != null) 
                        retVal.CodeSize = myTmpBlk.mc7code.Length;

                    retVal.StructureFromString = Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref tmpList, blkInfo.BlockType, false, this, retVal, myTmpBlk.mc7code);
                    if (myTmpBlk.blkinterfaceInMC5 != null)
                    {
                        //List<string> tmp = new List<string>();
                        //retVal.StructureFromMC7 = Parameter.GetInterface(myTmpBlk.blkinterfaceInMC5, myTmpBlk.mc7code, ref tmp, blkInfo.BlockType, myTmpBlk.IsInstanceDB, retVal);
                    }                        
                    retVal.BlockNumber = plcblkifo.BlockNumber;
                    retVal.BlockType = blkInfo.BlockType;
                    retVal.Attributes = step7Attributes;

                    retVal.LastCodeChange = myTmpBlk.LastCodeChange;
                    retVal.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retVal.ParentFolder = this;
                    retVal.usedS7ConvertingOptions = myConvOpt;
                    blkInfo._Block = retVal;

                    return retVal;
                }
                else if (blkInfo.BlockType == PLCBlockType.FC || blkInfo.BlockType == PLCBlockType.FB || blkInfo.BlockType == PLCBlockType.OB || blkInfo.BlockType == PLCBlockType.SFB || blkInfo.BlockType == PLCBlockType.SFC)
                {
                    List<string> ParaList = new List<string>();

                    S7FunctionBlock retVal = new S7FunctionBlock();                   

                    retVal.LastCodeChange = myTmpBlk.LastCodeChange;
                    retVal.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retVal.BlockNumber = plcblkifo.BlockNumber;
                    retVal.BlockType = blkInfo.BlockType;
                    retVal.Attributes = step7Attributes;
                    retVal.KnowHowProtection = myTmpBlk.knowHowProtection;
                    retVal.MnemonicLanguage = Project.ProjectLanguage;

                    retVal.Author = myTmpBlk.username;
                    retVal.Version = myTmpBlk.version;

                    retVal.Parameter = Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref ParaList, blkInfo.BlockType, false, this, retVal);
                
                    if (myTmpBlk.blockdescription != null)
                    {
                        retVal.Title = Project.ProjectEncoding.GetString(myTmpBlk.blockdescription, 3, myTmpBlk.blockdescription[1] - 4);
                        retVal.Description = Project.ProjectEncoding.GetString(myTmpBlk.blockdescription, myTmpBlk.blockdescription[1], myTmpBlk.blockdescription.Length - myTmpBlk.blockdescription[1] - 1).Replace("\n", Environment.NewLine);
                    }

                    if (blkInfo.BlockType == PLCBlockType.FC || blkInfo.BlockType == PLCBlockType.FB || blkInfo.BlockType == PLCBlockType.OB)
                    {
                        retVal.CodeSize = myTmpBlk.mc7code.Length;

                        int[] Networks;
                        Networks = NetWork.GetNetworks(0, myTmpBlk.nwinfo);

                        S7ProgrammFolder prgFld = null;
                        if (this.Parent is S7ProgrammFolder)
                            prgFld = (S7ProgrammFolder)this.Parent;

                        retVal.AWLCode = MC7toAWL.GetAWL(0, myTmpBlk.mc7code.Length - 2, (int)myConvOpt.Mnemonic, myTmpBlk.mc7code, Networks, ParaList, prgFld, retVal);

                        retVal.AWLCode = JumpMarks.AddJumpmarks(retVal.AWLCode, myTmpBlk.jumpmarks, myTmpBlk.nwinfo, myConvOpt);

                        LocalDataConverter.ConvertLocaldataToSymbols(retVal, myConvOpt);
                        
                        CallConverter.ConvertUCToCall(retVal, prgFld, this, myConvOpt, null);

                        FBStaticAccessConverter.ReplaceStaticAccess(retVal, prgFld, myConvOpt);                        

                        #region UseComments from Block
                        if (myConvOpt.UseComments)
                        {
                            List<FunctionBlockRow> newAwlCode = new List<FunctionBlockRow>();

                            int n = 0;
                            int akRowInAwlCode = 0;
                            int lineNumberInCall = 0; //Counter wich line in Command (for Calls and UCs)

                            if (myTmpBlk.comments != null)
                            {
                                byte[] cmt = myTmpBlk.comments;

                                //string aa = System.Text.Encoding.GetEncoding("Windows-1251").GetString(cmt);
                                //string testaa = "";

                                while (n < myTmpBlk.comments.Length)
                                {
                                    int kommLen = cmt[n + 0];
                                    int startNWKomm = cmt[n + 1];
                                    int anzUebsprungZeilen = cmt[n + 2] + cmt[n + 3] * 0x100;
                                    int lenNWKommZeile = cmt[n + 3] + cmt[n + 4] * 0x100;
                                    //Console.WriteLine(cmt[n + 5].ToString("X"));
                                    if (cmt[n + 5] == 0x06)
                                    {
                                        //NWKomentar:
                                        string tx1 = Project.ProjectEncoding.GetString(cmt, n + 6, startNWKomm - 7);
                                        string tx2 = Project.ProjectEncoding.GetString(cmt, n + startNWKomm, lenNWKommZeile - startNWKomm - 1).Replace("\n", Environment.NewLine);
                                        n += lenNWKommZeile;

                                        if (retVal.AWLCode.Count > akRowInAwlCode)
                                        {
                                            while (retVal.AWLCode.Count - 1 > akRowInAwlCode && retVal.AWLCode[akRowInAwlCode].Command != "NETWORK")
                                            {
                                                if (!newAwlCode.Contains(retVal.AWLCode[akRowInAwlCode]))
                                                {
                                                    //newAwlCode.Add(retVal.AWLCode[akRowInAwlCode]);
                                                    S7FunctionBlockRow akRw = (S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode];

                                                    if (akRw.CombineDBAccess)
                                                    {
                                                        S7FunctionBlockRow nRw = (S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode + 1];
                                                        if (!nRw.Parameter.Contains("["))
                                                        {
                                                            nRw.Parameter = akRw.Parameter + "." + nRw.Parameter;
                                                            nRw.MC7 = Helper.CombineByteArray(akRw.MC7, nRw.MC7);
                                                            nRw.Label = akRw.Label ?? nRw.Label;
                                                            akRw = nRw;
                                                            retVal.AWLCode.RemoveAt(akRowInAwlCode + 1);
                                                        }
                                                    }

                                                    if (!newAwlCode.Contains(akRw))
                                                        newAwlCode.Add(akRw);
                                                }
                                                akRowInAwlCode++;
                                            }
                                            ((S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode]).NetworkName = tx1;
                                            ((S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode]).Comment = tx2;
                                            newAwlCode.Add(retVal.AWLCode[akRowInAwlCode]);
                                        }
                                        akRowInAwlCode++;

                                        lineNumberInCall = 0;
                                    }
                                    else
                                    {
                                        S7FunctionBlockRow lastRow = null;

                                        //Anzahl der Anweisungen vor diesem Kommentar (inklusive aktueller Zeile!)
                                        for (int q = 0; q < (anzUebsprungZeilen); q++)
                                        {
                                            if (retVal.AWLCode.Count > akRowInAwlCode)
                                            {
                                                S7FunctionBlockRow akRw = (S7FunctionBlockRow) retVal.AWLCode[akRowInAwlCode];

                                                 if (cmt[n + 4] == 0xc0 && q == anzUebsprungZeilen-1)
                                                     akRw.CombineDBAccess = false;

                                                //Db Zugriff zusammenfügen...
                                                if (akRw.CombineDBAccess)
                                                {
                                                    S7FunctionBlockRow nRw = (S7FunctionBlockRow) retVal.AWLCode[akRowInAwlCode + 1];
                                                    nRw.Parameter = akRw.Parameter + "." + nRw.Parameter;
                                                    nRw.MC7 = Helper.CombineByteArray(akRw.MC7, nRw.MC7);
                                                    nRw.Label = akRw.Label ?? nRw.Label;
                                                    akRw = nRw;
                                                    retVal.AWLCode.RemoveAt(akRowInAwlCode + 1);
                                                }
                                                
                                                if (!newAwlCode.Contains(akRw))
                                                    newAwlCode.Add(akRw);


                                                if (akRw.GetNumberOfLines() == 1)
                                                {
                                                    lineNumberInCall = 0;

                                                    lastRow = akRw;

                                                    //if (!newAwlCode.Contains(akRw))
                                                    //    newAwlCode.Add(akRw);

                                                    akRowInAwlCode++;
                                                }
                                                else
                                                {
                                                    lastRow = akRw;
                                                    if (lineNumberInCall == 0 && !(cmt[n + 4] != 0x80 && cmt[n + 4] != 0xc0))
                                                    {
                                                        //if (!newAwlCode.Contains(akRw))
                                                        //    newAwlCode.Add(akRw);                                                        
                                                    }

                                                    if (akRw.GetNumberOfLines() - 1 == lineNumberInCall)
                                                    {
                                                        akRowInAwlCode++;
                                                        lineNumberInCall = 0;
                                                        //subCnt++;    //The set to zero was wrong here, but maybe now comments on calls do not work, need to check!
                                                    }
                                                    else
                                                    {
                                                        lineNumberInCall++;
                                                    }
                                                }
                                            }
                                        }


                                        //if (lastRow == null || cmt[n + 4] != 0x80)
                                        if (lastRow == null || (cmt[n + 4] != 0x80 && cmt[n + 4] != 0xc0))
                                        {
                                            lastRow = new S7FunctionBlockRow(){ Parent = retVal };
                                            newAwlCode.Add(lastRow);
                                            lineNumberInCall = 0;
                                        }

                                        string tx1 = Project.ProjectEncoding.GetString(cmt, n + 6, kommLen);
                                        if (lineNumberInCall == 0)
                                            lastRow.Comment = tx1;
                                        else
                                            if (lastRow.Command == "CALL")
                                                if (lineNumberInCall == 1) lastRow.Comment = tx1;
                                                else
                                                {
                                                    if (lastRow.CallParameter.Count >= lineNumberInCall - 2)
                                                    {
                                                        lastRow.CallParameter[lineNumberInCall - 2].Comment = tx1;
                                                    }
                                                }
                                        n += kommLen + 6;

                                        //subCnt = 0;
                                    }
                                }
                            }
                            while (akRowInAwlCode < retVal.AWLCode.Count)
                            {
                                newAwlCode.Add(retVal.AWLCode[akRowInAwlCode]);
                                akRowInAwlCode++;
                            }
                            retVal.AWLCode = newAwlCode;
                        }
                        #endregion
                    }

                    retVal.Networks = NetWork.GetNetworksList(retVal);

                    retVal.ParentFolder = this;
                    retVal.usedS7ConvertingOptions = myConvOpt;
                    blkInfo._Block = retVal;

                    return retVal;
                }
            }
            return null;
        }
Exemple #7
0
 public S7FunctionBlockParameter(S7FunctionBlockRow Parent)
 {
     this.Parent = Parent;
 }
        //In this Class a UC is converted to a Call and also backwards...
        public static void ConvertUCToCall(S7FunctionBlock myFct, S7ProgrammFolder myFld, BlocksOfflineFolder myblkFld, S7ConvertingOptions myOpt, byte[] addInfoFromBlock)
        {
            if (myOpt.GenerateCallsfromUCs)
            {
                int inBld = 0; //1=nach BLD 1
                S7FunctionBlockRow newRow = null;

                Dictionary<string, string> Parameters = new Dictionary<string, string>();
                List<FunctionBlockRow> retVal = new List<FunctionBlockRow>();
                List<FunctionBlockRow> tempList = new List<FunctionBlockRow>();

                string registerDi = "DI";
                string registerDb = "";
                string registerAkku1 = "";
                string registerAkku2 = "";
                string registerAR1 = "";
                string registerAR2 = "";

                string diName = "";
                string akPar = "";
                string db = "";
                string label = "";
                string akku = "";
                bool afterCall = false;
                bool multiInstance = false;
                int multiInstanceOffset = 0;
                Pointer ar2Addr = new Pointer(0,0);

                S7FunctionBlockRow callRow = null;

                for (int n = 0; n < myFct.AWLCode.Count; n++)
                {
                    S7FunctionBlockRow row = (S7FunctionBlockRow)myFct.AWLCode[n];
                    if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "1" || row.Parameter == "7" || row.Parameter == "3" || row.Parameter == "16" || row.Parameter == "14") && inBld == 0)
                    {
                        retVal.AddRange(tempList);
                        tempList.Clear();

                        Parameters.Clear();
                        db = "";

                        label = row.Label;

                        inBld = Convert.ToInt32(row.Parameter);
                        newRow = null;
                        afterCall = false;
                        callRow = null;
                        diName = "";

                        multiInstance = false;
                        multiInstanceOffset = 0;
                        ar2Addr = new Pointer(0, 0);

                        tempList.Add(row);
                    }
                    else if (inBld == 1 || inBld == 7)
                    {
                        #region FC Aufruf
                        tempList.Add(row);
                        if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Mnemonic.opBLD[(int)myOpt.Mnemonic])
                        {
                            //Do nothing, but this line needs to be there!
                        }
                        else if (row.Command == Mnemonic.opU[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opUN[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opX[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opXN[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opL[(int)myOpt.Mnemonic])
                        {
                            akPar = row.Parameter;
                        }
                        else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic])
                        {
                            db = row.Parameter + ".";
                        }
                        else if (row.Command == Mnemonic.opCLR[(int)myOpt.Mnemonic])
                        {
                            akPar = "FALSE";
                        }
                        else if (row.Command == Mnemonic.opSET[(int)myOpt.Mnemonic] )
                        {
                            akPar = "TRUE";
                        }
                        else if (row.Command == Mnemonic.opTAR2[(int)myOpt.Mnemonic])
                        {
                            //look what we need to do here!!!
                        }
                        else if (row.Command == Mnemonic.opPAR2[(int)myOpt.Mnemonic])
                        {
                            //look what we need to do here!!!
                        }
                        else if (row.Command == Mnemonic.opLAR2[(int)myOpt.Mnemonic])
                        {
                            //look what we need to do here!!!
                        }
                        else if (row.Command == Mnemonic.opLAR1[(int)myOpt.Mnemonic])
                        {
                            //look what we need to do here!!!
                        }
                        else if ((row.Command == "=") && akPar != "")
                        {
                            if (afterCall == false)
                            {
                                string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key, db + akPar);
                            }
                            else
                            {
                                string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key, db + row.Parameter);
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar != "")
                        {
                            if (afterCall == false)
                            {
                                string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key + ".0", db + akPar);
                            }
                            else
                            {
                                string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey("P#V " + key))
                                    Parameters.Add("P#V " + key, db + row.Parameter);
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar == "")
                        {
                            //look what we need to do here!!!
                        }
                        else if (row.Command == Mnemonic.opUC[(int)myOpt.Mnemonic])
                        {
                            //Commands after a Call --> Out-Para
                            callRow = row;
                            afterCall = true;
                        }
                        else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "2" || row.Parameter == "8"))
                        {
                            //Block Interface auslesen (von FC oder vom Programm)
                            S7DataRow para = myblkFld.GetInterface(callRow.Parameter);

                            newRow = new S7FunctionBlockRow();
                            newRow.Command = Mnemonic.opCALL[(int)myOpt.Mnemonic];
                            newRow.Parent = callRow.Parent;
                            newRow.Parameter = callRow.Parameter;
                            newRow.CallParameter = new List<S7FunctionBlockParameter>();

                            for (int i = 0; i < callRow.ExtParameter.Count; i++)
                            {
                                string s = callRow.ExtParameter[i];

                                string parnm = "";
                                S7DataRow akRow = Parameter.GetFunctionParameterFromNumber(para, i);
                                if (akRow != null)
                                    parnm = akRow.Name + "";
                                else
                                    parnm = "$$undef";

                                S7FunctionBlockParameter newPar = new S7FunctionBlockParameter(newRow);
                                newPar.Name = parnm;
                                if (akRow != null)
                                {
                                    newPar.ParameterDataType = akRow.DataType;
                                    if (akRow.Parent.Name == "OUT")
                                        newPar.ParameterType = S7FunctionBlockParameterDirection.OUT;
                                    else if (akRow.Parent.Name == "IN_OUT")
                                        newPar.ParameterType = S7FunctionBlockParameterDirection.IN_OUT;
                                    else
                                        newPar.ParameterType = S7FunctionBlockParameterDirection.IN;
                                }

                                if (akRow != null)
                                {
                                    int posL = s.IndexOf(' ');
                                    int ak_address = 0;
                                    if (posL >= 0)
                                        ak_address = Convert.ToInt32(s.Substring(posL + 1).Split('.')[0]);
                                    else
                                    {
                                        ak_address = Convert.ToInt32(s.Substring(2).Split('.')[0])*8 +
                                                     Convert.ToInt32(s.Substring(2).Split('.')[1]);
                                    }

                                    int lokaldata_address = -1;
                                    if (s.Substring(0, 3) == "P#V")
                                        lokaldata_address = Convert.ToInt32(s.Substring(4).Split('.')[0]);

                                    if (akRow.DataType == S7DataRowType.STRING || akRow.DataType == S7DataRowType.DATE_AND_TIME ||
                                        akRow.DataType == S7DataRowType.STRUCT || akRow.DataType == S7DataRowType.UDT ||
                                        akRow.DataType == S7DataRowType.POINTER || akRow.IsArray)
                                    {
                                        string p1 = "";
                                        string p2 = "";
                                        Parameters.TryGetValue("P#V " + (lokaldata_address + 0).ToString() + ".0", out p1);
                                        Parameters.TryGetValue("P#V " + (lokaldata_address + 2).ToString() + ".0", out p2);

                                        string tmp = "";
                                        if (p1 != "" && p1 != "0")
                                            tmp += "P#DB" + p1 + "." + (p2 == null ? "0" : p2.Substring(2));
                                        else
                                            tmp += p2;
                                        newPar.Value = tmp;
                                        newRow.CallParameter.Add(newPar);
                                    }
                                    else if (akRow.DataType == S7DataRowType.ANY)
                                    {
                                        string tmp = s;
                                        if (Parameters.ContainsKey("P#V " + (lokaldata_address + 0).ToString() + ".0") &&
                                            Parameters.ContainsKey("P#V " + (lokaldata_address + 2).ToString() + ".0") &&
                                            Parameters.ContainsKey("P#V " + (lokaldata_address + 4).ToString() + ".0") &&
                                            Parameters.ContainsKey("P#V " + (lokaldata_address + 6).ToString() + ".0"))
                                        {
                                            string p1 = Parameters["P#V " + (lokaldata_address + 0).ToString() + ".0"];
                                            string p2 = Parameters["P#V " + (lokaldata_address + 2).ToString() + ".0"];
                                            string p3 = Parameters["P#V " + (lokaldata_address + 4).ToString() + ".0"];
                                            string p4 = Parameters["P#V " + (lokaldata_address + 6).ToString() + ".0"];

                                            tmp = "P#";
                                            if (p3 != "0")
                                                tmp += "DB" + p3 + ".";
                                            tmp += p4.Substring(2);
                                            tmp += " BYTE "; //Todo Parse Byte 1 if the Type is Byte!
                                            tmp += p2;
                                        }
                                        newPar.Value = tmp;
                                        newRow.CallParameter.Add(newPar);
                                    }
                                    else
                                    {
                                        if (Parameters.ContainsKey(s))
                                        {
                                            string par = Parameters[s];
                                            if (akRow.DataType == S7DataRowType.S5TIME && par[0] >= '0' && par[0] <= '9')
                                            {
                                                newPar.Value = Helper.GetS5Time(
                                                                            BitConverter.GetBytes(Convert.ToInt32(par))[1],
                                                                            BitConverter.GetBytes(Convert.ToInt32(par))[0]);
                                            }
                                            else if (akRow.DataType == S7DataRowType.TIME && par[0] >= '0' && par[0] <= '9')
                                            {
                                                newPar.Value = Helper.GetDTime(BitConverter.GetBytes(Convert.ToInt32(par)),0);
                                            }
                                            else if (akRow.DataType == S7DataRowType.CHAR && par[0] == 'B')
                                            {
                                                newPar.Value = (char) Int32.Parse(par.Substring(5), System.Globalization.NumberStyles.AllowHexSpecifier) + "'";
                                            }
                                            else
                                            {
                                                newPar.Value = Parameters[s];
                                            }
                                        }
                                        else
                                        {
                                            if (akRow.DataType == S7DataRowType.BOOL)
                                            {
                                                newPar.Value = s.Substring(2).Replace('V', 'L');
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_DB)
                                            {
                                                newPar.Value = "DB" + ak_address.ToString();
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_FB)
                                            {
                                                newPar.Value = "FB" + ak_address.ToString();
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_FC)
                                            {
                                                newPar.Value = "FC" + ak_address.ToString();
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_SDB)
                                            {
                                                newPar.Value = "SDB" + ak_address.ToString();
                                            }
                                            else if (akRow.DataType == S7DataRowType.TIMER)
                                            {
                                                newPar.Value = Mnemonic.adT[(int)myOpt.Mnemonic] + ak_address.ToString();
                                            }
                                            else if (akRow.DataType == S7DataRowType.COUNTER)
                                            {
                                                newPar.Value = Mnemonic.adZ[(int)myOpt.Mnemonic] + ak_address.ToString();
                                            }
                                            else
                                            {
                                                string ber = "";
                                                if (s.Substring(0, 5) == "P#DBX")
                                                    ber = "DB";
                                                else if (s.Substring(0, 5) == "P#DIX")
                                                    ber = "DI";
                                                else
                                                    ber = s.Substring(2, 1);

                                                if (akRow.ByteLength == 1)
                                                    ber += "B";
                                                else if (akRow.ByteLength == 2)
                                                    ber += "W";
                                                else if (akRow.ByteLength == 4)
                                                    ber += "D";

                                                newPar.Value = ber.Replace('V', 'L') + ak_address.ToString();

                                            }
                                        }

                                        newRow.CallParameter.Add(newPar);
                                    }
                                }
                            }

                            newRow.CombinedCommands = tempList;
                            newRow.Label = label;

                            int sz = 0;
                            foreach (var functionBlockRow in newRow.CombinedCommands)
                            {
                                sz += ((S7FunctionBlockRow) functionBlockRow).ByteSize;
                            }
                            byte[] mcges=new byte[sz];
                            sz = 0;
                            foreach (var functionBlockRow in newRow.CombinedCommands)
                            {
                                Array.Copy(((S7FunctionBlockRow) functionBlockRow).MC7, 0, mcges, sz, ((S7FunctionBlockRow) functionBlockRow).ByteSize);
                                sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize;
                            }
                            newRow.MC7 = mcges;

                            retVal.Add(newRow);
                            Parameters.Clear();
                            tempList = new List<FunctionBlockRow>();
                            inBld = 0;

                            newRow = null;
                        }
                        else
                        {
                            retVal.AddRange(tempList);
                            tempList.Clear();

                            inBld = 0;
                        }
                        #endregion
                    }
                    else if (inBld == 3 || inBld == 16 || inBld == 14)
                    {
                        #region FB Aufruf
                        tempList.Add(row);
                        if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Mnemonic.opBLD[(int)myOpt.Mnemonic])
                        {
                            //Do nothing, but this line needs to be there!
                        }
                        else if (row.Command == Mnemonic.opTDB[(int)myOpt.Mnemonic])
                        {
                            //Do nothing, but this line needs to be there!
                        }
                        else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && row.Parameter=="11")
                        {
                            //whatever this BLD 11 in the FB Calls means...
                        }
                        else if (row.Command == Mnemonic.opTAR2[(int)myOpt.Mnemonic])
                        {
                            if (ar2Addr.MemoryArea==MemoryArea.None)
                                akPar = "P#DIX " + ar2Addr.ToString();
                            else
                                akPar = ar2Addr.ToString(myOpt.Mnemonic);
                        }
                        else if (row.Command == Mnemonic.opLAR2[(int)myOpt.Mnemonic])
                        {
                            if (row.Parameter.StartsWith("P#"))
                            {
                                ar2Addr = new Pointer(row.Parameter.Substring(2));
                            }
                            else
                            {
                                ar2Addr.ByteAddress = 0;
                                ar2Addr.BitAddress = 0;
                            }
                        }
                        else if (row.Command == Mnemonic.opPAR2[(int)myOpt.Mnemonic])
                        {
                            ar2Addr += new Pointer(row.Parameter);
                        }
                        else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic] && (tempList.Count == 4))
                        {
                            diName = row.Parameter;
                        }
                        else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic] && row.Parameter.Contains("[") && (tempList.Count == 6))
                        {
                            multiInstance = true;

                            diName = "";
                        }
                        else if (row.Command == Mnemonic.opU[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opUN[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opX[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opXN[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opL[(int)myOpt.Mnemonic])
                        {
                            akPar = db + row.Parameter;
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic])
                        {
                            db = row.Parameter + ".";
                        }
                        else if (row.Command == "CLR")
                        {
                            akPar = "FALSE";
                        }
                        else if (row.Command == "SET")
                        {
                            akPar = "TRUE";
                        }
                        else if ((row.Command == "=") && akPar != "")
                        {
                            if (afterCall == false)
                            {
                                if (!Parameters.ContainsKey(row.Parameter))
                                    Parameters.Add(row.Parameter, akPar);
                            }
                            else
                            {
                                if (!Parameters.ContainsKey(akPar))
                                    Parameters.Add(akPar, row.Parameter);
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar != "")
                        {
                            if (afterCall == false)
                            {
                                if (!Parameters.ContainsKey(row.Parameter))
                                    Parameters.Add(row.Parameter, akPar);
                            }
                            else
                            {
                                if (!Parameters.ContainsKey(akPar))
                                    Parameters.Add(akPar, row.Parameter);
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic])
                        {
                            if (afterCall == false)
                            {
                                if (!Parameters.ContainsKey(row.Parameter))
                                    Parameters.Add(row.Parameter, "");
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opUC[(int)myOpt.Mnemonic])
                        {
                            multiInstanceOffset = 0;
                            for (int j = tempList.Count - 2; j > -1; j--)
                            {
                                if (tempList[j].Command == Mnemonic.opPAR2[(int)myOpt.Mnemonic])
                                    multiInstanceOffset += (int)double.Parse((((S7FunctionBlockRow)tempList[j]).Parameter.Substring(2)), CultureInfo.InvariantCulture);
                                break;
                            }

                            //Commands after a Call --> Out-Para
                            callRow = row;
                            afterCall = true;
                        }
                        else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "4" || row.Parameter == "17" || row.Parameter == "15"))
                        {
                            //Block Interface auslesen (von FC oder vom Programm)
                            S7DataRow para = myblkFld.GetInterface(callRow.Parameter);

                            newRow = new S7FunctionBlockRow();
                            newRow.Parent = callRow.Parent;
                            newRow.Command = Mnemonic.opCALL[(int)myOpt.Mnemonic];
                            newRow.Parameter = callRow.Parameter;
                            if (diName.Length > 2 && !diName.StartsWith("#"))
                                newRow.DiName = "DI" + int.Parse(diName.Substring(2));
                            else if (diName.StartsWith("#"))
                                newRow.DiName = diName;
                            newRow.CallParameter = new List<S7FunctionBlockParameter>();

                            if (para != null)
                            {
                            var allPar = para.Children.Where(itm => itm.Name == "IN" || itm.Name == "IN_OUT" || itm.Name == "OUT");
                                foreach (var s7DataRowMain in allPar)
                                {
                                    foreach (var s7DataRow in s7DataRowMain.Children)
                                    {
                                        S7FunctionBlockParameter newPar = new S7FunctionBlockParameter(newRow);
                                        newPar.Name = s7DataRow.Name;

                                        string par = null;
                                        if (!multiInstance) Parameters.TryGetValue(((S7DataRow)s7DataRow).BlockAddressInDbFormat.Replace("DB", "DI"), out par);
                                        else if (((S7DataRow)s7DataRow).DataType == S7DataRowType.ANY)
                                        {
                                            var anySizeAddr = ((S7DataRow)s7DataRow).BlockAddress.ByteAddress + multiInstanceOffset + 2;
                                            var anyPosAddr = ((S7DataRow)s7DataRow).BlockAddress.ByteAddress + multiInstanceOffset + 6;

                                            string anySize = "";
                                            string anyPos = "";
                                            Parameters.TryGetValue("DIW[AR2,P#" + anySizeAddr + ".0]", out anySize);
                                            Parameters.TryGetValue("DID[AR2,P#" + anyPosAddr + ".0]", out anyPos);
                                            par = anyPos + " BYTE " + anySize;
                                        }
                                        else
                                        {
                                            var addr = ((S7DataRow)s7DataRow).BlockAddressInDbFormat;
                                            if (!string.IsNullOrEmpty(addr))
                                            {
                                                var addrTp = addr.Substring(0, 3).Replace("DB", "DI");
                                                double bytepos = double.Parse(addr.Substring(3), CultureInfo.InvariantCulture) + multiInstanceOffset;
                                                Parameters.TryGetValue(addrTp + "[AR2,P#" + bytepos.ToString("0.0", CultureInfo.InvariantCulture) + "]", out par);
                                            }
                                        }

                                        if (par != null && par.Contains("[AR2"))
                                        {
                                            newPar.Value = par;
                                            var addr = par.Substring(10);
                                            addr = addr.Substring(0, addr.Length - 1);
                                            var pRow = S7DataRow.GetDataRowWithAddress(myFct.Parameter.Children.Where(itm => itm.Name != "TEMP").Cast<S7DataRow>(), new ByteBitAddress(addr));
                                            if (pRow != null) newPar.Value = ((S7DataRow)pRow).StructuredName.Substring(((S7DataRow)pRow).StructuredName.IndexOf('.') + 1);

                                        }
                                        else
                                        {
                                            switch (((S7DataRow)s7DataRow).DataType)
                                            {
                                                case S7DataRowType.BLOCK_DB:
                                                    newPar.Value = "DB" + par;
                                                    break;
                                                case S7DataRowType.BLOCK_FC:
                                                    newPar.Value = "FC" + par;
                                                    break;
                                                case S7DataRowType.BLOCK_FB:
                                                    newPar.Value = "FB" + par;
                                                    break;
                                                case S7DataRowType.TIMER:
                                                    newPar.Value = Mnemonic.adT[(int)myOpt.Mnemonic] + par.ToString();
                                                    break;
                                                case S7DataRowType.COUNTER:
                                                    newPar.Value = Mnemonic.adZ[(int)myOpt.Mnemonic] + par.ToString();
                                                    break;
                                                case S7DataRowType.TIME:
                                                    if (par != null && par.StartsWith("L#"))
                                                    {
                                                        var arr = BitConverter.GetBytes(Convert.ToInt32(par.Substring(2)));
                                                        Array.Reverse(arr);
                                                        newPar.Value = Helper.GetDTime(arr, 0);
                                                    }
                                                    else
                                                    {
                                                        newPar.Value = par;
                                                    }
                                                    break;
                                                default:
                                                    newPar.Value = par;
                                                    break;
                                            }
                                        }

                                        newRow.CallParameter.Add(newPar);
                                    }
                                }
                            }

                            newRow.CombinedCommands = tempList;
                            newRow.Label = label;

                            int sz = 0;
                            foreach (var functionBlockRow in newRow.CombinedCommands)
                            {
                                sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize;
                            }
                            byte[] mcges = new byte[sz];
                            sz = 0;
                            foreach (var functionBlockRow in newRow.CombinedCommands)
                            {
                                Array.Copy(((S7FunctionBlockRow)functionBlockRow).MC7, 0, mcges, sz, ((S7FunctionBlockRow)functionBlockRow).ByteSize);
                                sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize;
                            }
                            newRow.MC7 = mcges;

                            retVal.Add(newRow);
                            Parameters.Clear();
                            tempList = new List<FunctionBlockRow>();
                            inBld = 0;

                            newRow = null;
                        }
                        else
                        {
                            retVal.AddRange(tempList);
                            tempList.Clear();

                            inBld = 0;
                        }
                        #endregion
                    }
                    else
                    {
                        retVal.Add(row);
                    }

                }
                myFct.AWLCode = retVal;
            }
        }
        //In this Class a UC is converted to a Call and also backwards...
        public static void ConvertUCToCall(S7FunctionBlock myFct, S7ProgrammFolder myFld, BlocksOfflineFolder myblkFld, S7ConvertingOptions myOpt, byte[] addInfoFromBlock)
        {
            if (myOpt.GenerateCallsfromUCs)
            {
                int inBld = 0; //1=nach BLD 1
                S7FunctionBlockRow newRow = null;

                Dictionary<string, string> Parameters = new Dictionary<string, string>();
                List<FunctionBlockRow> retVal = new List<FunctionBlockRow>();
                List<FunctionBlockRow> tempList = new List<FunctionBlockRow>();

                string akPar = "";
                string db = "";
                string label = "";
                bool afterCall = false;
                S7FunctionBlockRow callRow = null;

                for (int n = 0; n < myFct.AWLCode.Count; n++)
                {
                    S7FunctionBlockRow row = (S7FunctionBlockRow)myFct.AWLCode[n];
                    if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && ( row.Parameter == "1" ||  row.Parameter == "7") && inBld==0)
                    {
                        retVal.AddRange(tempList);
                        tempList.Clear();

                        Parameters.Clear();
                        db = "";

                        label = row.Label;

                        inBld = Convert.ToInt32(row.Parameter);
                        newRow = null;
                        afterCall = false;
                        callRow = null;
                        tempList.Add(row);
                    }
                    else if (inBld > 0)
                    {
                        tempList.Add(row);
                        if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Mnemonic.opBLD[(int)myOpt.Mnemonic])
                        {
                            //Do nothing, but this line needs to be there!
                        }
                        else if (row.Command == Mnemonic.opU[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opUN[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opX[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opXN[(int)myOpt.Mnemonic] ||
                                 row.Command == Mnemonic.opL[(int)myOpt.Mnemonic])
                        {
                            akPar = row.Parameter;
                        }
                        else if (row.Command == "AUF")
                        {
                            db = row.Parameter + ".";
                        }
                        else if (row.Command == "CLR")
                        {
                            akPar = "FALSE";
                        }
                        else if (row.Command == "SET")
                        {
                            akPar = "TRUE";
                        }
                        else if ((row.Command == "=") && akPar != "")
                        {
                            if (afterCall == false)
                            {
                                string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key, db + akPar);
                            }
                            else
                            {
                                string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key, db + row.Parameter);
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar != "")
                        {
                            if (afterCall == false)
                            {
                                string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key + ".0", db + akPar);
                            }
                            else
                            {
                                string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "");
                                if (!Parameters.ContainsKey(key))
                                    Parameters.Add("P#V " + key, db + row.Parameter);
                            }
                            akPar = "";
                            db = "";
                        }
                        else if (row.Command == Mnemonic.opUC[(int)myOpt.Mnemonic])
                        {
                            //Commands after a Call --> Out-Para
                            callRow = row;
                            afterCall = true;
                        }
                        else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "2" || row.Parameter == "8"))
                        {
                            //Block Interface auslesen (von FC oder vom Programm)
                            //myFld.BlocksOfflineFolder.GetBlock()
                            S7DataRow para = myblkFld.GetInterface(callRow.Parameter);

                            newRow = new S7FunctionBlockRow();
                            newRow.Command = Mnemonic.opCALL[(int)myOpt.Mnemonic];
                            newRow.Parameter = callRow.Parameter;
                            //newRow.ExtParameter = new List<string>();
                            newRow.CallParameter=new List<S7FunctionBlockParameter>();

                            for (int i = 0; i < callRow.ExtParameter.Count; i++)
                            {
                                string s = callRow.ExtParameter[i];

                                string parnm = "";
                                S7DataRow akRow = Parameter.GetFunctionParameterFromNumber(para, i);
                                if (akRow != null)
                                    parnm = akRow.Name + "";
                                else
                                    parnm = "$$undef";

                                S7FunctionBlockParameter newPar = new S7FunctionBlockParameter();
                                newPar.Name = parnm;
                                if (akRow != null)
                                {
                                    newPar.ParameterDataType = akRow.DataType;
                                    if (akRow.Parent.Name == "OUT")
                                        newPar.ParameterType = S7FunctionBlockParameterDirection.OUT;
                                    else if (akRow.Parent.Name == "IN_OUT")
                                        newPar.ParameterType = S7FunctionBlockParameterDirection.IN_OUT;
                                    else
                                        newPar.ParameterType = S7FunctionBlockParameterDirection.IN;
                                    //newPar.ParameterType
                                }

                                if (akRow != null)
                                {
                                    int posL = s.IndexOf(' ');
                                    int ak_address = 0;
                                    if (posL >= 0)
                                        ak_address = Convert.ToInt32(s.Substring(posL + 1).Split('.')[0]);
                                    else
                                    {
                                        ak_address = Convert.ToInt32(s.Substring(2).Split('.')[0])*8 +
                                                     Convert.ToInt32(s.Substring(2).Split('.')[1]);
                                    }

                                    int lokaldata_address = -1;
                                    if (s.Substring(0, 3) == "P#V")
                                        lokaldata_address = Convert.ToInt32(s.Substring(4).Split('.')[0]);

                                    if (akRow.DataType == S7DataRowType.STRING || akRow.DataType == S7DataRowType.DATE_AND_TIME ||
                                        akRow.DataType == S7DataRowType.STRUCT || akRow.DataType == S7DataRowType.UDT ||
                                        akRow.DataType == S7DataRowType.POINTER || akRow.IsArray)
                                    {
                                        string p1 = Parameters["P#V " + (lokaldata_address + 0).ToString() + ".0"];
                                        string p2 = Parameters["P#V " + (lokaldata_address + 2).ToString() + ".0"];

                                        string tmp = "";
                                        if (p1 != "" && p1 != "0")
                                            tmp += "P#DB" + p1 + "." + p2.Substring(2);
                                        else
                                            tmp += p2;
                                        newPar.Value = tmp;
                                        newRow.CallParameter.Add(newPar);
                                        //newRow.ExtParameter.Add(parnm + tmp);
                                    }
                                    else if (akRow.DataType == S7DataRowType.ANY)
                                    {
                                        string tmp = s;
                                        if (Parameters.ContainsKey("P#V " + (lokaldata_address + 0).ToString() + ".0") &&
                                            Parameters.ContainsKey("P#V " + (lokaldata_address + 2).ToString() + ".0") &&
                                            Parameters.ContainsKey("P#V " + (lokaldata_address + 4).ToString() + ".0") &&
                                            Parameters.ContainsKey("P#V " + (lokaldata_address + 6).ToString() + ".0"))
                                        {
                                            string p1 = Parameters["P#V " + (lokaldata_address + 0).ToString() + ".0"];
                                            string p2 = Parameters["P#V " + (lokaldata_address + 2).ToString() + ".0"];
                                            string p3 = Parameters["P#V " + (lokaldata_address + 4).ToString() + ".0"];
                                            string p4 = Parameters["P#V " + (lokaldata_address + 6).ToString() + ".0"];

                                            tmp = "P#";
                                            if (p3 != "0")
                                                tmp += "DB" + p3 + ".";
                                            tmp += p4.Substring(2);
                                            tmp += " BYTE "; //Todo Parse Byte 1 if the Type is Byte!
                                            tmp += p2;
                                        }
                                        newPar.Value = tmp;
                                        newRow.CallParameter.Add(newPar);
                                        //newRow.ExtParameter.Add(parnm + tmp);
                                    }
                                    else
                                    {
                                        if (Parameters.ContainsKey(s))
                                        {
                                            string par = Parameters[s];
                                            if (akRow.DataType == S7DataRowType.S5TIME && par[0] >= '0' && par[0] <= '9')
                                            {
                                                newPar.Value = Helper.GetS5Time(
                                                                            BitConverter.GetBytes(Convert.ToInt32(par))[1],
                                                                            BitConverter.GetBytes(Convert.ToInt32(par))[0]);
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm +
                                                //                        Helper.GetS5Time(
                                                //                            BitConverter.GetBytes(Convert.ToInt32(par))[1],
                                                //                            BitConverter.GetBytes(Convert.ToInt32(par))[0]));
                                            }
                                            else if (akRow.DataType == S7DataRowType.TIME && par[0] >= '0' && par[0] <= '9')
                                            {
                                                newPar.Value = Helper.GetDTime(BitConverter.GetBytes(Convert.ToInt32(par)),0);
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm +
                                                //                        Helper.GetDTime(BitConverter.GetBytes(Convert.ToInt32(par)),0));
                                            }
                                            else if (akRow.DataType == S7DataRowType.CHAR && par[0] == 'B')
                                            {
                                                newPar.Value =
                                                    (char)
                                                    Int32.Parse(par.Substring(5),
                                                                System.Globalization.NumberStyles.AllowHexSpecifier) +
                                                    "'";
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm + "'" +
                                                //                        (char)Int32.Parse(par.Substring(5), System.Globalization.NumberStyles.AllowHexSpecifier) + "'");
                                            }
                                            else
                                            {
                                                newPar.Value = Parameters[s];
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm + Parameters[s]);
                                            }
                                        }
                                        else
                                        {
                                            if (akRow.DataType == S7DataRowType.BOOL)
                                            {
                                                newPar.Value = s.Substring(2).Replace('V', 'L');
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm + s.Substring(2).Replace('V', 'L'));
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_DB)
                                            {
                                                newPar.Value = "DB" + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm + "DB" + ak_address.ToString());
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_FB)
                                            {
                                                newPar.Value = "FB" + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm + "FB" + ak_address.ToString());
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_FC)
                                            {
                                                newPar.Value = "FC" + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                            }
                                            else if (akRow.DataType == S7DataRowType.BLOCK_SDB)
                                            {
                                                newPar.Value = "SDB" + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                            }
                                            else if (akRow.DataType == S7DataRowType.TIMER)
                                            {
                                                newPar.Value = Mnemonic.adT[(int)myOpt.Mnemonic] + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                            }
                                            else if (akRow.DataType == S7DataRowType.COUNTER)
                                            {
                                                newPar.Value = Mnemonic.adZ[(int)myOpt.Mnemonic] + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                            }
                                            else
                                            {
                                                string ber = "";
                                                if (s.Substring(0, 5) == "P#DBX")
                                                    ber = "DB";
                                                else if (s.Substring(0, 5) == "P#DIX")
                                                    ber = "DI";
                                                else
                                                    ber = s.Substring(2, 1);

                                                if (akRow.ByteLength == 1)
                                                    ber += "B";
                                                else if (akRow.ByteLength == 2)
                                                    ber += "W";
                                                else if (akRow.ByteLength == 4)
                                                    ber += "D";

                                                newPar.Value = ber.Replace('V', 'L') + ak_address.ToString();
                                                newRow.CallParameter.Add(newPar);
                                                //newRow.ExtParameter.Add(parnm +
                                                //                        ber.Replace('V', 'L') +
                                                //                        ak_address.ToString());

                                            }

                                        }
                                    }
                                }
                            }

                            newRow.CombinedCommands = tempList;
                            newRow.Label = label;

                            int sz = 0;
                            foreach (var functionBlockRow in newRow.CombinedCommands)
                            {
                                sz += ((S7FunctionBlockRow) functionBlockRow).ByteSize;
                            }
                            byte[] mcges=new byte[sz];
                            sz = 0;
                            foreach (var functionBlockRow in newRow.CombinedCommands)
                            {
                                Array.Copy(((S7FunctionBlockRow) functionBlockRow).MC7, 0, mcges, sz, ((S7FunctionBlockRow) functionBlockRow).ByteSize);
                                sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize;
                            }
                            newRow.MC7 = mcges;

                            retVal.Add(newRow);
                            Parameters.Clear();
                            tempList = new List<FunctionBlockRow>();
                            inBld = 0;
                        }
                        else
                        {
                            retVal.AddRange(tempList);
                            tempList.Clear();

                            inBld = 0;
                        }
                    }
                    else
                    {
                        retVal.Add(row);
                    }

                }
                myFct.AWLCode = retVal;
            }
        }
        static public byte[] GetMC7(S7FunctionBlockRow myCmd)
        {
            int MN=0; //Memnoic still needs to be implemented!


            if (myCmd.Command == "NETWORK")
                return null;
            else if (myCmd.Command == Mnemonic.opTAK[MN])
                return new byte[] { 0x70, 0x02 };
            else if (myCmd.Command == Mnemonic.opPUSH[MN])
                return new byte[] { 0x68, 0x2E };
            else if (myCmd.Command == Mnemonic.opPOP[MN])
                return new byte[] { 0x68, 0x3E };
            else if (myCmd.Command == Mnemonic.opENT[MN])
                return new byte[] { 0x60, 0x08 };
            else if (myCmd.Command == Mnemonic.opLEAVE[MN])
                return new byte[] { 0x68, 0x4E };
            else if (myCmd.Command == Mnemonic.opPAR1[MN])
                return new byte[] { 0xFE, 0x06 };
            else if (myCmd.Command == Mnemonic.opPAR2[MN])
                return new byte[] { 0xFE, 0x0E };
            else if (myCmd.Command == Mnemonic.opNOP[MN])
                if (myCmd.Parameter == "0")
                    return new byte[] { 0x00, 0x00 };
                else
                    return new byte[] { 0xFF, 0xFF };
            else if (myCmd.Command == Mnemonic.opINC[MN])
                return new byte[] { 0x11, Convert.ToByte(myCmd.Parameter) };
            else if (myCmd.Command == Mnemonic.opBLD[MN])
                return new byte[] { 0x10, Convert.ToByte(myCmd.Parameter) };
            else if (myCmd.Command == Mnemonic.opDEC[MN])
                return new byte[] { 0x19, Convert.ToByte(myCmd.Parameter) };
            else if (myCmd.Command == "+D")
                return new byte[] { 0x60, 0x0D };
            else if (myCmd.Command == "-D")
                return new byte[] { 0x60, 0x09 };
            else if (myCmd.Command == "*D")
                return new byte[] { 0x60, 0x0A };
            else if (myCmd.Command == "/D")
                return new byte[] { 0x60, 0x0E };
            else if (myCmd.Command == Mnemonic.opMOD[MN])
                return new byte[] { 0x60, 0x01 };
            else if (myCmd.Command == "+I")
                return new byte[] { 0x79, 0x05 };
            else if (myCmd.Command == "-I")
                return new byte[] { 0x59, 0x05 };
            else if (myCmd.Command == "*I")
                return new byte[] { 0x60, 0x04 };
            else if (myCmd.Command == "/I")
                return new byte[] { 0x60, 0x00 };
            else if (myCmd.Command == Mnemonic.opSQR[MN])
                return new byte[] { 0x60, 0x1C };
            else if (myCmd.Command == Mnemonic.opSQRT[MN])
                return new byte[] { 0x60, 0x14 };
            else if (myCmd.Command == Mnemonic.opEXP[MN])
                return new byte[] { 0x60, 0x1B };
            else if (myCmd.Command == Mnemonic.opLN[MN])
                return new byte[] { 0x60, 0x13 };
            else if (myCmd.Command == Mnemonic.opSIN[MN])
                return new byte[] { 0x60, 0x10 };
            else if (myCmd.Command == Mnemonic.opCOS[MN])
                return new byte[] { 0x60, 0x11 };
            else if (myCmd.Command == Mnemonic.opTAN[MN])
                return new byte[] { 0x60, 0x12 };
            else if (myCmd.Command == Mnemonic.opASIN[MN])
                return new byte[] { 0x60, 0x18 };
            else if (myCmd.Command == Mnemonic.opACOS[MN])
                return new byte[] { 0x60, 0x19 };
            else if (myCmd.Command == Mnemonic.opATAN[MN])
                return new byte[] { 0x60, 0x1A };
            else if (myCmd.Command == "+R")
                return new byte[] { 0x60, 0x0F };
            else if (myCmd.Command == "-R")
                return new byte[] { 0x60, 0x0B };
            else if (myCmd.Command == "*R")
                return new byte[] { 0x60, 0x07 };
            else if (myCmd.Command == "/R")
                return new byte[] { 0x60, 0x03 };
            else if (myCmd.Command == Mnemonic.opBTI[MN])
                return new byte[] { 0x68, 0x0C };
            else if (myCmd.Command == Mnemonic.opITB[MN])
                return new byte[] { 0x68, 0x08 };
            else if (myCmd.Command == Mnemonic.opBTD[MN])
                return new byte[] { 0x68, 0x08 };
            else if (myCmd.Command == Mnemonic.opITD[MN])
                return new byte[] { 0x68, 0x1E };
            else if (myCmd.Command == Mnemonic.opDTB[MN])
                return new byte[] { 0x68, 0x0A };
            else if (myCmd.Command == Mnemonic.opDTR[MN])
                return new byte[] { 0x68, 0x06 };
            else if (myCmd.Command == Mnemonic.opINVI[MN])
                return new byte[] { 0x01, 0x00 };
            else if (myCmd.Command == Mnemonic.opINVD[MN])
                return new byte[] { 0x68, 0x0D };
            else if (myCmd.Command == Mnemonic.opNEGI[MN])
                return new byte[] { 0x09, 0x00 };
            else if (myCmd.Command == Mnemonic.opNEGD[MN])
                return new byte[] { 0x68, 0x07 };
            else if (myCmd.Command == Mnemonic.opNEGR[MN])
                return new byte[] { 0x60, 0x06 };
            else if (myCmd.Command == Mnemonic.opTAW[MN])
                return new byte[] { 0x68, 0x1A };
            else if (myCmd.Command == Mnemonic.opTAD[MN])
                return new byte[] { 0x68, 0x1B };
            else if (myCmd.Command == Mnemonic.opRND[MN])
                return new byte[] { 0x68, 0x5C };
            else if (myCmd.Command == Mnemonic.opTRUNC[MN])
                return new byte[] { 0x68, 0x5F };
            else if (myCmd.Command == Mnemonic.opRNDP[MN])
                return new byte[] { 0x68, 0x5E };
            else if (myCmd.Command == Mnemonic.opRNDM[MN])
                return new byte[] { 0x68, 0x5D };
            else if (myCmd.Command == Mnemonic.opABS[MN])
                return new byte[] { 0x60, 0x02 };
            else if (myCmd.Command == Mnemonic.opBE[MN])
                return new byte[] { 0x65, 0x00 };
            else if (myCmd.Command == Mnemonic.opBEA[MN])
                return new byte[] { 0x65, 0x01 };
            else if (myCmd.Command == Mnemonic.opBEB[MN])
                return new byte[] { 0x05, 0x00 };
            else if (myCmd.Command == Mnemonic.opCLR[MN])
                return new byte[] { 0x68, 0x1C };
            else if (myCmd.Command == Mnemonic.opNOT[MN])
                return new byte[] { 0x68, 0x2D };
            else if (myCmd.Command == Mnemonic.opSET[MN])
                return new byte[] { 0x68, 0x1D };
            else if (myCmd.Command == Mnemonic.opSAVE[MN])
                return new byte[] { 0x68, 0x2C };
            else if (myCmd.Command == Mnemonic.opUO[MN])
                return new byte[] { 0xBA, 0x00 };
            else if (myCmd.Command == Mnemonic.opOO[MN])
                return new byte[] { 0xBB, 0x00 };
            else if (myCmd.Command == Mnemonic.opUNO[MN])
                return new byte[] { 0xFF, 0xF1 };
            else if (myCmd.Command == Mnemonic.opONO[MN])
                return new byte[] { 0xFF, 0xF3 };
            else if (myCmd.Command == Mnemonic.opMCRA[MN])
                return new byte[] { 0x68, 0x3a };
            else if (myCmd.Command == Mnemonic.opMCRD[MN])
                return new byte[] { 0x68, 0x3b };
            else if (myCmd.Command == Mnemonic.opMCRO[MN])
                return new byte[] { 0x68, 0x3c };
            else if (myCmd.Command == Mnemonic.opMCRC[MN])
                return new byte[] { 0x68, 0x3d };
            else if (myCmd.Command == Mnemonic.opXO[MN])
                return new byte[] { 0xFF, 0xF4 };
            else if (myCmd.Command == Mnemonic.opXNO[MN])
                return new byte[] { 0xFF, 0xF5 };
            else if (myCmd.Command == Mnemonic.opTAR[MN])
                return new byte[] { 0xFE, 0x08 };
            else if (myCmd.Command == Mnemonic.opTDB[MN])
                return new byte[] { 0xFB, 0x7C };
            else if (myCmd.Command == Mnemonic.opUC[MN])
            {
                switch (myCmd.GetParameterType())
                {
                    case PLCFunctionBlockAdressType.Direct:
                        if (myCmd.Parameter.ToUpper().Contains("FB"))
                            if (Helper.GetParameterValueInt(myCmd.Parameter) < 256)
                                return new byte[] { 0x75, Helper.GetParameterValueBytes(myCmd.Parameter)[0] };
                            else
                                return new byte[] { 0xFB, 0x72, Helper.GetParameterValueBytes(myCmd.Parameter)[1], Helper.GetParameterValueBytes(myCmd.Parameter)[0] };
                        else if (myCmd.ExtParameter == null || myCmd.ExtParameter.Count == 0)
                            if (Helper.GetParameterValueInt(myCmd.Parameter) < 256)
                                return new byte[] { 0x3D, Helper.GetParameterValueBytes(myCmd.Parameter)[0], 0x70, 0x0B, 0x00, 0x02 };
                            else
                                return new byte[] { 0xFB, 0x70, Helper.GetParameterValueBytes(myCmd.Parameter)[1], Helper.GetParameterValueBytes(myCmd.Parameter)[0], 0x70, 0x0B, 0x00, 0x02 };
                        else
                        {
                            List<byte> myAddVal = new List<byte>();
                            if (Helper.GetParameterValueInt(myCmd.Parameter) < 256)
                                myAddVal.AddRange(new byte[] { 0xFB, 0x70, 0x00, Helper.GetParameterValueBytes(myCmd.Parameter)[0], 0x70, 0x0B, 0x00 });
                            else
                                myAddVal.AddRange(new byte[] { 0xFB, 0x70, Helper.GetParameterValueBytes(myCmd.Parameter)[1], Helper.GetParameterValueBytes(myCmd.Parameter)[0], 0x70, 0x0B, 0x00 });
                            myAddVal.Add(Convert.ToByte(myCmd.ExtParameter.Count * 2 + 2));
                            foreach (string par in myCmd.ExtParameter)
                                myAddVal.AddRange(Helper.GetCallParameterByte(par));
                            return myAddVal.ToArray();
                        }
                    case PLCFunctionBlockAdressType.Indirect:
                        if (myCmd.Parameter.ToUpper().Contains("FB"))
                            return new byte[] { 0xFB, Convert.ToByte(Helper.GetIndirectBytesWord(myCmd.Parameter)[2] | 0x02), Helper.GetIndirectBytesWord(myCmd.Parameter)[1], Helper.GetIndirectBytesWord(myCmd.Parameter)[0], 0x70, 0x0B, 0x00, 0x02 };
                        else
                            return new byte[] { 0xFB, Convert.ToByte(Helper.GetIndirectBytesWord(myCmd.Parameter)[2] | 0x00), Helper.GetIndirectBytesWord(myCmd.Parameter)[1], Helper.GetIndirectBytesWord(myCmd.Parameter)[0], 0x70, 0x0B, 0x00, 0x02 };
                }
            }
            /*
        else if (myCmd.Command == Memnoic.opAUF[MN])
            switch (myCmd.GetParameterType())
            {
                case PLCFunctionBlockAdressType.
                if (myCmd.Parameter.ToUpper().Contains("FB"))
                        if (Helper.GetParameterValueInt(myCmd.Parameter) < 256)
            return new byte[] { 0xFB, 0x7C };  0x20 //auf db
                                                0xFB, 0x38 //db [mw]  48=dbw    58=diw  68=lw
                                                      0x39 //di [mw]
                                                0xfb, 0x78  //auf db >256
                                                0xfb, 0x79  //auf di >256
                                                0xfb, 0xd8  //auf db #par

             * 
             * 
                        public static string[] opU = new[] { "U", "U" };
                        public static string[] opFN = new[] { "FN", "FN" };
                        public static string[] opFP = new[] { "FP", "FP" };
                        public static string[] opO = new[] { "O", "O" };
                        public static string[] opR = new[] { "R", "R" };
                        public static string[] opS = new[] { "S", "S" };
                        public static string[] opUN = new[] { "UN", "UN" };
                        public static string[] opX = new[] { "X", "X" };
                        public static string[] opXN = new[] { "XN", "XN" };
                        public static string[] opZUW = new[] { "=", "=" }; 

             */
            /*
                 * Commands still to do:
                        public static string[] opAUF = new[] { "AUF", "OPN" };                       
                        public static string[] opCC = new[] { "CC", "CC" };
             * 
                        
             *          public static string[] opFR = new[] { "FR", "FR" };
             *          
                        public static string[] opL = new[] { "L", "L" };
                        
             *          public static string[] opLAR1 = new[] { "LAR1", "LAR1" };
                        public static string[] opLAR2 = new[] { "LAR2", "LAR2" };
                        public static string[] opLC = new[] { "LC", "LC" };
                        public static string[] opLN = new[] { "LN", "LN" };
                                               
             *          public static string[] opOD = new[] { "OD", "OD" };
                        public static string[] opON = new[] { "ON", "ON" };
                        public static string[] opOW = new[] { "OW", "OW" };
                        public static string[] opPLU = new[] { "+", "+" };
                        public static string[] opRLD = new[] { "RLD", "RLD" };
                        public static string[] opRLDA = new[] { "RLDA", "RLDA" };
                        public static string[] opRRD = new[] { "RRD", "RRD" };
                        public static string[] opRRDA = new[] { "RRDA", "RRDA" };
                        public static string[] opSA = new[] { "SA", "SF" };
                        public static string[] opSE = new[] { "SE", "SD" };
                        public static string[] opSI = new[] { "SI", "SP" };
                        public static string[] opSLD = new[] { "SLD", "SLD" };
                        public static string[] opSLW = new[] { "SLW", "SLW" };
                      
             *        * public static string[] opLOOP = new[] { "LOOP", "LOOP" };
                        public static string[] opSPA = new[] { "SPA", "JU" };
                        public static string[] opSPB = new[] { "SPB", "JC" };
                        public static string[] opSPBB = new[] { "SPBB", "JCB" };
                        public static string[] opSPBI = new[] { "SPBI", "JBI" };
                        public static string[] opSPBIN = new[] { "SPBIN", "JBNI" };
                        public static string[] opSPBN = new[] { "SPBN", "JCN" };
                        public static string[] opSPBNB = new[] { "SPBNB", "JNB" };
                        public static string[] opSPL = new[] { "SPL", "SPL" };
                        public static string[] opSPM = new[] { "SPM", "SPM" };
                        public static string[] opSPMZ = new[] { "SPMZ", "SPMZ" };
                        public static string[] opSPN = new[] { "SPN", "SPN" };
                        public static string[] opSPO = new[] { "SPO", "SPO" };
                        public static string[] opSPP = new[] { "SPP", "SPP" };
                        public static string[] opSPPZ = new[] { "SPPZ", "SPPZ" };
                        public static string[] opSPS = new[] { "SPS", "SPS" };
                        public static string[] opSPU = new[] { "SPU", "SPU" };
                        public static string[] opSPZ = new[] { "SPZ", "SPZ" };

                        public static string[] opSRD = new[] { "SRD", "SRD" };
                        public static string[] opSRW = new[] { "SRW", "SRW" };
                        public static string[] opSS = new[] { "SS", "SS" };
                        public static string[] opSSD = new[] { "SSD", "SSD" };
                        public static string[] opSSI = new[] { "SSI", "SSI" };
                        public static string[] opSV = new[] { "SV", "SV" };
                        public static string[] opT = new[] { "T", "T" };
                        public static string[] opTAR1 = new[] { "TAR1", "TAR1" };
                        public static string[] opTAR2 = new[] { "TAR2", "TAR2" };
                        public static string[] opUD = new[] { "UD", "UD" };
                        public static string[] opUW = new[] { "UW", "UW" };
                        public static string[] opXOD = new[] { "XOD", "XOD" };
                        public static string[] opXOW = new[] { "XOW", "XOW" };
                        public static string[] opZR = new[] { "ZR", "ZR" };
                        public static string[] opZV = new[] { "ZV", "ZV" };
                        
                 * End of commands list
                                */



            return null;
        }
 public void ExecuteCommand(S7FunctionBlockRow row)
 {
     if (row.Command == Mnemonic.opABS[0])
     {
         Akku1.Int32 = Math.Abs(Akku1.Int32);                    
     }
     else if (row.Command == Mnemonic.opACOS[0])
     {
         Akku1.Single = (Single)Math.Acos(Akku1.Single);
     }
     else if (row.Command == Mnemonic.opL[0])
     {
         Akku1.Single = (Single)Math.Acos(Akku1.Single);
     }
     else if (row.Command == Mnemonic.opTAK[0])
     {
         var sp = Akku2;
         Akku2 = Akku1.UInt32;
         Akku1.UInt32 = sp;                
     }
 }