Strings in Logix5000 Structured Text

whumphrey

Lifetime Supporting Member
Join Date
Aug 2011
Location
Lincoln, NE
Posts
35
Does anyone have a good way to assign values to STRING tags in Structured Text?

It seems that you cannot use text in quotes....i.e. StringVar := "String Text";

Also tried using all variables but am forced to declare which character to assign....i.e. StringVar1.Data[0] := StringVar2.Data[0];

Hopefully I'm overlooking something easy. Is there a structured text equivalent to the COP instruction where you can specify the number of elements?

Thanks,
Warren
 
At least for StringVar1 := StringVar2, you can likely use a COP() command. If the string types have different static lengths, you may want to modify StringVar1.LEN afterwards.

For StringVar := "StringLiteral", I want to bump the question to the top.
 
At least for StringVar1 := StringVar2, you can likely use a COP() command. If the string types have different static lengths, you may want to modify StringVar1.LEN afterwards.

For StringVar := "StringLiteral", I want to bump the question to the top.
The only way I am sure should work on any AB platform is to MOV literal INTs or DINTs into positions which are then copied into the string file. This is the surest way I know of to hard code it in the PLC.

This can be done in ladder, and may be different in ST.

I am not experienced with a/b structured text programming.

Another method is to apply security to the string file after manually setting the values, saving and downloading it.

This makes it "unsearchable" in the logic which may be undesirable, but you can use a dummy copy or a good comment to document it.
 
Last edited:
To improve on assigning literal INTs, I tried to put the string literal into a variable.

This exports in .l5k as

teststring : STRING := [4, 'test$00$00$00.....'];

I removed the $00s and it imports fine. 4 is the string length and 'test' is the string. To make it more searchable, the string "test" is included in the name, but this won't work for all strings.

Try using COP() to assign it to the target string if necessary.

I didn't try to COP() this over but I think it should work in Ladder and ST. Will likely be any or all of: faster, more compact, more readable, easier to generate than assigning INTs.

Would still better to have a "proper" way to assign strings.
 
Strings with Structured Text

I'm a big fan of Structured Text for a lot of various purposes, so FWIW, later versions of Logix accepts single quoted string literals.

PLXString := 'String for PLX31-EIP-ASCII';

Where PLXString is a `STRING` type.

Otherwise, the only way I know of to do it, is to create STRING tags of say, program scope, making them as Constant, and then copy them; the hard way if you have to.

COP(PLXString.DATA[0], DefaultStr.DATA[0], DefaultStr.LEN);
COP(PLXString.LEN, DefaultStr.LEN, 1);


None of which are attractive.

(I believe you can in fact use the assignment operator :=[/FONT to copy an entire string, but I haven't tried that specifically. You also have access to keywords like INSERT to insert a string into another string, but I haven't played with that a lot yet.)

I specifically tested this in v32, but I have a feeling it will work in earlier versions too.
v32string.png


(Later versions, I just discovered, means 5380 processors for CLX, and 5069 processors for CompactLogix. Seems those are the only processors that accept string literals. So, it's not only to do with RSLogix version number, it is actually processor specific, but since those processors have a limited scope of versions they can run; it still codes you into a corner.)

After testing with a 5580 (L81, v29, the oldest FW I had for an L81) proves that string literals can/do work...so long as you're using the right processor. If you're using the "wrong" processor; you have to go through all the fancy footwork to get anything close to resembling anything usable.
v29-L81.png


If anyone has questions on ST, let me know. I've written quite a bit of code in it, despite the fact that its use seems to be rejected on principle, almost industry wide.

(Excuse my poor post ethics. 'Tis my first post! Just finding my sea-legs here.)

v29-L81.png v32String.png
 
Last edited:
Larry, that is exactly what I was looking for, thank you. I was using double quotes and wondering why it didn't like it.

I feel your pain about trying to get languages adopted. I fight tooth and nail to get people to use function blocks, but everyone defaults to ladder, despite it being clunky in many applications. I use ST where it's the best way/still easy to read, like I/O mapping or anything where a for loop would be handy.

I think FBD is a slightly easier sell since it's still a "visual" language, where ST "looks like scary typed code" so a lot of non-career programmers shy away from it.

That and the good ol' Rockwell "highlight whatever and press F1 to see how it works" doesn't appear to work in ST, which is how I made my way here in the first place...
 
Even though this is originally an old thread..
I think the direct assignment is CPU/fw specific.

I recently went through a similar challenge with a L16 & ended up assigning the decimal equivalent of the ASCII character direct to the elements, then set the length.

strNoRead.DATA[0] := 78;
etc

strNoRead.LEN:=7
 
I'm a big fan of Structured Text for a lot of various purposes, so FWIW, later versions of Logix accepts single quoted string literals.

PLXString := 'String for PLX31-EIP-ASCII';

Where PLXString is a `STRING` type.

(I believe you can in fact use the assignment operator :=[/FONT to copy an entire string, but I haven't tried that specifically. You also have access to keywords like INSERT to insert a string into another string, but I haven't played with that a lot yet.)

I specifically tested this in v32, but I have a feeling it will work in earlier versions too.
v32string.png


(Later versions, I just discovered, means 5380 processors for CLX, and 5069 processors for CompactLogix. Seems those are the only processors that accept string literals. So, it's not only to do with RSLogix version number, it is actually processor specific, but since those processors have a limited scope of versions they can run; it still codes you into a corner.)

After testing with a 5580 (L81, v29, the oldest FW I had for an L81) proves that string literals can/do work...so long as you're using the right processor. If you're using the "wrong" processor; you have to go through all the fancy footwork to get anything close to resembling anything usable.
v29-L81.png


If anyone has questions on ST, let me know. I've written quite a bit of code in it, despite the fact that its use seems to be rejected on principle, almost industry wide.

(Excuse my poor post ethics. 'Tis my first post! Just finding my sea-legs here.)



Was glad I found someone that had success with direct right of strings but I can't seem to get it to verify in studio 5000 v35 with logix emulate, probably shouldn't use this technique for my current project so I maintain compatibility with customers older systems
 

Similar Topics

Instead of defining static alarm text strings in Wonderware, is it possible to build dynamic strings in the PLC and display those, or is that just...
Replies
3
Views
1,506
OK - strings don't belong in a PLC :bonkhead: but . . . I want to copy a string from one tag to another. Can I do this? I haven't found any...
Replies
3
Views
1,551
I have an application that I would like to display a string with an embedded DINT. In Logix500, this is very simple in the string editor, but not...
Replies
3
Views
3,402
Hey all, was wondering if it was possible to shift values in an array of strings? I have a database that I am loading up with "Users" in the...
Replies
2
Views
296
hi All I am completely green in Mitsubishi PLC (i used to program siemens) but need kepware to connect to FX3U pls with ENET adp module. Could...
Replies
31
Views
7,078
Back
Top Bottom