CALLs aus AWL Code erzeugen...

Jochen Kühner

Level-3
Beiträge
4.448
Reaktionspunkte
677
Zuviel Werbung?
-> Hier kostenlos registrieren
Suche nach einer Strategie um aus dem AWL Code der Parameterzuweisungen CALL Anweisungen zu erstellen! Hat da jemand eine gute Idee, hab zwar in Grundzügen schon mal Angefangen, bin aber noch auf keinem grünen Zweig...


Hab mal meinen momentanen Code angehängt, der aber noch lange nicht fertig ist...
Code:
using System;
using System.Collections.Generic;
using System.Text;
using LibNoDaveConnectionLibrary.DataTypes.Blocks;
using LibNoDaveConnectionLibrary.DataTypes.Step7Project;

namespace LibNoDaveConnectionLibrary.MC7
{
    static class CallConverter
    {
        //In this Class a UC is converted to a Call and also backwards...
        public static void ConvertUCToCall(PLCFunctionBlock myFct, S7ProgrammFolder myFld, MC7ConvertingOptions myOpt, byte[] addInfoFromBlock)
        {
            if (myOpt.GenerateCallsfromUCs)
            {
                int inBld = 0; //1=nach BLD 1
                PLCFunctionBlockRow newRow = null;

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



                string akPar = "";

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

                        Parameters.Clear();
                        inBld = 1;
                        newRow = null;
                        tempList.Add(row);
                    }
                    else if (inBld == 1)
                    {
                        tempList.Add(row);
                        if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Memnoic.opBLD[myOpt.Memnoic])
                        {
                            //Do nothing, but this line needs to be there!
                        }
                        else if (row.Command == Memnoic.opU[myOpt.Memnoic] || row.Command == Memnoic.opUN[myOpt.Memnoic] ||
                                 row.Command == Memnoic.opO[myOpt.Memnoic] || row.Command == Memnoic.opON[myOpt.Memnoic] ||
                                 row.Command == Memnoic.opO[myOpt.Memnoic] || row.Command == Memnoic.opON[myOpt.Memnoic] ||
                                 row.Command == Memnoic.opX[myOpt.Memnoic] || row.Command == Memnoic.opXN[myOpt.Memnoic] ||
                                 row.Command == Memnoic.opL[myOpt.Memnoic])
                        {
                            akPar = row.Parameter;
                        }
                        else if ((row.Command == "=" || row.Command == Memnoic.opT[myOpt.Memnoic]) && akPar != "")
                        {
                            Parameters.Add("P#V " + (row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", "")), akPar);
                            akPar = "";
                        }
                        else if (row.Command == Memnoic.opUC[myOpt.Memnoic] && newRow == null)
                        {
                            //Block Interface auslesen (von FC oder vom Programm)
                            //myFld.BlocksOfflineFolder.GetBlock()
                            newRow = new PLCFunctionBlockRow();
                            newRow.Command = Memnoic.opCALL[myOpt.Memnoic];
                            newRow.Parameter = row.Parameter;
                            newRow.ExtParameter = new List<string>();
                            for (int i = 0; i < row.ExtParameter.Count; i++)
                            {
                                string s = row.ExtParameter[i];
                                if (Parameters.ContainsKey(s))
                                    newRow.ExtParameter.Add(Parameters[s]);
                                else
                                    newRow.ExtParameter.Add(s);
                            }

                        }
                        else if (row.Command == Memnoic.opBLD[myOpt.Memnoic] && row.Parameter == "2" && newRow != null)
                        {
                            newRow.CombinedCommands = tempList;
                            retVal.Add(newRow);
                            Parameters.Clear();
                            tempList = new List<PLCFunctionBlockRow>();
                            //Do nothing, but this line needs to be there!
                        }
                        else
                        {
                            retVal.AddRange(tempList);
                            tempList.Clear();
                            inBld = 0;
                        }
                    }
                    else
                    {
                        retVal.Add(row);
                    }

                }
                myFct.AWLCode = retVal;
            }            
        }
    }
}
 
Also falls es jemand intressiert, Ich hab das für FC-Calls in FCs mal realisiert, finde es aber ziemlich umständlich wie Ich das im Moment mache, also falls dazu noch jemand eine Idee hat, nur her damit! (falls es jemand anschauen will der Code ist hier : http://siemensplctoolboxlib.codeplex.com/SourceControl/changeset/view/72784# dann auf libnodaveconnectionlib/plc/s7xxx/mc7/callconverter.cs klicken) ( gut, ok, der code mag im moment nicht so toll sein aber er geht!)

Jetzt will Ich das ganze noch für FBs machen, aber das wird ja noch komplexer, da wird ja im aufruf auch noch TDB ab und an verwendet! Also bin immer noch auf der suche nach einer Idee das einfacher zu lösen...
 
Zurück
Oben