Exemple #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         string ProjectName = textBox3.Text;
         if (ProjectName == "")
         {
             throw new Exception("invalid ProjectPrefix");
         }
         LogStatus("Preparing creation for " + ProjectName);
         //openFileDialog1.Filter = "csv|(*.csv)";
         if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {   //parse the fíle
             Stream InputFile = openFileDialog1.OpenFile();
             LogStatus("Reading file...");
             string          OutputFileName = Path.GetDirectoryName(openFileDialog1.FileName) + "\\" + ProjectName + "BK.cs";
             WagoBK.Channels MyChannels     = CreateChannelsFromFile(InputFile);
             LogStatus("Creating file " + OutputFileName);
             FileStream ClassFile = System.IO.File.Create(OutputFileName);
             CreateClassFileFromChannels(MyChannels, ProjectName, ClassFile);
             LogStatus("Creation completed for " + ProjectName);
         }
         else
         {
             LogStatus("Creation canceled by user");
         }
     }
     catch (Exception ex)
     {
         LogStatus(ex.Message);
     }
 }
Exemple #2
0
 public BKSim(WagoBK.Channels ChannelDef)
 {
     InitializeComponent();
     txtIP.Text       = "192.168.2.24";
     txtPort.Text     = "51557";
     btListen.Checked = true;
     CountInstances++;
     btConnect_Click(null, new EventArgs());
     timer1.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
     //m_Channels = new Demo.DemoBK.DemoChannels();
     m_Channels = ChannelDef;
     CreateChannelCtrls(m_Channels);
     //timer1.Stop(); //f*****g timer doesnt work if enabled at start??
 }
Exemple #3
0
        protected void CreateChannelCtrls(WagoBK.Channels ChList)
        {
            //delete existing controls
            this.DInputs.Controls.Clear();
            this.DOutputs.Controls.Clear();

            //create new controls
            foreach (string Name in ChList.DIChannels.Keys)
            {
                WagoBK.ChannelDI channel = new WagoBK.ChannelDI(ChList.DIChannels[Name]);
                this.DInputs.Controls.Add(channel);
            }
            foreach (string Name in ChList.DOChannels.Keys)
            {
                WagoBK.ChannelDO channel = new WagoBK.ChannelDO(ChList.DOChannels[Name]);
                this.DOutputs.Controls.Add(channel);
            }
        }
 public BKIn(Channels List)
 {
     m_Channels = List;     //use copy constructor??
 }
 public BKIn()
 {
     m_Channels = new Channels();
 }
 public BKOut()
 {
     m_Channels = new Channels();
 }
Exemple #7
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();
        }