<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Usage of VAR RETAIN PERSISTENT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/</id><updated>2021-02-02T20:51:33.990000Z</updated><subtitle>Recent posts to Usage of VAR RETAIN PERSISTENT</subtitle><entry><title>Usage of VAR RETAIN PERSISTENT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/?limit=25#93ae/ece3" rel="alternate"/><published>2021-02-02T20:51:33.990000Z</published><updated>2021-02-02T20:51:33.990000Z</updated><author><name>dawidr</name><uri>https://forge.codesys.com/u/dawidr/</uri></author><id>https://forge.codesys.com8163c9cc72ca57c426bb769ce47728c0b2562f87</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I know about "Declarations/Add all instance paths" function but I was thinking that it will store the whole function block in the retain memory area. Just like it was written in the manual (https://help.codesys.com/api-content/2/codesys/3.5.12.0/en/_cds_vartypes_retain_persistent/).&lt;/p&gt;
&lt;p&gt;I will try to do some tests just like you did in your post.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Usage of VAR RETAIN PERSISTENT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/?limit=25#93ae" rel="alternate"/><published>2021-02-02T18:50:14.052000Z</published><updated>2021-02-02T18:50:14.052000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com77aea8a60fc630d4c7fd90e93eea5db222194124</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I used to do it the way you've described.  I now do it this way, which I've found easier.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;FUNCTION&lt;/span&gt; &lt;span class="nt"&gt;BLOCK&lt;/span&gt; &lt;span class="nt"&gt;TEST_FB&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt; &lt;span class="nt"&gt;PERSISTENT&lt;/span&gt;
    &lt;span class="nt"&gt;Setpoints&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;   &lt;span class="nt"&gt;SETPOINT_STRUCT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;all&lt;/span&gt; &lt;span class="nt"&gt;persistent&lt;/span&gt; &lt;span class="nt"&gt;variables&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then, within the PersistentVars variable list, go to "Declarations/Add all instance paths".  The paths of all your persistent variables will be automatically created.  &lt;/p&gt;
&lt;p&gt;&lt;a href="https://help.codesys.com/api-content/2/codesys/3.5.12.0/en/_cds_cmd_add_all_instance_paths/" rel="nofollow"&gt;https://help.codesys.com/api-content/2/codesys/3.5.12.0/en/_cds_cmd_add_all_instance_paths/&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Usage of VAR RETAIN PERSISTENT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/?limit=25#d318" rel="alternate"/><published>2021-01-29T12:35:14.918000Z</published><updated>2021-01-29T12:35:14.918000Z</updated><author><name>dawidr</name><uri>https://forge.codesys.com/u/dawidr/</uri></author><id>https://forge.codesys.comad06f0ffaaf36cd511fa1941587437474854a1a5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm using WAGO PLC PFC200 in my home automation project. I've plenty of POUs, each for one room. Each room implements IRoom interface and uses base POU for common logic like turning off all lights. For lights management, I'm using&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;FbEvaluateShortLongPress from WagoAppBuilding to handle short and long press of buttons on the wall (it could also be a function block from OSCAT library)&lt;/li&gt;
&lt;li&gt;FbLatchingRelay from WagoAppBuilding as a toggle for PLC digital output&lt;br/&gt;
I want to save the state of FbLatchingRelay in case of e.g.: power drop. I want all lights which were turned off before power drop to be turned on when the power comes back.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I've solved it by declaring a FbLatchingRelay in the VAR RETAIN PERSISTENT area in my POU. But then after reading here that:&lt;/p&gt;
&lt;p&gt;If you declare a local variable in a function block as RETAIN, CODESYS stores the complete instance of this function block in the Retain range (all data of the function block); however, only the declared RETAIN variable is treated as such.&lt;/p&gt;
&lt;p&gt;I decided to change that in order not to waste RETAIN memory for a bunch of variables which are in POU but are not needed to be stored as RETAIN.&lt;/p&gt;
&lt;p&gt;So right now I have something like that:&lt;/p&gt;
&lt;p&gt;the VAR RETAIN PERSISTENT area is only declared in my main program&lt;br/&gt;
it stores structures for each room (each POU) only with needed data - FbLatchingRelay POU and few other variables&lt;br/&gt;
while initializing the room (POU) I'm passing those structures to my rooms using VAR_IN_OUT&lt;br/&gt;
each room (POU) uses then this data&lt;br/&gt;
PLC_PRG:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;VAR&lt;/span&gt; &lt;span class="nt"&gt;RETAIN&lt;/span&gt; &lt;span class="nt"&gt;PERSISTENT&lt;/span&gt;
    &lt;span class="nt"&gt;BathroomPersistentData&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;BathroomData&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="nt"&gt;Bathroom&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;PersistData&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;BathroomPersistentData&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;xMainLightSwitch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;DI1_13&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;xMirrorLightSwitch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;DI2_3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;xMirrorLightSwitchActuator&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;DO2_1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;xMainLightSwitchActuator&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;DO1_11&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Bathroom POU:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;VAR_IN_OUT&lt;/span&gt;
    &lt;span class="nt"&gt;PersistData&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;BathroomData&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Is this a good approach? What do you think? It complicates project a bit but I'm not wasting RETAIN memory for things which should not be there (whole POUs).&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>