<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to FB_init and var init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/</id><updated>2020-02-27T13:52:20.534000Z</updated><subtitle>Recent posts to FB_init and var init</subtitle><entry><title>FB_init and var init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/?limit=25#f846" rel="alternate"/><published>2020-02-27T13:52:20.534000Z</published><updated>2020-02-27T13:52:20.534000Z</updated><author><name>josepmariarams</name><uri>https://forge.codesys.com/u/josepmariarams/</uri></author><id>https://forge.codesys.coma99b0b2b76b602793454fe85a5309627db41e35a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Look at pragmas help. There are one called   call_after_init or something similar. It doesn t work if it is called from a library.&lt;/p&gt;
&lt;p&gt;There exist another method which is instantiate an fb from var. If you  instantiate it as the first var in your fb, the fb_init of the new fb will be called before your variables initialization.&lt;/p&gt;
&lt;p&gt;Be healty!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>FB_init and var init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/?limit=25#b0e5" rel="alternate"/><published>2020-02-27T13:52:20.366000Z</published><updated>2020-02-27T13:52:20.366000Z</updated><author><name>wpmccormick</name><uri>https://forge.codesys.com/u/wpmccormick/</uri></author><id>https://forge.codesys.comf9d4ed5b6801f2e78b71b3b1f1611defd2b13b4a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;OK, thanks. I saw something that said FB_Init happened before VAR init. &lt;/p&gt;
&lt;p&gt;What is the function/method decorator to have it called after init? I think that will work for me.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>FB_init and var init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/?limit=25#60f7" rel="alternate"/><published>2020-02-27T13:52:20.196000Z</published><updated>2020-02-27T13:52:20.196000Z</updated><author><name>josepmariarams</name><uri>https://forge.codesys.com/u/josepmariarams/</uri></author><id>https://forge.codesys.com20a36031f7733ad26509bf02ec77b6979a95eb99</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Fb_init is called after the variables initialization.&lt;/p&gt;
&lt;p&gt;See in online help how is the initialization sequence&lt;/p&gt;
&lt;p&gt;Enviat des del meu Aquaris M5.5 usant Tapatalk&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>FB_init and var init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4bf9750dfa/?limit=25#02cf" rel="alternate"/><published>2020-02-27T13:52:20.019000Z</published><updated>2020-02-27T13:52:20.019000Z</updated><author><name>wpmccormick</name><uri>https://forge.codesys.com/u/wpmccormick/</uri></author><id>https://forge.codesys.com56267c851a1c371521002a1aaac03cd0ecdca260</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm having trouble with initializing function blocks inside of function blocks:&lt;/p&gt;
&lt;p&gt;FUNCTION BLOCK FB_Child&lt;br/&gt;
VAR&lt;br/&gt;
  cVar: DINT&lt;br/&gt;
END&lt;br/&gt;
METHOD FB_Init&lt;br/&gt;
VAR_INPUT&lt;br/&gt;
    bInitRetains: BOOL;&lt;br/&gt;
    bInCopyCode: BOOL;&lt;br/&gt;
    SomeVar: DINT;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;THIS^.cVar := SomeVar;&lt;/p&gt;
&lt;p&gt;FUNCTION BLOCK FB_Parent&lt;br/&gt;
VAR&lt;br/&gt;
  pVar: DINT;&lt;br/&gt;
  Child: FB_Child(myVar);&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;METHOD FB_Init&lt;br/&gt;
VAR_INPUT&lt;br/&gt;
    bInitRetains: BOOL;&lt;br/&gt;
    bInCopyCode: BOOL;&lt;br/&gt;
    SomeVar: DINT;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;THIS^.myVar := SomeVar;&lt;/p&gt;
&lt;p&gt;PROGRAM TestProg&lt;br/&gt;
VAR&lt;br/&gt;
    Test: DINT;&lt;br/&gt;
    Parent: FB_Parent(1234);&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;Obviously, this program does nothing but initialize a single variable, or should. The problem I'm having is that the Child.cVar (fairy syntax) doesn't have the value 1234, per my example.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>