Beckhoff#What is VAR_STAT and how to use it?

In this tutorial I will explain the variable that is defined inside VAR_STAT.

VAR_STAT?

VAR_STAT is an object that extends from IEC61131-3 , and  the Variables that are defined inside, are shared the same memory. 

AS we know, Function blocks have their own instance and these instances ‘ memory are separate.But – the Variables that are defined inside VAR_STAT, are sharing the same variables from all multiple instances.

Let’s see some examples.


Example

Let’s add a Function Block.

We named it as FB_TEST.

Add the VAR_STAT statement, and define a variable named _iCounter.

And then insert a method in the Function Block.

We can implement some sample code to test these VAR_STAT features. 

This method will +1 while called.

And inside the method , it receives one input and the _iCounter is increased 1 while the value of bAdd1 is True.

Now we defined 6 instances of FB_TEST, but only the first one will execute the Method with +1.

After we downloaded the program, the actual value of _iCounter is 0.

Can you see the icon of _iCounter has a little “s” letter.?

It means _iCounter is a VAR_STAT variable.

While we call the Meth_add() with Ture, the value of _iCounter inside all instance are changed to 1.It means that all multiple instance are sharing the same variable.

But I still do not know how to use it in real-applications..

Download

Please follow the link the download the sample code.

TwinCAT3/TwinCAT Project Example VAR_STAT.tnzip at main · soup01Threes/TwinCAT3 (github.com)

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする