示例#1
0
        public override void Configure(INodeConfiguration configuration)
        {
            var c = configuration as Sinumerik840dNodeConfiguration;

            NCVar = new NC_Var();

            base.Configure(configuration);
        }
        private static void WriteNck(string ipAddress = "192.168.214.1")
        {
            using (var con = new PLCConnection("WriteNck"))
            {
                con.Configuration.CpuIP   = ipAddress;
                con.Configuration.CpuSlot = 4;
                con.Connect();

                try
                {
                    if (!con.Connected)
                    {
                        con.Connect();
                    }

                    #region Channel 1 R[0]
                    var R0 = new NC_Var(0x82, 0x41, 0x1, 0x1, 0x15, 0x1, 0xF, 0x8).GetNckTag();
                    R0.Controlvalue = 5;
                    con.WriteValue(R0);
                    #endregion

                    #region List of R-Parameter
                    var rpa     = new NC_Var(0x82, 0x40, 0x1, 0x0, 0x15, 0x1, 0xF, 0x8);
                    var tags    = new List <PLCNckTag>();
                    int channel = 1;
                    for (int i = 1; i < 10; i++)
                    {
                        tags.Add(rpa.GetNckTag(channel, i));
                        tags.Last().Controlvalue = i;
                    }
                    con.WriteValues(tags);
                    #endregion
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
        }
        private static void ReadFromNck(string ipAddress = "192.168.214.1")
        {
            using (var con = new PLCConnection("ReadFromNck"))
            {
                con.Configuration.CpuIP   = ipAddress;
                con.Configuration.CpuSlot = 4;
                con.Connect();

                try
                {
                    if (!con.Connected)
                    {
                        con.Connect();
                    }

                    #region Channel 1 R[0]
                    var R0 = con.ReadValue(new NC_Var(0x82, 0x41, 0x1, 0x1, 0x15, 0x1, 0xF, 0x8));
                    Console.WriteLine("R0: {0}", R0);
                    #endregion

                    #region List of R-Parameter
                    var rpa     = new NC_Var(0x82, 0x40, 0x1, 0x0, 0x15, 0x1, 0xF, 0x8);
                    var tags    = new List <PLCNckTag>();
                    int channel = 1;
                    for (int i = 1; i < 10; i++)
                    {
                        tags.Add(rpa.GetNckTag(channel, i));
                        tags.Last().Tag = string.Format("R[{0}]", i - 1);
                    }
                    con.ReadValues(tags);
                    tags.ForEach(f => Console.WriteLine("{0}: {1}", f.Tag, f.Value));
                    #endregion
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
        }
示例#4
0
        private void GetParts()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            if (myConn == null)
            {
                DoConnect();
            }

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

            try
            {
                //---------------------  ActualParts   -------------------------------

                NC_Var actualParts = new NC_Var();
                actualParts.Bereich_u_einheit = 0x40;
                actualParts.Spalte            = 0x79;
                actualParts.Zeile             = 0x1;
                actualParts.Bausteintyp       = 0x7F;
                actualParts.ZEILENANZAHL      = 0x1;
                actualParts.Typ    = 0xF;
                actualParts.Laenge = 0x8;



                PLCNckTag actualPartsTag = actualParts.GetNckTag(1, 0);
                actualPartsTag.Tag = "ActualParts";
                tagList.Add(actualPartsTag);

                //---------------------  TotalParts  -------------------------------

                NC_Var totalParts = new NC_Var();
                totalParts.Bereich_u_einheit = 0x40;
                totalParts.Spalte            = 0x78;
                totalParts.Zeile             = 0x1;
                totalParts.Bausteintyp       = 0x7F;
                totalParts.ZEILENANZAHL      = 0x1;
                totalParts.Typ    = 0xF;
                totalParts.Laenge = 0x8;

                PLCNckTag totalPartsTag = totalParts.GetNckTag(1, 0);
                totalPartsTag.Tag = "TotalParts";
                tagList.Add(totalPartsTag);



                NC_Var    partsCounter    = new NC_Var(0x82, 0x40, 0x6CE8, 0x1, 0x1A, 0x1, 0x7, 0x4); // soll 272 sein, dann ists richtig aktiviert
                PLCNckTag counterPartsTag = partsCounter.GetNckTag(1, 0);
                tagList.Add(counterPartsTag);


                NC_Var    cycleTime    = new NC_Var(0x82, 0x40, 0x9, 0x1, 0x3B, 0x1, 0xF, 0x8);
                PLCNckTag cycleTimeTag = cycleTime.GetNckTag(1, 0);
                tagList.Add(cycleTimeTag);

                NC_Var    oldProgNetTime    = new NC_Var(0x82, 0x40, 0x12A, 0x1, 0x7F, 0x1, 0xF, 0x8);
                PLCNckTag oldProgNetTimeTag = oldProgNetTime.GetNckTag(1, 0);
                tagList.Add(oldProgNetTimeTag);

                oldProgNetTimeTag.Value = 12.3;
                myConn.WriteValue(oldProgNetTimeTag);

                myConn.ReadValues(tagList);

                lblActualParts.Text    = String.Format("Actual: {0}", actualPartsTag.Value.ToString());
                lblTotalParts.Text     = String.Format("Total: {0}", totalPartsTag.Value.ToString());
                lblCounter.Text        = String.Format("Counter: {0}", counterPartsTag.Value.ToString());
                lblCycleTime.Text      = String.Format("CycleTime: {0}", cycleTimeTag.Value.ToString());
                lblOldProgNetTime.Text = String.Format("OldProgNetTime: {0}", oldProgNetTimeTag.Value.ToString());
            }
            catch
            {
            }

            sw.Stop();

            lblStatus.Text += "           " + sw.ElapsedMilliseconds.ToString() + " ms";
        }