PLUS+1 User Forum

PLUS+1 Hardware => Controllers => Topic started by: macbahi on June 07, 2022, 05:48:58 PM

Title: Static variable in POU
Post by: macbahi on June 07, 2022, 05:48:58 PM
Hello,

I try to use POU structured text.

Please I want to use static variable as in C programming.

as example   static double var1 =0   (initialized to zero but it can be changed after in the program)
 
Thanks in advance

With bests regards

Title: Re: Static variable in POU
Post by: macbahi on June 07, 2022, 06:10:38 PM
Hi

I have using this PLCcode  but not working with plus1

VAR_STAT
  var1 : INT :=0;
END_VAR

Thanks
Title: Re: Static variable in POU
Post by: Tor on June 08, 2022, 09:34:12 AM
Hello macbahi,

I'm not a ST or C coder so I asked around and this is what I got.

"If the customer makes his POU a FUNCTION_BLOCK then the value of ordinary VAR variables will be kept between the calls, just like a static in C-code

ie:
FUNCTION_BLOCK MyBlock
VAR
  var1 : INT := 0;
END_VAR

"

I hope it helps.
Title: Re: Static variable in POU
Post by: macbahi on June 08, 2022, 06:25:31 PM
Hi Tor,

Ok .

Thanks

With best regards
mac bahi