TemperedEnterprises

RSLogix 5000 Code Generation using C#

4 posts in this topic

            CsvFileDescription d = new CsvFileDescription { SeparatorChar = ',', FirstLineHasColumnNames = true };
            CsvContext cc = new CsvContext();

            List<Pump> Pumps = new List<Pump>(cc.Read<Pump>(@"c:\tmp\pumps.csv", d));


            RSLogix5000Content c = RSLogix5000Content.Load(@"C:\tmp\test.l5x");

            Tag PAck = new Tag() { Name = "AlarmsProgAck", DataType = "BOOL", Description = new Description { TypedValue = "All Alarms Program Ack" } };
            Tag PRes = new Tag() { Name = "AlarmsProgRes", DataType = "BOOL", Description = new Description { TypedValue = "All Alarms Program Reset" } };
            Tag PEn = new Tag() { Name = "AlarmsProgEn", DataType = "BOOL", Description = new Description { TypedValue = "All Alarms Program Enable" } };
            Tag PDis = new Tag() { Name = "AlarmsProgDis", DataType = "BOOL", Description = new Description { TypedValue = "All Alarms Program Disable" } };

            c.Controller.Tags.Tag.Add(PAck);
            c.Controller.Tags.Tag.Add(PRes);
            c.Controller.Tags.Tag.Add(PEn);
            c.Controller.Tags.Tag.Add(PDis);


            int x = 1;

            foreach (Pump p in Pumps)
            {
                String InterlockBuilder = "";
                if ((p.Interlocks ?? "").Contains(','))
                {
                    string[] Interlocks = p.Interlocks.Trim().Split(',');

                    foreach (string interlock in Interlocks)
                    {
                        InterlockBuilder += "XIC(" + interlock + "Running)";
                    }
                }


                Tag PStart = new Tag() { Name = p.Name + "Start", DataType = "BOOL", Description = new Description { TypedValue = p.Description + " Start Command" } };
                Tag PStop = new Tag() { Name = p.Name + "Stop", DataType = "BOOL", Description = new Description { TypedValue = p.Description + " Stop Command" } };
                Tag PRunA = new Tag() { Name = p.Name + "Run", TagType = "Alias", AliasFor = p.StartOutput, Description = new Description { TypedValue = p.Description + " Run Output" } };
                Tag PRunningA = new Tag() { Name = p.Name + "Running", TagType = "Alias", AliasFor = p.RunInput, Description = new Description { TypedValue = p.Description + " Running Input" } };
                Tag PAlarmD = new Tag() { Name = p.Name + "Alarm", DataType = "ALARM_DIGITAL", Description = new Description { TypedValue = p.Description + " Start Alarm" } };

                Rung r = new Rung();
                r.Number = x++;
                r.Comment = new Comment { TypedValue = "Pump Logic Code for " + p.Description };
                r.Text = new Text { TypedValue = "[" + InterlockBuilder + "[XIC(" + p.Name + "Run)XIO(" + p.Name + "Stop),XIC(" + p.Name + "Start)]OTE(" + p.Name + "Run),XIC(" + p.Name + "Run)XIO(" + p.Name + "Running)ALMD(" + PAlarmD.Name + "," + PAck.Name + "," + PRes.Name + "," + PDis.Name + "," + PEn.Name + ")];" };


                Routine PumpRoutine = new Routine { Name = p.Name, Type = "RLL" };
                PumpRoutine.RLLContent = new RLLContent();
                PumpRoutine.RLLContent.Rung.Add(r);

                c.Controller.Programs.Program[0].Routines.Routine.Add(PumpRoutine);

                c.Controller.Programs.Program[0].Routines.Routine[0].RLLContent.Rung.Add(new Rung { Number = x, Text = new Text { TypedValue = "JSR(" + p.Name + ",0);" } });

                c.Controller.Tags.Tag.Add(PStart);
                c.Controller.Tags.Tag.Add(PStop);
                c.Controller.Tags.Tag.Add(PRunA);
                c.Controller.Tags.Tag.Add(PRunningA);
                c.Controller.Tags.Tag.Add(PAlarmD);
            }

            c.Save("c:\\tmp\\testout.l5x");

Here is the code that generates the ladder logic.

Share this post


Link to post
Share on other sites

wuld you mind sharing more info on this topic. How you are doing it e.t.c, e.t.c

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now