<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Retain variables in function block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/fbd343d7ad/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/fbd343d7ad/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/fbd343d7ad/</id><updated>2021-02-02T20:48:04.227000Z</updated><subtitle>Recent posts to Retain variables in function block</subtitle><entry><title>Retain variables in function block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/fbd343d7ad/?limit=25#0de8" rel="alternate"/><published>2021-02-02T20:48:04.227000Z</published><updated>2021-02-02T20:48:04.227000Z</updated><author><name>dawidr</name><uri>https://forge.codesys.com/u/dawidr/</uri></author><id>https://forge.codesys.com64f20906d741df7856319032a09b40d572fa8f8d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;That is the question I'm also looking answer for!&lt;br/&gt;
Anyone has more info?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Retain variables in function block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/fbd343d7ad/?limit=25#0473" rel="alternate"/><published>2020-02-27T13:49:31.850000Z</published><updated>2020-02-27T13:49:31.850000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com9c1790056dad3e26bf117536e14959c688fb90fa</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;According to the help file "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;a class="" href="https://help.codesys.com/api-content/2/codesys/3.5.12.0/en/_cds_vartypes_retain_persistent/" rel="nofollow"&gt;https://help.codesys.com/api-content/2/ ... ersistent/&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;I created a function block with only the following variables:&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="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Test1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;ARRAY&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;..50&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;UINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;100&lt;/span&gt; &lt;span class="nt"&gt;bytes&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt; &lt;span class="nt"&gt;RETAIN&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Test2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;ARRAY&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;..50&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;DINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;200&lt;/span&gt; &lt;span class="nt"&gt;bytes&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I have a program that only implements one instance of this function block.  Using SIZEOF at runtime shows a function block size of 312 bytes&lt;/p&gt;
&lt;p&gt;Now, if I right click on the device, and go to "Device Memory Info", the size of my Retain Data is only 203 bytes.  &lt;/p&gt;
&lt;p&gt;If the complete instance of the function block is stored in the retain range, I would expect the retain data size to be the same as the function block size (312 bytes), but it isn't, it's only 203 bytes--the size of the retain data.  Is the manual incorrect?&lt;/p&gt;
&lt;p&gt;I am using Schneider M241 PLC with Machine Expert 1.1, which is using Codesys 3.5 SP12&lt;/p&gt;
&lt;p&gt;thanks&lt;/p&gt;
&lt;p&gt;Tim&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>