PLUS+1 User Forum

PLUS+1 Hardware => Controllers => Topic started by: macbahi on August 01, 2022, 03:03:29 PM

Title: POU Variable RETAIN
Post by: macbahi 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
Title: Re: POU Variable RETAIN
Post by: FluidPowerTom 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.
Title: Re: POU Variable RETAIN
Post by: macbahi 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
Title: Re: POU Variable RETAIN
Post by: macbahi 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
Title: Re: POU Variable RETAIN
Post by: acmall 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.




Title: Re: POU Variable RETAIN
Post by: macbahi on August 02, 2022, 02:07:50 PM
Hi!

Thank you Sir.

With best regards
Title: Re: POU Variable RETAIN
Post by: macbahi 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
Title: Re: POU Variable RETAIN
Post by: acmall on August 02, 2022, 04:37:53 PM
Can you post your code as it is now?
Title: Re: POU Variable RETAIN
Post by: macbahi 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