How to Assign String Values in RSLogix PLCs

Question:

As a newcomer to Logix PLCs, I am in the process of writing Structured Text code for implementation. Unfortunately, I am facing difficulty in assigning a string value to a string tag. After searching for resources, I came across Rockwell's Structured Text programming manual online. Surprisingly, the manual only provides two examples on how to achieve this task: Code:string1.DATA[0]:= 65; and Code:string1.DATA[0]:= string2.DATA[0]; Is it truly the case that strings can only be modified one character at a time? I am hoping that there is more to it than what is currently presented. It is frustrating to see Rockwell's lackluster string support.

Top Replies

To learn more about structured text programming for PLCs, refer to the detailed Structured Text Programming Manual available at http://claymore.engineer.gvsu.edu/~jackh/books/plcs/chapters/plc_st.pdf. This guide highlights various string manipulation instructions commonly used in structured text programming.

In the Logix 5000 operating system, there is no provision for using String literals or String constants. This means that you cannot simply assign a literal string to a String datatype tag like 'Twas brillig and the slithy toves.' However, you can still work with arrays of data from the .Data[x] SINT array or input character values into each .Data[x] element individually. While this functionality is present in IEC1131-3 Structured Text for creating variables, it is not supported in Logix 5000. Typically, String tags are created first, followed by manual entry of desired values in the Tag Database editor.

To optimize your code and maintain consistency, consider creating a set of constant string tags, such as "Always65String," for frequently used strings. Utilize a function like COP(Always65String, string1, 50) to define the length of the string (50 characters in this example). This approach will streamline your writing and enhance the efficiency of your programming endeavors.

To assign a string value to a tag (TAG_1) in RsLogix 5000, you need to have another tag (TAG_2) containing the desired value. Once you have TAG_2 set up, you can use the COP/CPS function to copy the string value into TAG_1. If you need to clear out a string, simply use the FLL function to fill TAG_1 with zeros. In newer versions of RsLogix 5000, such as v31+, you can compare a tag to a literal string using the EQU instruction, for example: EQU(TAG_1, "Test"). Hopefully, this explanation is helpful for your programming needs.

I'm confident that the original poster has found a solution over the span of five years.

I completely share your feeling with Rockwell's lackluster string support. However, I believe the approach you've found is the most common way to handle strings in this environment. While it isn't ideal and appears cumbersome, one aspect to understand is that in the PLC world, memory is often at a premium and every byte counts, so strings are typically treated as arrays of characters. Another method to assign a string value can be using the COPY instruction. For instance, COPY SOURCE:="Your String" DEST:=string_var; But, bear in mind that not all PLC models support this instruction. Though, you can always check your PLC model specifics in the Rockwell's programming guide. Cheers and happy coding!

More Replies →

Streamline Your Asset Management
See How Oxmaint Works!!

✅   Work Order Management

✅   Asset Tracking

✅   Preventive Maintenance

✅   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: 1. Is it possible to assign a full string value to a string tag in RSLogix PLCs?

Answer: Answer: While RSLogix PLCs primarily handle string manipulation at the character level, you can assign a full string value by sequentially assigning characters to the corresponding indices of the string tag.

FAQ: 2. Are there alternative methods for assigning string values in RSLogix PLCs beyond the examples provided in the Rockwell Structured Text programming manual?

Answer: Answer: Yes, aside from the examples in the manual, you can implement custom functions or logic to facilitate the assignment of string values more efficiently in RSLogix PLCs.

FAQ: 3. How can I enhance string manipulation capabilities in RSLogix PLCs beyond what is available in the standard resources?

Answer: Answer: You can explore advanced techniques such as using arrays of strings, custom string manipulation functions, or leveraging structured text programming features to streamline string handling tasks in RSLogix PLCs.

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  â†’