<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to method Fb_init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/</id><updated>2023-08-16T13:25:01.518000Z</updated><subtitle>Recent posts to method Fb_init</subtitle><entry><title>method Fb_init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/?limit=25#c209" rel="alternate"/><published>2023-08-16T13:25:01.518000Z</published><updated>2023-08-16T13:25:01.518000Z</updated><author><name>TimvH</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.com8470f314bca4dffa8c18e19f2800f25a7a32d3e2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;You are trying to make something very simple really complex, but my best guess is that the order of execution is:&lt;br/&gt;
- initialize FB (x becomes 1)&lt;br/&gt;
- Load persistent (x is 1)&lt;br/&gt;
- start application (x remains 1)&lt;/p&gt;
&lt;p&gt;PS, It could also be that your "persistent" variables are not stored correctly and that, at startup, the value is always 0. Did you add this variable to the Persistent Variable list? And did you make sure that this works correctly on the device you are using?&lt;br/&gt;
So maybe the execution order is:&lt;br/&gt;
- load persistent (x is 0, because it was not stored correctly)&lt;br/&gt;
- initialize FB (x becomes 1)&lt;br/&gt;
- start application (x remains 1)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>method Fb_init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/?limit=25#f352/11d5" rel="alternate"/><published>2023-08-16T10:55:19.982000Z</published><updated>2023-08-16T10:55:19.982000Z</updated><author><name>sarunas</name><uri>https://forge.codesys.com/u/sarunas/</uri></author><id>https://forge.codesys.com8c420a98fe031f2c95cea436392467ecbc715f52</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I don't find information. All information about fb_init method is there "&lt;em&gt;You can declare additional function block inputs in an FBinit method. Then you have to set these inputs in the declaration of the function block instance.&lt;/em&gt;" and show example. So when fb_init of method is call.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>method Fb_init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/?limit=250#f352" rel="alternate"/><published>2023-08-16T10:35:20.914000Z</published><updated>2023-08-16T10:35:20.914000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com266608ef634ee5165bb75b53b062dba1744c99db</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Your anwsers are here: &lt;a href="https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_method_fb_init_fb_reinit.html" rel="nofollow"&gt;https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_method_fb_init_fb_reinit.html&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>method Fb_init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/047e509ebe/?limit=25#4d28" rel="alternate"/><published>2023-08-16T07:44:44.595000Z</published><updated>2023-08-16T07:44:44.595000Z</updated><author><name>sarunas</name><uri>https://forge.codesys.com/u/sarunas/</uri></author><id>https://forge.codesys.com7b35c4b99399bd21b19cd35c8e5a87f95a48bfbf</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;br/&gt;
"Could you please explain to me how the method FB_init works? The block inside it states, '&lt;em&gt;the retain variables are initialized (reset warm / reset cold).&lt;/em&gt;' Every time I perform a 'cold' reset on the PLC, do I need to call FB_init? Am I thinking correctly?"&lt;br/&gt;
Then I do that&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;VAR_GLOBAL PERSISTENT&lt;/span&gt;
&lt;span class="c"&gt;x: UINT;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Create function block&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;{attribute 'call_after_init'}&lt;/span&gt;
&lt;span class="err"&gt;FUNCTION_BLOCK Test&lt;/span&gt;
&lt;span class="err"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt;    y:                          INT;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;span class="err"&gt;VAR &lt;/span&gt;
&lt;span class="err"&gt;    output                      :INT;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;span class="c"&gt;output:=y*y;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Create FB_init of function block&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;METHOD FB_init : BOOL&lt;/span&gt;
&lt;span class="err"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt;    bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)&lt;/span&gt;
&lt;span class="err"&gt;    bInCopyCode : BOOL;  // if TRUE, the instance afterwards gets moved into the copy code (online change)&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;span class="err"&gt;gvl.x:=gvl.x+1;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Create main program&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;PROGRAM MAIN&lt;/span&gt;
&lt;span class="err"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt;    test: test;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;span class="err"&gt;test(y:=15);&lt;/span&gt;
&lt;span class="err"&gt;test(y:=16);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I'm currently performing a cold reset on the PLC, and the value of 'x' is supposed to increase. However, the value of 'x' remains unchanged at 1 all the time. The variable 'x' is of the PERSISTENT type so a cold reset of the PLC doesn't to have any impact on it.&lt;br/&gt;
Why can explain for me why that happen? &lt;/p&gt;&lt;/div&gt;</summary></entry></feed>