Exemple #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (MainApp.GetDoc().ActiveMdiChild is TcApplication.FormMView &&
                adsPlcServer != null &&
                adsPlcServer.PlcIsRunning)
            {
                TwinCAT.Ads.AdsStream adsStream = new TwinCAT.Ads.AdsStream(500);
                BinaryReader          binRead   = new BinaryReader(adsStream);
                int res;

                try
                {
                    for (int i = 0; i < numberOfViews; i++)
                    {
                        adsStream.Position = 0;
                        res = adsPlcServer.PlcClient.Read(".MViewStatus[" + (i + 1) + "].Color", ref adsStream);
                        for (int field = 0; field < MViewBox[i].Fields; field++)
                        {
                            MViewBox[i].ValueBackColor(field, GetColor(binRead.ReadInt16()));
                        }

                        adsStream.Position = 0;
                        res = adsPlcServer.PlcClient.Read(".MViewStatus[" + (i + 1) + "].Description", ref adsStream);
                        for (int field = 0; field < MViewBox[i].Fields; field++)
                        {
                            MViewBox[i].Value(field, new string(binRead.ReadChars(31)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    MainApp.log.Error("Error in FormMView timer1_Tick()", ex);
                }
            }
        }
Exemple #2
0
        public override void FKeyUpEvent(int nIdx)
        {
            switch (nIdx)
            {
            case 1:
                break;

            case 4:
                tcRecipe1.InsertRow();
                MainApp.GetDoc().tcFKey1.FKeyBackColor(10, Color.DarkGray);
                hasChanged = true;
                break;

            case 5:
                tcRecipe1.DeleteRow();
                MainApp.GetDoc().tcFKey1.FKeyBackColor(10, Color.DarkGray);
                hasChanged = true;
                break;

            case 7:                        // Recipe löschen
                if (textBoxAuftrag.Text != "")
                {
                    if (askDeleteRecipe(textBoxAuftrag.Text))
                    {
                        System.IO.File.Delete(rootdir + "\\" + textBoxAuftrag.Text + ending);
                        if (treeView2.SelectedNode != null)
                        {
                            treeView2.Nodes.Remove(treeView2.SelectedNode);
                        }
                        // ein anderes Element selektieren
                        if (treeView2.Nodes.Count != 0)
                        {
                            treeView2.SelectedNode = treeView2.Nodes[0];
                        }
                        else
                        {
                            textBoxAuftrag.Text = "";
                            recipeFilename      = "";
                        }
                    }
                }
                break;

            case 8:
                InputBox box = new InputBox(GetText("New", "Neu anlegen"), GetText("FileName", "Dateiname:"));
                box.ShowDialog();
                if (box.DialogResult == DialogResult.OK && !box.GetInput().Equals(""))
                {
                    string fileName = box.GetInput();
                    recipeFilename = rootdir + "\\" + fileName + ending;
                    tcRecipe1.NewFile(recipeFilename);
                    tcRecipe1.WriteData();
                    treeView2.Nodes.Add(fileName, fileName);
                    textBoxAuftrag.Text = fileName;
                }
                break;

            case 9:
                tcRecipe1.ReadData();
                break;

            case 10:
                tcRecipe1.WriteData();
                MainApp.GetDoc().tcFKey1.FKeyBackColor(10, oldButtonColor);
                hasChanged = false;
                break;

            case 11:
                try
                {
                    // Get recipe data and write to the Plc
                    System.IO.MemoryStream memStream;
                    tcRecipe1.WriteDataToMemory(out memStream);
                    TwinCAT.Ads.AdsStream adsStream = new TwinCAT.Ads.AdsStream((int)memStream.Capacity);
                    adsStream.Write(memStream.GetBuffer(), 0, (int)memStream.Length);
                    adsServer.PlcClient.Write(".RecipeData", adsStream);
                    memStream = null;
                }
                catch (Exception ex)
                {
                    string tmp = this.Name + " Error writing recipe data to the PLC!";
                    MainApp.log.Error(tmp, ex);
                    MessageBox.Show(tmp);
                }
                break;

            case 12:
                timerListbox.Enabled = false;
                break;
            }
        }