Structured text (Logix) tag defaults don't work.

JaxGTO

Member
Join Date
Apr 2009
Location
Kalieefornia
Posts
1,071
Ok so this is my first time using structured text. I have some old quick basic string functions I'm trying to convert. For the local tags I'm trying to use the default to preset some string and numeric tags. But at runtime only a couple have the values I set in development.
I even commented out the code to make sure it's not stepping on the values. And sure enough only some have the default value.
I also tried to set them at the top of the routine but they still don't change.
What am I missing?

Logix 21.0
 
Can you post the actual code ? Since it's structured text you don't even need a screenshot, just copy/paste.

One of the curious things about ControlLogix is that there's no such thing as a string literal. You can use constant values for integers and reals, but you can't set a string to a literal value, like

Code:
Initial_Barcode := "ABC999" ;

But setting integers with the assignment operator should be fine.

Code:
Initial_Value := 999 ;
 
Here is the function. Converts a integer to a string of binary bits.

B:=InputDINT;

ZeroString.DATA[0]:=48;
OneString.DATA[0]:=49;

if B<>0 then
if B < 0 then //Negitive so set left most to '1' else its '0'
cop(OneString,T2,1);
else
cop(ZeroString,T2,1);
end_if;
M:=16384; //4000H=16384 Dec
for I:= 2 to 16 do
BandM:=B and M;
if BandM <> 0 then
BandedM:=1;
else
BandedM:=0;
end_if;
if BandedM then
CONCAT(T2,OneString,T2);
else
CONCAT(T2,ZeroString,T2);
end_if;
M:=M/2;
end_for;
end_if;
cop(T2,OutputString,1);

When I run it and hover over the first ref of OneString and ZeroString they show a '1' and '0' in them. But the next ref OneString shows '1' and ZeroString shows ''.

What could possibly be clearing that variable.
 
Setting .Data[0] is not enough
You must set .LEN to 1 in order string to be valid.

ZeroString.LEN:=1;
OneString.LEN:=1;
 
I agree with @Contr_Conn. Also I think you need to redefine T2.LEN because the first COP (copying One or Zero) will set T2.LEN to 1.

Just to give you another approach, I refactored your code:
Code:
FOR index := 0 TO 15 DO
  index2 := 15 - index;
  IF InputINT.[index2] THEN
    TempString.DATA[index] := 49;
  ELSE
    TempString.DATA[index] := 48;
  END_IF;
END_FOR;
TempString.LEN := 16;
 
Setting .Data[0] is not enough
You must set .LEN to 1 in order string to be valid.

ZeroString.LEN:=1;
OneString.LEN:=1;

OK I did that and now it works. The strange part is I should not have to set those local tags at all. When I created them I set the 'Default' valves accordingly, but the ZeroString tag would always show '' in it. Must be a corrupted file or something. I think next I will export it and see what's in the export file. If it looks good I will import it into a new program and see if it still does it.
 

Similar Topics

Good evening. I display the step number of a SFC on a display. Sometimes, on a trip, it goes quickly through many steps and I need to prove to...
Replies
1
Views
131
I am trying to learn structured text on the controllogix platform and have managed to fault the processor by creating an infinite loop. My problem...
Replies
21
Views
3,723
Hello, I please need your help why I cannot get the return parameter from the RET instruction to go into the return parameter in the JSR return...
Replies
6
Views
2,817
I am troubleshooting an issue on a controller with logic, function block and structured text. I am lost on how to read the structured text as...
Replies
8
Views
2,646
Hey! I'm looking for a way to reset a tag when the routine that sets the tag is disabled. For example: Routine 1 has the following If Tag1...
Replies
6
Views
1,812
Back
Top Bottom