PDA

View Full Version : Structured Text Persistent/Retain Structures?


Zlinger
December 9th, 2016, 11:34 AM
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.

jkerekes
December 9th, 2016, 12:05 PM
What PLC are we talking about?

Zlinger
December 9th, 2016, 12:08 PM
This is a Schneider M251 programmed with SoMachine v4.1, which is Codesys-esque.

ganutenator
December 10th, 2016, 10:58 AM
That M251 looks more powerful than an M340. How do you like it so far?

Zlinger
December 10th, 2016, 11:17 AM
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.

keshik
December 10th, 2016, 12:00 PM
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.

Zlinger
December 10th, 2016, 12:53 PM
Thank you.

ganutenator
December 10th, 2016, 01:46 PM
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.

shooter
December 11th, 2016, 02:36 PM
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.

Peter Nachtwey
December 11th, 2016, 04:03 PM
I have the specification. The retain etc attributes apply to all the variables declared between the VAR {attributes} ... END_VAR.