Working with ControlLogix Strings


Introduction to Working with ControlLogix Strings

In this post, we’ll be Working with ControlLogix Strings. String manipulation is becoming an important part of programming. You can display strings directly to the operator on an HMI. You might display machine status, and even troubleshooting information by manipulating strings.

In the past, memory was an important concern, and most of the string manipulation was on the HMI. As memory becomes cheaper, and processors become more powerful, programmers are starting to use strings more frequently in the ControlLogix processor itself.

Basically, the ControlLogix supports several commands for string manipulation. First, we can find text in a string. Additionally, we can insert characters into a string. Another command allows us to add strings together. Other commands allow us to extract parts of a string, and delete parts of a string.

Create Tags for Working with ControlLogix Strings

Before we begin, we’ll create some strings. We’ll use these strings to demonstrate the ASCII manipulation instructions. In this case, I’ll just add them to the program tags. I’m adding the following tags. We will have four String tags, Likewise, we’ll have two DINT tags.

Under “Monitor Tags”, I’m placing the following values into the tags:

FIND Instruction

The first command we’ll test is the FIND command. Occasionally, programmers use special characters to delineate parts of a string. Additionally, if we read a string over ASCII, some special characters in the string might indicate the type of data it is. For example, H followed by a number might indicate the type of data is humidity. Likewise, T followed by a number might indicate the data is for temperature. The find command allows us to search for these characters to determine the type of data the string contains.

Let’s take a look ant an example using the strings and values from our tags.

As you can see, MyThirdString contains the value “THREE”. Keep in mind that strings are case sensitive. In the search field, we are searching to see if the string contains the characters “EE”. We’ll start on the first character. This is position 1. When the FIND instruction executes, it finds the characters “EE” in our source string. Obviously, these characters begin at position #4. Basically, if the result is a non-zero value, we know the string contains the characters we are searching for.

INSERT Instruction

Occasionally, we may want to insert one string into another string at a particular location. We might do this to display alarms or machine status. This allows us to manipulate text on the fly that the operator will see. In this case, we’ll do a simple demonstration of this command. We’ll insert MySecondString into MyFirstString at position four. We store the result to “MyThirdString”. As you can see, the result is “ONETWO”.

Since MyThirdString is different now, we no longer have “EE” in MyThirdString. As a result, the FIND statement returned a 0.

CONCAT Instruction

The CONCAT Instructionis similarly to the INSERT instruction. The difference is that it simply adds a string to the end of another string. Basically, this is regardless of the length. Keep in mind the maximum length of a string is 82 characters though. In this case, we’ll simply add MySearchString to MyFirstString. The result will be “ONEEE”. Again, a practical application might be to add an alarm condition to another statement.

At this point, our FIND result changed to position #3. This is the first instance of the characters “EE”.

MID Instruction

Basically, the MID instruction allows us to extract a certain part of a string. To use the MID instruction, we must know the starting position within the string. Additionally, we must know how many characters we want to retrieve. As you can see, I’m extracting the letter “N” from the text “ONE”. Starting at position 2, we’re getting 1 character. You might use this on known bar codes. Certain parts of the bar code represent a certain property of a product. For example, the first four characters might represent a line number. The next four characters might represent a product code. Using the MID instruction, we can extract the parts of the bar code that we need in logic.

DELETE Instruction

Lastly, we have the DELETE Instruction. This allows us to delete part of a string, and store the result to another string. It does not manipulate the original string. In this case, I’ve deleted the letter N from “ONE”. The N is at position 2, and I’m deleting one character. Again, an example of this would be for a bar code. We might delete parts of a bar code, so the operator only has pertinent information.

Summary for Working with ControlLogix Strings

ASCII string manipulation is easy. We just need to know the right commands to use for the right purpose. Basically, we can insert, delete, and extract parts of a string with the ASCII Manipulation commands. Just be careful not to manipulate any existing strings with important data. Also, keep in mind, the maximum default length of a string is 82 characters. Keep an eye on your processor memory. ASCII Strings can use a lot of memory if you use the irresponsibly.

For more information, visit the ControlLogix Category Page!

–Ricky Bryce

Leave a comment

Your email address will not be published. Required fields are marked *