Author Topic: POU Variable RETAIN  (Read 7888 times)

Offline macbahi

  • PLUS+1 Guru
  • *****
  • Posts: 125
  • Karma: +1/-0
POU Variable RETAIN
« on: August 01, 2022, 03:03:29 PM »
Hello,

I am using POU with structured text ST as you see in my example.
I do average of some numbers.
Like you see when I use Retain Variable I have problem as you see in picture.

Please could you tell me where the problem

Thanks for your help

With best regards

Offline FluidPowerTom

  • PLUS+1 Guru
  • *****
  • Posts: 363
  • Karma: +33/-0
Re: POU Variable RETAIN
« Reply #1 on: August 01, 2022, 05:15:20 PM »
You've got a colon instead of a semicolon at the end of your first RETAIN variable declaration.
Controls Engineer
Hydra-Power Systems

Offline macbahi

  • PLUS+1 Guru
  • *****
  • Posts: 125
  • Karma: +1/-0
Re: POU Variable RETAIN
« Reply #2 on: August 01, 2022, 05:26:51 PM »
Hi Tom,

Tank you very much to replay me.
But I didn't understand.  Please could you give more detail. Or Correct example.
I am not familiarized with POU ST

Thanks in advance.

With best regards

Offline macbahi

  • PLUS+1 Guru
  • *****
  • Posts: 125
  • Karma: +1/-0
Re: POU Variable RETAIN
« Reply #3 on: August 01, 2022, 05:56:19 PM »
HI Tom,

Sorry Tom It's ok but now I have another problem. Please see image.

My function is working without VAR RETAIN but the result is not good.
As example When NbIncrement_Scan =1 the output is equal to input. It's Ok.

But when My NbIncrement_Scan est >1 then the output is equal to zero.

That's why I tried to use VAR RETAIN.

I hope you understand my problem.

Thanks in advance for your help

Best regards

Offline acmall

  • PLUS+1 Guru
  • *****
  • Posts: 201
  • Karma: +37/-1
Re: POU Variable RETAIN
« Reply #4 on: August 02, 2022, 09:21:38 AM »
If you want to keep the valve of NbIncrument and CounteurIncrement between calls use a Function Block instead of a Function.

A Function does not store the valve of it's variables between calls so each time the function is called NbIncrument and CounteurIncrement will always be initialised to 0.  A Function Block will store the value variables.





Offline macbahi

  • PLUS+1 Guru
  • *****
  • Posts: 125
  • Karma: +1/-0
Re: POU Variable RETAIN
« Reply #5 on: August 02, 2022, 02:07:50 PM »
Hi!

Thank you Sir.

With best regards

Offline macbahi

  • PLUS+1 Guru
  • *****
  • Posts: 125
  • Karma: +1/-0
Re: POU Variable RETAIN
« Reply #6 on: August 02, 2022, 03:44:58 PM »
Hi acmall,

I do it but still the same problem. NbIncrument and CounteurIncrement are also initialized to 0 every call.

Thanks
Best regards

Offline acmall

  • PLUS+1 Guru
  • *****
  • Posts: 201
  • Karma: +37/-1
Re: POU Variable RETAIN
« Reply #7 on: August 02, 2022, 04:37:53 PM »
Can you post your code as it is now?

Offline macbahi

  • PLUS+1 Guru
  • *****
  • Posts: 125
  • Karma: +1/-0
Re: POU Variable RETAIN
« Reply #8 on: August 15, 2022, 06:56:29 PM »
Hi Acmall,

Sorry to be late I was in vacancy.

It's ok now. It was mistake in call function.

Thank you very much.

With best regards