In the post ‘How to use monitoring attributes‘ I showed how to use the monitoring attributes: attribute ‘monitoring’ := ‘variable’ and attribute ‘monitoring’ := ‘call’. With these pragma attributes we can monitor and modify our function blocks properties. This comes however with a small drawback. As the online view now shows your properties and their backing fields your online view gets less clear. In this post I will show how to solve this with the hiding attributes.
The problem
Lets get back to the last example from How to use monitoring attributes. We have a function block with four properties. Each properties is backed with a local variable. The properties are all annotated with a monitoring variable which gave us the following view:
Our goal was to be able to monitor and modify our properties, which we successively did. However it shows us both the properties and the local backing fields (variables)! This is unnecessary double information which will confuse you more than it helps you. Especially when your programs grow bigger.
The solution
Luckily Codesys introduced some more pragma attributes:
{attribute ‘hide’} – The pragma attributes prevents the decorated variable to be shown in the online view. This attributes also prevents the variable from being visible in the input assistant.
{attribute ‘hide_all_locals’} – This pragma attributes hides all local variables of the decorated POU. This attributes also prevents the variable from being visible in the input assistant.
Lets add the attributes to some the of local variables of the function block ‘PropertyFBWithPragmas’:
FUNCTION_BLOCK PropertyFBWithPragmas VAR {attribute 'hide'} _Execute:BOOL; {attribute 'hide'} _Busy:BOOL; {attribute 'hide'} _Done:BOOL; _Counter:INT; END_VAR
Now going to the online view gives us a view without the annotated variables:
If you however want to hide all your local variables you could choose to decorate your POU, function block in our case, with the pragma attribute: ‘{attribute ‘hide_all_locals’}’ :
{attribute 'hide_all_locals'} FUNCTION_BLOCK PropertyFBWithHidePragma VAR _Execute:BOOL; _Busy:BOOL; _Done:BOOL; _Counter:INT; END_VAR
Which gives as expected a view where all local variables are hidden:
Conclusion
The monitoring attributes available in Codesys are great to show real time information about your properties. There is however a risk of getting double information because the online view now shows the properties as well as the backing field variables. But with the hiding attributes :{attribute ‘hide’} and {attribute ‘hide_all_locals’} we can chose to hide these backing fields variables.
For more information about pragma attributes check out the post about the monitoring attributes or the Codesys help files.