Author Topic: Static variable in POU  (Read 700 times)

Offline macbahi

  • PLUS+1 Expert
  • ****
  • Posts: 75
  • Karma: +1/-0
Static variable in POU
« 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


Offline macbahi

  • PLUS+1 Expert
  • ****
  • Posts: 75
  • Karma: +1/-0
Re: Static variable in POU
« Reply #1 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

Offline Tor

  • Administrator
  • PLUS+1 Guru
  • *
  • Posts: 208
  • Karma: +22/-1
Re: Static variable in POU
« Reply #2 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.
Best regards
Tor
PLUS+1 Helpdesk team

Offline macbahi

  • PLUS+1 Expert
  • ****
  • Posts: 75
  • Karma: +1/-0
Re: Static variable in POU
« Reply #3 on: June 08, 2022, 06:25:31 PM »
Hi Tor,

Ok .

Thanks

With best regards
mac bahi