/* * 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(); }
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(); }
/* * 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(); }