Beispiel #1
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a new User Defined Type on the processor called CustomUDT
         * 4. Add the following members to the type:
         *      1. Enabled : BOOL
         *      2. UpperLimit : DINT
         *      3. LowerLimit : DINT
         *      4. RunningValue : REAL
         *      5. Over : BOOL
         *      6. Under : BOOL
         * 5. Create a new tag of type CustomUDT called myCustomUDT
         * 6. Run
         *
         */
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";

            byte[]         path      = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            Console.WriteLine("6D Systems LLC\n\n");

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags or complex tags like UDTs.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            CustomUDT myCustomUDT = new CustomUDT("myCustomUDT", processor);

            myCustomUDT.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);

            //Add the tag to the group...
            myGroup.AddTag(myCustomUDT);

            //Set the group to auto update
            processor.EnableAutoUpdate(500);

            //Print out some structure information:
            PrintStructure(myCustomUDT);

            //Now wait for updates...
            Console.WriteLine("Change some data in the custom type, then hit Enter to quit");

            Console.ReadLine();

            processor.Disconnect();
        }
Beispiel #2
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a 1 dimensional DINT array on the processor called dintArray1[10]
         * 4. Create a 2 dimensional DINT array on the processor called dintArray2[10,10]
         * 5. Create a 3 dimensional DINT array on the processor called dintArray3[10,10,10]
         * 6. Run
         *
        */
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";
            byte[] path = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            //Now let's create our first array. The number of elements is the TOTAL number
            //of elements to read, in all dimensions.
            LogixDINT dintArray1 = new LogixDINT("dintArray1", processor, 10);

            //We don't need to set the number of dimensions on the tag here because it
            //assumes that it's a single dimension tag. All tags are set up to be arrays
            //by default, the .Value or similar member always returns the 0th element
            //of the array. With a tag that is not an array, that is where the value is.

            //Let's create the 2 dimensional array
            LogixDINT dintArray2 = new LogixDINT("dintArray2", processor, 100);

            //The number of elements are the subscripts multiplied by each other. In this
            //case, 10*10 = 100. If you put a lower value here you will only read that
            //much of the array. ControlLogix packs it's arrays in row major format, so
            //just keep that in mind if reading partial arrays.

            //If you want to set it up to read with a multidimensional accessor, we need
            //to tell the tag what the size of the dimensions are.
            dintArray2.SetMultipleDimensions(10, 10);

            //We can now access the tag by the tagName[row,column] format. If you didn't
            //set the size, you would get an exception when trying to access the tag
            //using that format.

            //Let's create the last tag
            LogixDINT dintArray3 = new LogixDINT("dintArray3", processor, 1000);

            //Set the dimensions
            dintArray3.SetMultipleDimensions(10, 10, 10);

            //Now let's add our tags to the tag group...
            myGroup.AddTag(dintArray1);
            myGroup.AddTag(dintArray2);
            myGroup.AddTag(dintArray3);

            Console.WriteLine("6D Systems LLC\n\n");
            Console.WriteLine("Tags created...");

            //Now let's pick out some random members and display them...
            Console.WriteLine("dintArray1[4]     = " + dintArray1[4].ToString());
            Console.WriteLine("dintArray2[5,2]   = " + dintArray2[5, 2].ToString());
            Console.WriteLine("dintArray3[4,7,3] = " + dintArray3[4, 7, 3].ToString());
            Console.WriteLine("\nPress any key to write a new value to each of the above tags");
            Console.ReadKey(false);

            //Now let's write some data to those tags...
            Random rnd = new Random();
            dintArray1[4] = rnd.Next(int.MinValue, int.MaxValue);
            dintArray2[5, 2] = rnd.Next(int.MinValue, int.MaxValue);
            dintArray3[4, 7, 3] = rnd.Next(int.MinValue, int.MaxValue);

            //Let's update the tag group
            processor.UpdateGroups();

            //Now print them back out for the user...
            Console.WriteLine("\nNew tag values...");
            Console.WriteLine("dintArray1[4]     = " + dintArray1[4].ToString());
            Console.WriteLine("dintArray2[5,2]   = " + dintArray2[5, 2].ToString());
            Console.WriteLine("dintArray3[4,7,3] = " + dintArray3[4, 7, 3].ToString());
            Console.WriteLine("\nPress any key to quit");
            Console.ReadKey(false);

            //Remember to disconnect from the processor
            processor.Disconnect();
        }
Beispiel #3
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a 1 dimensional DINT array on the processor called dintArray1[10]
         * 4. Create a 2 dimensional DINT array on the processor called dintArray2[10,10]
         * 5. Create a 3 dimensional DINT array on the processor called dintArray3[10,10,10]
         * 6. Run
         *
         */

        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";

            byte[]         path      = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            //Now let's create our first array. The number of elements is the TOTAL number
            //of elements to read, in all dimensions.
            LogixDINT dintArray1 = new LogixDINT("dintArray1", processor, 10);

            //We don't need to set the number of dimensions on the tag here because it
            //assumes that it's a single dimension tag. All tags are set up to be arrays
            //by default, the .Value or similar member always returns the 0th element
            //of the array. With a tag that is not an array, that is where the value is.

            //Let's create the 2 dimensional array
            LogixDINT dintArray2 = new LogixDINT("dintArray2", processor, 100);

            //The number of elements are the subscripts multiplied by each other. In this
            //case, 10*10 = 100. If you put a lower value here you will only read that
            //much of the array. ControlLogix packs it's arrays in row major format, so
            //just keep that in mind if reading partial arrays.

            //If you want to set it up to read with a multidimensional accessor, we need
            //to tell the tag what the size of the dimensions are.
            dintArray2.SetMultipleDimensions(10, 10);

            //We can now access the tag by the tagName[row,column] format. If you didn't
            //set the size, you would get an exception when trying to access the tag
            //using that format.

            //Let's create the last tag
            LogixDINT dintArray3 = new LogixDINT("dintArray3", processor, 1000);

            //Set the dimensions
            dintArray3.SetMultipleDimensions(10, 10, 10);

            //Now let's add our tags to the tag group...
            myGroup.AddTag(dintArray1);
            myGroup.AddTag(dintArray2);
            myGroup.AddTag(dintArray3);

            Console.WriteLine("6D Systems LLC\n\n");
            Console.WriteLine("Tags created...");

            //Now let's pick out some random members and display them...
            Console.WriteLine("dintArray1[4]     = " + dintArray1[4].ToString());
            Console.WriteLine("dintArray2[5,2]   = " + dintArray2[5, 2].ToString());
            Console.WriteLine("dintArray3[4,7,3] = " + dintArray3[4, 7, 3].ToString());
            Console.WriteLine("\nPress any key to write a new value to each of the above tags");
            Console.ReadKey(false);

            //Now let's write some data to those tags...
            Random rnd = new Random();

            dintArray1[4]       = rnd.Next(int.MinValue, int.MaxValue);
            dintArray2[5, 2]    = rnd.Next(int.MinValue, int.MaxValue);
            dintArray3[4, 7, 3] = rnd.Next(int.MinValue, int.MaxValue);

            //Let's update the tag group
            processor.UpdateGroups();

            //Now print them back out for the user...
            Console.WriteLine("\nNew tag values...");
            Console.WriteLine("dintArray1[4]     = " + dintArray1[4].ToString());
            Console.WriteLine("dintArray2[5,2]   = " + dintArray2[5, 2].ToString());
            Console.WriteLine("dintArray3[4,7,3] = " + dintArray3[4, 7, 3].ToString());
            Console.WriteLine("\nPress any key to quit");
            Console.ReadKey(false);

            //Remember to disconnect from the processor
            processor.Disconnect();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";

            byte[]         path      = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //Connect to the PLC, you can create the events before or after the connect function
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //Tag groups allow you to group tags in a useful manner. For example in an HMI you
            //could create tag groups for each page. Disabling a tag group that is not in use
            //frees up resources on the processor and the network.

            //You also have to be careful about the two different kinds of Enabled properties.
            //There is an enabled property for the tag group, and there is an Enabled property
            //for the tag itself. Disabling the tag group stops it from being updated, so no
            //tags belonging to that group will be updated (unless they also belong to another
            //active tag group). Disabling the tag by setting the LogixTag.Enabled property
            //to false means that the tag won't accept new data or pending values, and that
            //any tag group that it belongs to won't update it.

            //First, we need to create a LogixTagGroup on the processor. The easiest way to do
            //this is to use the LogixProcessor.CreateTagGroup() method. This allows the
            //processor to create the tag group, verify it doesn't conflict with another tag
            //group, and manage the group.

            LogixTagGroup tg = processor.CreateTagGroup("MyGroup");

            //Now that we've created a tag group, we can add some tags to it. Adding and removing
            //tags from a tag group is an expensive process. The tag group will automatically
            //re-optimize all the tags it's responsible for when you add or remove a tag. It's
            //recommended that you don't add or remove tags very often, if you don't need a tag
            //to be updated anymore just set the LogixTag.Enabled property to false.

            //Here we are going to ask the user (probably you) for some tags. The easiest way to
            //create tags without knowing the underlying data type in the processor is to use
            //the LogixTagFactory.

            bool      quitFlag = false;
            LogixDINT dTag     = new LogixDINT("tst_Dint", processor);

            dTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);
            tg.AddTag(dTag);

            while (!quitFlag)
            {
                Console.Write("Please enter a tag name to monitor, enter 'done' when finished: ");

                string tagName = Console.ReadLine();

                if (tagName.ToLower() == "done")
                {
                    quitFlag = true;
                    continue;
                }

                LogixTag userTag = LogixTagFactory.CreateTag(tagName, processor);

                if (userTag == null)
                {
                    //When the tag factory returns null, the tag was not found or some other
                    //catastrophic error occurred trying to reference it on the processor.
                    Console.WriteLine("The tag " + tagName + " could not be created");
                    continue;
                }

                //If we got here, we were able to successfully create the tag. Let's print
                //some information about it...
                Console.WriteLine("Created " + tagName + " as a(n) " + userTag.LogixType.ToString());

                //Let's reference the update functions...
                userTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);

                //Now let's add it to the tag group...
                tg.AddTag(userTag);
            }

            //The processor has a feature that allows them to automatically update the tag group. This
            //helps to free up your logic and not worry about having to update tag groups that are
            //enabled or disabled. The argument for this function is the time between updates in
            //milliseconds. The actual time from the start of one update to the start of another is
            //dependant on how many tags there are and how much data needs to be transferred.
            processor.EnableAutoUpdate(500);

            Console.WriteLine("Press Enter to quit");
            Console.ReadLine();

            processor.Disconnect();
        }
Beispiel #5
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a user defined type tag in your processor called myUDT1
         * 4. Create an ALARM tag in your processor called myAlarm1
         * 5. Run
         *
         */

        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";

            byte[]         path      = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            Console.WriteLine("6D Systems LLC\n\n");

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags or complex tags like UDTs.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            //Ok, let's create the first tag which is some random user defined type
            LogixTag genericTag = LogixTagFactory.CreateTag("myUDT1", processor);
            LogixUDT udtTag     = genericTag as LogixUDT;

            if (udtTag == null)
            {
                Console.WriteLine("The tag 'myUDT1' on the processor is not a structure tag");
                Console.WriteLine("Press any key to quit");
                Console.ReadKey(false);
                processor.Disconnect();
                return;
            }

            //Let's print out some information about the UDT
            PrintStructure(udtTag);

            //The value of any member can also be set with the tagName[memberName] = value syntax

            //Now let's get information about the alarm tag that was created...
            LogixTag genericAlarm = LogixTagFactory.CreateTag("myAlarm1", processor);
            LogixUDT alarmTag     = genericAlarm as LogixUDT;

            if (alarmTag == null)
            {
                Console.WriteLine("The tag 'myAlarm1' is not a structure tag");
                Console.WriteLine("Press any key to quit");
                Console.ReadKey(false);
                processor.Disconnect();
                return;
            }

            //Print out information about it...
            PrintStructure(alarmTag);

            //Now, let's set up the tags in the group, set the group to auto update, and watch
            //for tag update events...
            myGroup.AddTag(udtTag);
            myGroup.AddTag(alarmTag);

            udtTag.TagValueUpdated   += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);
            alarmTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);

            processor.EnableAutoUpdate(500);

            Console.WriteLine("Press Enter to quit");

            Console.ReadLine();

            processor.Disconnect();
        }
Beispiel #6
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Run
         *
        */
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";
            byte[] path = new byte[] { 0 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            string menu = "6D Systems LLC\n"
                        + "-----------------------------------------\n"
                        + "(1) - Get Information About A Tag\n"
                        + "(2) - Read a tag\n"
                        + "(3) - Write a tag\n"
                        + "(Q) - Quit\n"
                        + "-----------------------------------------\n"
                        + "Enter your choice:";

            bool quitFlag = false;

            while (!quitFlag)
            {
                Console.Clear();
                Console.Write(menu);

                string key = Console.ReadLine();

                switch (key)
                {
                    case "1":
                        TagInformation(processor);
                        break;
                    case "2":
                        ReadTag(processor);
                        break;
                    case "3":
                        WriteTag(processor);
                        break;
                    case "q":
                    case "Q":
                        quitFlag = true;
                        continue;
                    default:
                        Console.WriteLine("Invalid entry");
                        break;
                }

                Console.WriteLine("Hit any key to go back to the menu");
                Console.ReadKey(false);
            }

            //Remember to disconnect from the processor. If you forget, the processor won't allow you
            //to reconnect until the session times out, which is typically 60 seconds.

            processor.Disconnect();
        }
Beispiel #7
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Run
         *
         */

        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";

            byte[]         path      = new byte[] { 0 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            string menu = "6D Systems LLC\n"
                          + "-----------------------------------------\n"
                          + "(1) - Get Information About A Tag\n"
                          + "(2) - Read a tag\n"
                          + "(3) - Write a tag\n"
                          + "(Q) - Quit\n"
                          + "-----------------------------------------\n"
                          + "Enter your choice:";

            bool quitFlag = false;

            while (!quitFlag)
            {
                Console.Clear();
                Console.Write(menu);

                string key = Console.ReadLine();

                switch (key)
                {
                case "1":
                    TagInformation(processor);
                    break;

                case "2":
                    ReadTag(processor);
                    break;

                case "3":
                    WriteTag(processor);
                    break;

                case "q":
                case "Q":
                    quitFlag = true;
                    continue;

                default:
                    Console.WriteLine("Invalid entry");
                    break;
                }

                Console.WriteLine("Hit any key to go back to the menu");
                Console.ReadKey(false);
            }

            //Remember to disconnect from the processor. If you forget, the processor won't allow you
            //to reconnect until the session times out, which is typically 60 seconds.

            processor.Disconnect();
        }
Beispiel #8
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Run
         *
         */

        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";

            byte[]         path      = new byte[] { 0 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //Connect to the PLC, you can create the events before or after the connect function
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //Create the events, the processor state is updated every second, and if there is
            //a change in either the fault state, key switch position, or processor state (RUN, PROGRAM, TEST),
            //then one of these events will be fired.
            processor.FaultStateChanged     += new LogixFaultStateChangedEvent(processor_FaultStateChanged);
            processor.KeySwitchChanged      += new LogixKeyPositionChangedEvent(processor_KeySwitchChanged);
            processor.ProcessorStateChanged += new LogixProcessorStateChangedEvent(processor_ProcessorStateChanged);

            Console.WriteLine("6D Systems LLC");
            Console.WriteLine("Processor State Example: Change the key switch, fault state, or processor\nmode to see a message displayed");
            Console.WriteLine("\nProcessor Information:\n" + processor);
            Console.WriteLine("\n\n");

            //The processor can, through source code, be put in Program mode or Run mode. This is useful
            //if you are developing a critical process where you want to be able to shut all the outputs
            //off on the PLC at one time. Mode changes only work if the processor key is in Remote

            //The .UserData field can be used to store any data you desire, and it will be persisted
            //with the processor object. This is useful, for example, for storing information about
            //a processor when it's in a dictionary...

            processor.UserData = "MainPLC_1";

            bool quitFlag = false;

            while (!quitFlag)
            {
                Console.WriteLine("\n\n=============================MENU=============================");
                Console.WriteLine("Press the 'P' key to put the processor in Program mode");
                Console.WriteLine("Press the 'R' key to put the processor in Run mode");
                Console.WriteLine("Press the 'U' key to display the processor UserData");
                Console.WriteLine("Press the 'T' key to display all the tags on the processor");
                Console.WriteLine("Press the 'Q' key to quit");
                Console.WriteLine("==============================================================");

                char key = Console.ReadKey(true).KeyChar;

                switch (key)
                {
                case 'p':
                case 'P':
                    Console.WriteLine("Setting processor to Program mode...");
                    processor.SetProgramMode();
                    break;

                case 'r':
                case 'R':
                    Console.WriteLine("Setting processor to Run mode...");
                    processor.SetRunMode();
                    break;

                case 'u':
                case 'U':
                    Console.WriteLine("UserData: " + (string)processor.UserData);
                    break;

                case 't':
                case 'T':
                    List <LogixTagInfo> tagInfo = processor.EnumerateTags();
                    if (tagInfo == null)
                    {
                        Console.WriteLine("No tags found");
                        break;
                    }
                    Console.WriteLine("There are " + tagInfo.Count + " tags...");
                    foreach (LogixTagInfo info in tagInfo)
                    {
                        string name = info.TagName;
                        if (info.Dimensions > 0)
                        {
                            name += "[" + info.Dimension1Size.ToString();
                        }
                        if (info.Dimensions > 1)
                        {
                            name += ", " + info.Dimension2Size.ToString();
                        }
                        if (info.Dimensions > 2)
                        {
                            name += ", " + info.Dimension3Size.ToString();
                        }
                        if (info.Dimensions > 0)
                        {
                            name += "]";
                        }
                        Console.WriteLine("\t" + name);
                    }
                    break;

                case 'q':
                case 'Q':
                    quitFlag = true;
                    break;

                default:
                    break;
                }
            }

            //Always remember to disconnect the PLC. If you forget, the PLC won't allow you to reconnect
            //until the session times out. This is typically about 45-60 seconds.
            processor.Disconnect();
        }
Beispiel #9
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a user defined type tag in your processor called myUDT1
         * 4. Create an ALARM tag in your processor called myAlarm1
         * 5. Run
         *
        */
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";
            byte[] path = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            Console.WriteLine("6D Systems LLC\n\n");

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags or complex tags like UDTs.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            //Ok, let's create the first tag which is some random user defined type
            LogixTag genericTag = LogixTagFactory.CreateTag("myUDT1", processor);
            LogixUDT udtTag = genericTag as LogixUDT;

            if (udtTag == null)
            {
                Console.WriteLine("The tag 'myUDT1' on the processor is not a structure tag");
                Console.WriteLine("Press any key to quit");
                Console.ReadKey(false);
                processor.Disconnect();
                return;
            }

            //Let's print out some information about the UDT
            PrintStructure(udtTag);

            //The value of any member can also be set with the tagName[memberName] = value syntax

            //Now let's get information about the alarm tag that was created...
            LogixTag genericAlarm = LogixTagFactory.CreateTag("myAlarm1", processor);
            LogixUDT alarmTag = genericAlarm as LogixUDT;

            if (alarmTag == null)
            {
                Console.WriteLine("The tag 'myAlarm1' is not a structure tag");
                Console.WriteLine("Press any key to quit");
                Console.ReadKey(false);
                processor.Disconnect();
                return;
            }

            //Print out information about it...
            PrintStructure(alarmTag);

            //Now, let's set up the tags in the group, set the group to auto update, and watch
            //for tag update events...
            myGroup.AddTag(udtTag);
            myGroup.AddTag(alarmTag);

            udtTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);
            alarmTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);

            processor.EnableAutoUpdate(500);

            Console.WriteLine("Press Enter to quit");

            Console.ReadLine();

            processor.Disconnect();
        }
Beispiel #10
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Run
         *
        */
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";
            byte[] path = new byte[] { 0 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //Connect to the PLC, you can create the events before or after the connect function
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //Create the events, the processor state is updated every second, and if there is
            //a change in either the fault state, key switch position, or processor state (RUN, PROGRAM, TEST),
            //then one of these events will be fired.
            processor.FaultStateChanged += new LogixFaultStateChangedEvent(processor_FaultStateChanged);
            processor.KeySwitchChanged += new LogixKeyPositionChangedEvent(processor_KeySwitchChanged);
            processor.ProcessorStateChanged += new LogixProcessorStateChangedEvent(processor_ProcessorStateChanged);

            Console.WriteLine("6D Systems LLC");
            Console.WriteLine("Processor State Example: Change the key switch, fault state, or processor\nmode to see a message displayed");
            Console.WriteLine("\nProcessor Information:\n" + processor);
            Console.WriteLine("\n\n");

            //The processor can, through source code, be put in Program mode or Run mode. This is useful
            //if you are developing a critical process where you want to be able to shut all the outputs
            //off on the PLC at one time. Mode changes only work if the processor key is in Remote

            //The .UserData field can be used to store any data you desire, and it will be persisted
            //with the processor object. This is useful, for example, for storing information about
            //a processor when it's in a dictionary...

            processor.UserData = "MainPLC_1";

            bool quitFlag = false;

            while (!quitFlag)
            {
                Console.WriteLine("\n\n=============================MENU=============================");
                Console.WriteLine("Press the 'P' key to put the processor in Program mode");
                Console.WriteLine("Press the 'R' key to put the processor in Run mode");
                Console.WriteLine("Press the 'U' key to display the processor UserData");
                Console.WriteLine("Press the 'T' key to display all the tags on the processor");
                Console.WriteLine("Press the 'Q' key to quit");
                Console.WriteLine("==============================================================");

                char key = Console.ReadKey(true).KeyChar;

                switch (key)
                {
                    case 'p':
                    case 'P':
                        Console.WriteLine("Setting processor to Program mode...");
                        processor.SetProgramMode();
                        break;
                    case 'r':
                    case 'R':
                        Console.WriteLine("Setting processor to Run mode...");
                        processor.SetRunMode();
                        break;
                    case 'u':
                    case 'U':
                        Console.WriteLine("UserData: " + (string)processor.UserData);
                        break;
                    case 't':
                    case 'T':
                        List<LogixTagInfo> tagInfo = processor.EnumerateTags();
                        if (tagInfo == null)
                        {
                            Console.WriteLine("No tags found");
                            break;
                        }
                        Console.WriteLine("There are " + tagInfo.Count + " tags...");
                        foreach (LogixTagInfo info in tagInfo)
                        {
                            string name = info.TagName;
                            if (info.Dimensions > 0)
                                name += "[" + info.Dimension1Size.ToString();
                            if (info.Dimensions > 1)
                                name += ", " + info.Dimension2Size.ToString();
                            if (info.Dimensions > 2)
                                name += ", " + info.Dimension3Size.ToString();
                            if (info.Dimensions > 0)
                                name += "]";
                            Console.WriteLine("\t" + name);
                        }
                        break;
                    case 'q':
                    case 'Q':
                        quitFlag = true;
                        break;
                    default:
                        break;
                }
            }

            //Always remember to disconnect the PLC. If you forget, the PLC won't allow you to reconnect
            //until the session times out. This is typically about 45-60 seconds.
            processor.Disconnect();
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";
            byte[] path = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //Connect to the PLC, you can create the events before or after the connect function
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //Tag groups allow you to group tags in a useful manner. For example in an HMI you
            //could create tag groups for each page. Disabling a tag group that is not in use
            //frees up resources on the processor and the network.

            //You also have to be careful about the two different kinds of Enabled properties.
            //There is an enabled property for the tag group, and there is an Enabled property
            //for the tag itself. Disabling the tag group stops it from being updated, so no
            //tags belonging to that group will be updated (unless they also belong to another
            //active tag group). Disabling the tag by setting the LogixTag.Enabled property
            //to false means that the tag won't accept new data or pending values, and that
            //any tag group that it belongs to won't update it.

            //First, we need to create a LogixTagGroup on the processor. The easiest way to do
            //this is to use the LogixProcessor.CreateTagGroup() method. This allows the
            //processor to create the tag group, verify it doesn't conflict with another tag
            //group, and manage the group.

            LogixTagGroup tg = processor.CreateTagGroup("MyGroup");

            //Now that we've created a tag group, we can add some tags to it. Adding and removing
            //tags from a tag group is an expensive process. The tag group will automatically
            //re-optimize all the tags it's responsible for when you add or remove a tag. It's
            //recommended that you don't add or remove tags very often, if you don't need a tag
            //to be updated anymore just set the LogixTag.Enabled property to false.

            //Here we are going to ask the user (probably you) for some tags. The easiest way to
            //create tags without knowing the underlying data type in the processor is to use
            //the LogixTagFactory.

            bool quitFlag = false;
            LogixDINT dTag = new LogixDINT("tst_Dint", processor);
            dTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);
            tg.AddTag(dTag);

            while (!quitFlag)
            {
                Console.Write("Please enter a tag name to monitor, enter 'done' when finished: ");

                string tagName = Console.ReadLine();

                if (tagName.ToLower() == "done")
                {
                    quitFlag = true;
                    continue;
                }

                LogixTag userTag = LogixTagFactory.CreateTag(tagName, processor);

                if (userTag == null)
                {
                    //When the tag factory returns null, the tag was not found or some other
                    //catastrophic error occurred trying to reference it on the processor.
                    Console.WriteLine("The tag " + tagName + " could not be created");
                    continue;
                }

                //If we got here, we were able to successfully create the tag. Let's print
                //some information about it...
                Console.WriteLine("Created " + tagName + " as a(n) " + userTag.LogixType.ToString());

                //Let's reference the update functions...
                userTag.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);

                //Now let's add it to the tag group...
                tg.AddTag(userTag);
            }

            //The processor has a feature that allows them to automatically update the tag group. This
            //helps to free up your logic and not worry about having to update tag groups that are
            //enabled or disabled. The argument for this function is the time between updates in
            //milliseconds. The actual time from the start of one update to the start of another is
            //dependant on how many tags there are and how much data needs to be transferred.
            processor.EnableAutoUpdate(500);

            Console.WriteLine("Press Enter to quit");
            Console.ReadLine();

            processor.Disconnect();
        }
Beispiel #12
0
        /*
         * HOW TO USE THIS SAMPLE
         *
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a new User Defined Type on the processor called CustomUDT
         * 4. Add the following members to the type:
         *      1. Enabled : BOOL
         *      2. UpperLimit : DINT
         *      3. LowerLimit : DINT
         *      4. RunningValue : REAL
         *      5. Over : BOOL
         *      6. Under : BOOL
         * 5. Create a new tag of type CustomUDT called myCustomUDT
         * 6. Run
         *
        */
        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "192.168.1.10";
            byte[] path = new byte[] { 1 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            Console.WriteLine("6D Systems LLC\n\n");

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags or complex tags like UDTs.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            CustomUDT myCustomUDT = new CustomUDT("myCustomUDT", processor);
            myCustomUDT.TagValueUpdated += new ICommon.TagValueUpdateEventHandler(TagValueUpdated);

            //Add the tag to the group...
            myGroup.AddTag(myCustomUDT);

            //Set the group to auto update
            processor.EnableAutoUpdate(500);

            //Print out some structure information:
            PrintStructure(myCustomUDT);

            //Now wait for updates...
            Console.WriteLine("Change some data in the custom type, then hit Enter to quit");

            Console.ReadLine();

            processor.Disconnect();
        }