Пример #1
0
        private void CreateClassFileFromChannels(WagoBK.Channels MyChannels, string ProjectName, Stream OutputFile)
        {
            if (OutputFile == null)
            {
                throw new Exception("output file is null");
            }
            if (MyChannels == null)
            {
                throw new Exception("Channel-Obj is null");
            }
            int[]       Slots     = MyChannels.ProjectCards.GetSlotNumbers();
            FileCreator BKFileOut = new FileCreator(OutputFile);

            BKFileOut.WriteLine("using System;");
            BKFileOut.WriteLine("using System.Collections.Generic;");
            BKFileOut.WriteLine("using System.Text;");
            BKFileOut.WriteLine("using WagoBK;");

            BKFileOut.WriteLine("namespace " + ProjectName);
            BKFileOut.WriteLine("{");
            BKFileOut.WriteLine("public class " + ProjectName + "BK : WagoBKBase");
            BKFileOut.WriteLine("{");
            BKFileOut.WriteLine("public " + ProjectName + "BK(): base() {}");
            BKFileOut.WriteLine("protected override Channels CreateChannels()");
            BKFileOut.WriteLine("{ return new " + ProjectName + "Channels(); }");
            BKFileOut.WriteLine("public override void CheckInterlock(){}");
            BKFileOut.WriteLine("public new " + ProjectName + "Channels Ch()");
            BKFileOut.WriteLine("{ return (" + ProjectName + "Channels)base.Ch(); }");
            BKFileOut.WriteLine("");
            BKFileOut.WriteLine("public class " + ProjectName + "Channels : Channels");
            BKFileOut.WriteLine("{");
            BKFileOut.WriteLine("public " + ProjectName + "Channels() : base()");
            BKFileOut.WriteLine("{ }");
            BKFileOut.WriteLine("protected override void InitChannelList()");
            BKFileOut.WriteLine("{");

            //initialise and add Cards
            BKFileOut.WriteLine("int Slot = 0;");
            foreach (int Slot in Slots)
            {
                BKFileOut.WriteLine(" m_" + MyChannels.ProjectCards.GetCard(Slot).GetType().Name + "_" + Slot.ToString() +
                                    " = new " + MyChannels.ProjectCards.GetCard(Slot).GetType().Name + "();");
                BKFileOut.WriteLine("ProjectCards.AddCard(Slot++, " + MyChannels.ProjectCards.GetCard(Slot).GetType().Name + "_" + Slot.ToString() +
                                    ");");
            }

            // define Channel-List
            foreach (string Name in MyChannels.DIChannels.Keys)
            {
                BKFileOut.WriteLine("DIChannels.Add(\"" + Name + "\", new DIChannelDef(\"" +
                                    MyChannels.DIChannels[Name].GetName() + "\",\"" +
                                    MyChannels.DIChannels[Name].GetBMK() + "\"," +
                                    " m_" + MyChannels.DIChannels[Name].GetCard().GetType().Name +
                                    "_" + MyChannels.ProjectCards.GetCardSlot(MyChannels.DIChannels[Name].GetCard()).ToString() + "," +
                                    MyChannels.DIChannels[Name].GetChannel().ToString() + "));");
            }
            BKFileOut.WriteLine("");
            foreach (string Name in MyChannels.DOChannels.Keys)
            {
                BKFileOut.WriteLine("DOChannels.Add(\"" + Name + "\", new DOChannelDef(\"" +
                                    MyChannels.DOChannels[Name].GetName() + "\",\"" +
                                    MyChannels.DOChannels[Name].GetBMK() + "\"," +
                                    " m_" + MyChannels.DOChannels[Name].GetCard().GetType().Name +
                                    "_" + MyChannels.ProjectCards.GetCardSlot(MyChannels.DOChannels[Name].GetCard()).ToString() + "," +
                                    MyChannels.DOChannels[Name].GetChannel().ToString() + "));");
            }
            BKFileOut.WriteLine("");
            foreach (string Name in MyChannels.AIChannels.Keys)
            {
                BKFileOut.WriteLine("AIChannels.Add(\"" + Name + "\", new AIChannelDef(\"" +
                                    MyChannels.AIChannels[Name].GetName() + "\",\"" +
                                    MyChannels.AIChannels[Name].GetBMK() + "\"," +
                                    " m_" + MyChannels.AIChannels[Name].GetCard().GetType().Name +
                                    "_" + MyChannels.ProjectCards.GetCardSlot(MyChannels.AIChannels[Name].GetCard()).ToString() + "," +
                                    MyChannels.AIChannels[Name].GetChannel().ToString() + "));");
            }
            BKFileOut.WriteLine("");
            foreach (string Name in MyChannels.AOChannels.Keys)
            {
                BKFileOut.WriteLine("AOChannels.Add(\"" + Name + "\", new AOChannelDef(\"" +
                                    MyChannels.AOChannels[Name].GetName() + "\",\"" +
                                    MyChannels.AOChannels[Name].GetBMK() + "\"," +
                                    " m_" + MyChannels.AOChannels[Name].GetCard().GetType().Name +
                                    "_" + MyChannels.ProjectCards.GetCardSlot(MyChannels.AOChannels[Name].GetCard()).ToString() + "," +
                                    MyChannels.AOChannels[Name].GetChannel().ToString() + "));");
            }
            BKFileOut.WriteLine("}");
            //add property for each Channel
            foreach (string Name in MyChannels.DOChannels.Keys)
            {
                BKFileOut.WriteLine("public bool DO_" + Name);
                BKFileOut.WriteLine("{");
                BKFileOut.WriteLine("get { return DOChannels[\"" + Name + "\"].Get(); }");
                BKFileOut.WriteLine("set { DOChannels[\"" + Name + "\"].Set(value); }");
                BKFileOut.WriteLine("}");
            }
            BKFileOut.WriteLine("");
            foreach (string Name in MyChannels.DIChannels.Keys)
            {
                BKFileOut.WriteLine("public bool DI_" + Name);
                BKFileOut.WriteLine("{");
                BKFileOut.WriteLine("get { return DIChannels[\"" + Name + "\"].Get(); }");
                BKFileOut.WriteLine("}");
            }
            BKFileOut.WriteLine("");
            foreach (string Name in MyChannels.AIChannels.Keys)
            {
                BKFileOut.WriteLine("public double AI_" + Name);
                BKFileOut.WriteLine("{");
                BKFileOut.WriteLine("get { return AIChannels[\"" + Name + "\"].Get(); }");
                BKFileOut.WriteLine("}");
            }
            BKFileOut.WriteLine("");
            foreach (string Name in MyChannels.AOChannels.Keys)
            {
                BKFileOut.WriteLine("public double AO_" + Name);
                BKFileOut.WriteLine("{");
                BKFileOut.WriteLine("get { return AOChannels[\"" + Name + "\"].Get(); }");
                BKFileOut.WriteLine("set { AOChannels[\"" + Name + "\"].Set(value); }");
                BKFileOut.WriteLine("}");
            }
            //carddefinition
            foreach (int Slot in Slots)
            {
                BKFileOut.WriteLine("private " + MyChannels.ProjectCards.GetCard(Slot).GetType().Name +
                                    " m_" + MyChannels.ProjectCards.GetCard(Slot).GetType().Name + "_" + Slot.ToString() +
                                    ";");
                BKFileOut.WriteLine("public " + MyChannels.ProjectCards.GetCard(Slot).GetType().Name +
                                    " " + MyChannels.ProjectCards.GetCard(Slot).GetType().Name + "_" + Slot.ToString());
                BKFileOut.WriteLine("{");
                BKFileOut.WriteLine("get { return m_" + MyChannels.ProjectCards.GetCard(Slot).GetType().Name + "_" + Slot.ToString() + "; }");
                BKFileOut.WriteLine("}");
            }

            BKFileOut.WriteLine("}");
            BKFileOut.WriteLine("}");
            BKFileOut.WriteLine("}");

            BKFileOut.CloseFile();
        }