Structured Text Persistent/Retain Structures?

Zlinger

Member
Join Date
Mar 2014
Location
AZ
Posts
36
Hello all,

Thanks in advance for any help you can offer. I am pretty new to structured text. Is there any way that you can create a structure, and within that structure define some of the elements as PERSISTENT and RETAIN and some as just regular?

Lets say that I am defining a structure like this...

TYPE MyStruct :
STRUCT
//definition of my structure
element1 : DINT; //i want to define this as PERSISTENT
element2 : INT; //i want to define this as PERSISTENT and RETAIN
element3 : INT; //i don't want to define this as PERSISTENT or RETAIN
element4 : REAL; //i don't want to define this as PERSISTENT or RETAIN
END_STRUCT
END_TYPE

So, when I go to declare my variable as the type "MyStruct" that I just made, I have the option to designate the whole variable as just a VAR or VAR PERSISTENT RETAIN, or any combination of those, but I obviously can't specify those attributes for specific elements within the variable at that point.

Is there some syntax within the structure that I can use to designate specific elements for retention and others for no retention? I have tried a couple different stabs in the dark, but they always result in errors. Thank you.
 
Last edited:
It's not bad. It's a customer pick. I'm used to Allen Bradley mostly. I do like SoMachine better than UnityPro, but I haven't used either of them extensively.
 
I don't believe that you can accomplish what you are looking for. I would probably declare the struct as PERSISTENT/RETAIN and zero/default anything out that I didn't want retained on the first scan after powerup.
 
I don't believe that you can accomplish what you are looking for. I would probably declare the struct as PERSISTENT/RETAIN and zero/default anything out that I didn't want retained on the first scan after powerup.

good answer.
 
keshik is correct, as when declaring a variable (any kind) you have to set the way of keeping. this will set the place in the memory where the var is stored.
 
I'm new as well, could you declare a structure STRUCT PERSISTENT RETAIN and have another structure that extends this structure that contains non PERSISTENT RETAIN elements?
 
problem solved. went w/ the wago instead of the schneider product. the wago lets me locate persistent retain variables.
 
Persistent and Retain type variables have to be declared in a global variable list (GVL).

Maybe this might work for you (?):
First, create a structure for each of your variable types. So say ST_RETAIN (structure) would have all of your RETAIN variables, ST_PERSISTENT would have all of your PERSISTENT variables, etc. In each of the structures, you would declare variables as normal though, ie.....myBool:BOOL;, myInt:INT;, myREAL:REAL;, etc......

Then, create a global variable list (GVL) and in there declare an instance of each of your structures as VAR_GLOBAL PERSISTENT, VAR_GLOBAL, or VAR_GLOBAL RETAIN, like this:

VAR_GLOBAL PERSISTENT
myPersistentVars: ST_PERSISTENT;
END_VAR

VAR_GLOBAL RETAIN
MyRetainVars: ST_RETAIN;
END_VAR

Still, another way is to create one structure (MySTRUCT) and one global variable list (MyGVL) in your project tree. In the GVL, declare all of your variables as PERSISTENT, RETAIN, etc.... In your structure, create the same variables (myInt: INT, myBool:BOOL;, etc....). Then somewhere in your program, "map" the variables in the structure to the variables in the GVL:

MyStruct.someBoolean := MyGVL.someBoolean;
MyStruct.someInt := MyGVL.someInt;
etc......
 
Last edited:

Similar Topics

Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,166
I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
439
Trying to put these equations in structured text program in a Micro 830. when I run the verify I get this error. ;:expected before this new...
Replies
4
Views
394
Hey all, Studio v20.05 Background. We are piggy backing another system to record attributes for product travelling down the line and several...
Replies
21
Views
3,418
Hi, In our company (programming mainly Beckhoff PLCs) we are establishing internal coding guidelines for ST. Until now, the conventions were...
Replies
5
Views
1,017
Back
Top Bottom