Пример #1
0
        private void cmdReadWithReadValues_Click(object sender, EventArgs e)
        {
            try
            {
                txtWert.Text   = "";
                txtZeit.Text   = "";
                lblStatus.Text = "";

                if (myConn == null)
                {
                    cmdConnect_Click(sender, e);
                }

                PLCTag myTag = new PLCTag(txtTag.Text);

                List <PLCTag> tagList = new List <PLCTag>()
                {
                    myTag
                };

                Stopwatch sw = new Stopwatch();
                sw.Start();
                myConn.ReadValues(tagList);
                sw.Stop();

                txtZeit.Text = sw.ElapsedMilliseconds.ToString() + " ms";
                txtWert.Text = myTag.ValueAsString;
            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.Message;
            }
        }
Пример #2
0
        private void cmdConnect_Click(object sender, RoutedEventArgs e)
        {
            cmdConnect.IsEnabled = false;
            cmdStop.IsEnabled    = true;

            //Alle Tags in eine Liste packen
            List <PLCTag> Tags = new List <PLCTag>();

            foreach (DictionaryEntry dictionaryEntry in this.Resources)
            {
                if (dictionaryEntry.Value is PLCTag)
                {
                    Tags.Add((PLCTag)dictionaryEntry.Value);
                }
            }

            try
            {
                //Verbindungskonfig laden und Verbinden
                myConn = new PLCConnection("ExampleWPFVisualization");
                myConn.Connect();
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
            //Tags im Hintergrund laden
            if (worker != null)
            {
                worker.Dispose();
            }



            //Uncomment this line, to use the VarTab Functions for Read
            //PLCConnection.VarTabData vtab = myConn.ReadValuesWithVarTabFunctions(Tags, PLCReadTriggerVarTab.EndOfCycle);

            worker = new BackgroundWorker();
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                while (!worker.CancellationPending)
                {
                    try
                    {
                        myConn.ReadValues(Tags);
                        //Uncomment this line, to use the Vartab Functions for read, and comment the line above!
                        //vtab.RequestData();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            };

            worker.RunWorkerAsync();
        }
        private void cmdConnect_Click(object sender, RoutedEventArgs e)
        {
            cmdConnect.IsEnabled = false;
            cmdStop.IsEnabled = true;

            //Alle Tags in eine Liste packen
            List<PLCTag> Tags = new List<PLCTag>();
            foreach (DictionaryEntry dictionaryEntry in this.Resources)
            {
                if (dictionaryEntry.Value is PLCTag)
                    Tags.Add((PLCTag) dictionaryEntry.Value);
            }

            try
            {
                //Verbindungskonfig laden und Verbinden
                myConn = new PLCConnection("ExampleWPFVisualization");
                myConn.Connect();
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
            //Tags im Hintergrund laden
            if (worker != null)
            {
                worker.Dispose();
            }


            
            //Uncomment this line, to use the VarTab Functions for Read
            //PLCConnection.VarTabData vtab = myConn.ReadValuesWithVarTabFunctions(Tags, PLCReadTriggerVarTab.EndOfCycle);

            worker = new BackgroundWorker();
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
                                 {
                                     while (!worker.CancellationPending)
                                     {
                                         try
                                         {
                                             myConn.ReadValues(Tags);
                                             //Uncomment this line, to use the Vartab Functions for read, and comment the line above!
                                             //vtab.RequestData();                                             
                                         }
                                         catch (Exception ex)
                                         {
                                         }
                                     }
                                 };

            worker.RunWorkerAsync();
        }
Пример #4
0
        public List <ToolData> GetToolList()
        {
            //toolData = new List<ToolData>();
            bool error = false;


            Stopwatch sw = new Stopwatch();

            sw.Start();
            if (myConn == null)
            {
                DoConnect();
            }
            // Meherere Datenbausteine müssen eingelesen werden

            /////////////////////////////////////////////////////
            // Beginn mit Datenbaustein TP (MagazinPlatzdaten):



            List <ToolData> toolData = new List <ToolData>();

            PLCNckTag tag = new PLCNckTag();

            // Anzahl der Werkzeuge
            tag.NckArea   = NCK_Area.AreaTool;
            tag.NckModule = (int)NCK_Block.BlockTV;

            tag.NckLinecount = 1;
            tag.NckUnit      = 1;

            tag.NckLine     = 1;
            tag.NckColumn   = 1;
            tag.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;


            myConn.ReadValue(tag);
            ushort numberOfTools = 0;
            object o             = new object();

            numberOfTools = (UInt16)tag.Value;


            List <PLCNckTag> tagList = new List <PLCNckTag>();

            int line = 1;

            for (int i = 0; i < numberOfTools; i++)
            {
                try
                {
                    //---------------------  InternalNumber Tno   -------------------------------
                    PLCNckTag internalToolNumber = new PLCNckTag();
                    internalToolNumber.NckArea   = NCK_Area.AreaTool;
                    internalToolNumber.NckModule = (int)NCK_Block.BlockTV;

                    internalToolNumber.NckLinecount = 1;
                    internalToolNumber.NckUnit      = 1;

                    internalToolNumber.NckLine     = line;
                    internalToolNumber.NckColumn   = (int)NCK_BlockTVColumn.TNo;
                    internalToolNumber.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;
                    internalToolNumber.Tag         = "InternalToolNumber";
                    tagList.Add(internalToolNumber);


                    //---------------------  IdentNumber  -------------------------------

                    PLCNckTag identNumber = new PLCNckTag();
                    identNumber.NckArea   = NCK_Area.AreaTool;
                    identNumber.NckModule = (int)NCK_Block.BlockTV;

                    identNumber.NckLinecount = 1;
                    identNumber.NckUnit      = 1;

                    identNumber.NckLine   = line;
                    identNumber.NckColumn = (int)NCK_BlockTVColumn.Identnumber;

                    identNumber.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.CharArray;
                    identNumber.ArraySize   = 32;
                    identNumber.Tag         = "ToolIdentNumber";
                    tagList.Add(identNumber);
                    //---------------------  Duplo  -------------------------------
                    PLCNckTag duploNumber = new PLCNckTag();
                    duploNumber.NckArea   = NCK_Area.AreaTool;
                    duploNumber.NckModule = (int)NCK_Block.BlockTV;

                    duploNumber.NckLinecount = 1;
                    duploNumber.NckUnit      = 1;

                    duploNumber.NckLine     = line;
                    duploNumber.NckColumn   = (int)NCK_BlockTVColumn.Duplo;
                    duploNumber.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;
                    duploNumber.Tag         = "Duplo";
                    tagList.Add(duploNumber);

                    //---------------------  Edges  -------------------------------

                    PLCNckTag edges = new PLCNckTag();
                    edges.NckArea   = NCK_Area.AreaTool;
                    edges.NckModule = (int)NCK_Block.BlockTV;

                    edges.NckLinecount = 1;
                    edges.NckUnit      = 1;

                    edges.NckLine     = line;
                    edges.NckColumn   = (int)NCK_BlockTVColumn.Edges;
                    edges.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;
                    edges.Tag         = "Edges";
                    tagList.Add(edges);


                    //---------------------  Depot  -------------------------------

                    PLCNckTag depot = new PLCNckTag();
                    depot.NckArea   = NCK_Area.AreaTool;
                    depot.NckModule = (int)NCK_Block.BlockTV;

                    depot.NckLinecount = 1;
                    depot.NckUnit      = 1;

                    depot.NckLine     = line;
                    depot.NckColumn   = (int)NCK_BlockTVColumn.Depot;
                    depot.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;
                    depot.Tag         = "Depot";
                    tagList.Add(depot);



                    //---------------------  Place  -------------------------------
                    PLCNckTag place = new PLCNckTag();
                    place.NckArea   = NCK_Area.AreaTool;
                    place.NckModule = (int)NCK_Block.BlockTV;

                    place.NckLinecount = 1;
                    place.NckUnit      = 1;

                    place.NckLine     = line;
                    place.NckColumn   = (int)NCK_BlockTVColumn.Place;
                    place.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;
                    place.Tag         = "Place";
                    tagList.Add(place);



                    ++line;
                }
                catch (Exception ex)
                {
                }
            }

            //PLCNckTag p = new PLCNckTag();
            //p.NckArea = (int)NCK_Area.AreaTool;
            //p.NckModule = (int)NCK_Block.BlockTV;

            //p.NckLinecount = 1;
            //p.NckUnit = 1;

            //p.NckLine = 1;
            //p.NckColumn = (int)NCK_BlockTVColumn.Place;
            //p.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.Word;
            //p.Tag = "Place";
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);
            //tagList.Add(p);

            myConn.ReadValues(tagList);


            foreach (var nckTag in tagList)
            {
                if (nckTag.Tag != null)
                {
                    ToolData td = toolData.Where(w => w.Id == nckTag.NckLine).FirstOrDefault();
                    if (td == null)
                    {
                        td    = new ToolData();
                        td.Id = nckTag.NckLine;
                        toolData.Add(td);
                    }

                    PropertyInfo prop = typeof(ToolData).GetProperty(nckTag.Tag.ToString(), BindingFlags.Public | BindingFlags.Instance);
                    if (null != prop && prop.CanWrite)
                    {
                        try
                        {
                            prop.SetValue(td, Convert.ChangeType(nckTag.Value, prop.PropertyType), null);
                        }catch {}
                    }
                }
            }
            tagList = new List <PLCNckTag>();
            foreach (var td in toolData)
            {
                /////////////////////////////////////////////////////////
                ////// Beginn mit Datenbaustein TS (Schneidedaten, Korrekturdaten):

                //    //P1 = Vorwarngrenze Standzeit in Minuten ($TC_MOP1)
                //    //P2 = Verbleibende Standzeit in Minuten ($TC_MOP2)
                //    //P3 = Vorwarngrenze Stückzahl ($TC_MOP3)
                //    //P4 = verbleibende Stückzahl ($TC_MOP4)
                //    //P5 = Sollstandzeit ($TC_MOP11)
                //    //P6 = Sollstückzahl ($TC_MOP13)
                //    //P7 = Vorwarngrenze Verschleiß (Vorwarngrenze) (ab SW 5.1) ($TC_MOP5)
                //    //    Dieser Parameter kann nur gesetzt werden, wenn Bit 5 von Maschinendatum     $MN_MM_TOOL_MANAGEMENT_MASK entsprechend gesetzt ist.
                //    //P8 = verbleibender Verschleiß (Istwert) (ab SW 5.1) ($TC_MOP6) nicht schreibbar
                //    //P9 = Sollwert Verschleiß (ab SW 5.1) ($TC_MOP15)
                //    //    Dieser Parameter kann nur gesetzt werden, wenn Bit 5 von Maschinendatum
                //    //    $MN_MM_TOOL_MANAGEMENT_MASK entsprechend gesetzt ist.
                PLCNckTag restdurabillity = new PLCNckTag();
                restdurabillity.NckArea   = NCK_Area.AreaTool;
                restdurabillity.NckModule = (int)NCK_Block.BlockTS;

                restdurabillity.NckLinecount = 1;
                restdurabillity.NckUnit      = 1;

                restdurabillity.NckLine     = (int)NCK_BlockTSLine.Resdurabillity;
                restdurabillity.NckColumn   = int.Parse(td.InternalToolNumber);
                restdurabillity.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.LReal;
                restdurabillity.Tag         = "RestDurability";
                tagList.Add(restdurabillity);

                PLCNckTag setTime = new PLCNckTag();
                setTime.NckArea   = NCK_Area.AreaTool;
                setTime.NckModule = (int)NCK_Block.BlockTS;

                setTime.NckLinecount = 1;
                setTime.NckUnit      = 1;

                setTime.NckLine     = (int)NCK_BlockTSLine.SetTime;
                setTime.NckColumn   = int.Parse(td.InternalToolNumber);
                setTime.TagDataType = DotNetSiemensPLCToolBoxLibrary.DataTypes.TagDataType.LReal;
                setTime.Tag         = "MaxTime";
                tagList.Add(setTime);
            }


            myConn.ReadValues(tagList);

            foreach (var nckTag in tagList)
            {
                if (nckTag.Tag != null)
                {
                    ToolData td = toolData.Where(w => w.InternalToolNumber == nckTag.NckColumn.ToString()).FirstOrDefault();
                    if (td != null)
                    {
                        PropertyInfo prop = typeof(ToolData).GetProperty(nckTag.Tag.ToString(), BindingFlags.Public | BindingFlags.Instance);
                        if (null != prop && prop.CanWrite)
                        {
                            try
                            {
                                if (prop.PropertyType == typeof(TimeSpan))
                                {
                                    TimeSpan ts = TimeSpan.FromSeconds(double.Parse(nckTag.Value.ToString()));
                                    prop.SetValue(td, ts, null);
                                }
                                else
                                {
                                    prop.SetValue(td, Convert.ChangeType(nckTag.Value, prop.PropertyType), null);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }

            if (error)
            {
                Console.WriteLine("Error GetTools in Aglink happened");
            }


            sw.Stop();

            lblStatus.Text = sw.ElapsedMilliseconds.ToString() + " ms";
            if (toolData != null)
            {
                dataGridView1.DataSource = toolData;
            }
            return(toolData);
        }