<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/</id><updated>2020-08-21T14:07:10.799000Z</updated><subtitle>Recent posts to How to initialize arrays of function blocks that need FB_Init to work</subtitle><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#a886/7576" rel="alternate"/><published>2020-08-21T14:07:10.799000Z</published><updated>2020-08-21T14:07:10.799000Z</updated><author><name>aikapan</name><uri>https://forge.codesys.com/u/aikapan/</uri></author><id>https://forge.codesys.com8a4014eab86f0b00f13b5a4acc0a682dca6442d4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;would also work for you! Why it should not? what's the problem?&lt;br/&gt;
workaround is not clean code. try directly ;)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#a886" rel="alternate"/><published>2020-04-24T22:17:05.613000Z</published><updated>2020-04-24T22:17:05.613000Z</updated><author><name>robertklonek</name><uri>https://forge.codesys.com/u/robertklonek/</uri></author><id>https://forge.codesys.com874fa320655abe0bfb74f3bed41713209fd0a99c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello,&lt;br/&gt;
I was interested. Unfortunately, your yannickasselin1 method didn't work for me.&lt;br/&gt;
I came up with a workaround - instead of FB_INIT I created a normal method: INIT (with the same implementation as FB_INIT). But since it's not called before running, I call them separately inside the FB_INIT method in another FB. For Example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;MyObject&lt;/span&gt;
&lt;span class="nv"&gt;METHOD&lt;/span&gt; &lt;span class="nv"&gt;init&lt;/span&gt; 
&lt;span class="nv"&gt;VAR_IN_OUT&lt;/span&gt;
    &lt;span class="nv"&gt;ptrCF&lt;/span&gt; : &lt;span class="nv"&gt;ptrCF&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;

&lt;span class="nv"&gt;HelpObject&lt;/span&gt;
&lt;span class="nv"&gt;METHOD&lt;/span&gt; &lt;span class="nv"&gt;FB_INIT&lt;/span&gt;
&lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt;
    &lt;span class="nv"&gt;MyObjectArray&lt;/span&gt;[&lt;span class="nv"&gt;i&lt;/span&gt;].&lt;span class="nv"&gt;init&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ptrCF&lt;/span&gt;[&lt;span class="nv"&gt;i&lt;/span&gt;]&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_FOR&lt;/span&gt;

&lt;span class="nv"&gt;GLOBAL_VAR&lt;/span&gt;
     &lt;span class="nv"&gt;MyObjectArray&lt;/span&gt;: &lt;span class="nv"&gt;ARRAY&lt;/span&gt;[&lt;span class="mi"&gt;0&lt;/span&gt;..&lt;span class="mi"&gt;3&lt;/span&gt;] &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;MyObject&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
     &lt;span class="nv"&gt;ptrCF&lt;/span&gt; : &lt;span class="nv"&gt;ARRAY&lt;/span&gt;[&lt;span class="mi"&gt;0&lt;/span&gt;..&lt;span class="mi"&gt;3&lt;/span&gt;] &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;ptrCF&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#ebf2" rel="alternate"/><published>2020-02-27T13:59:49.515000Z</published><updated>2020-02-27T13:59:49.515000Z</updated><author><name>yannickasselin1</name><uri>https://forge.codesys.com/u/yannickasselin1/</uri></author><id>https://forge.codesys.com594d7a335ccf1cefa6b3ae7a3322e02697befbbd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;@Joan M&lt;/p&gt;
&lt;p&gt;If anyone still looking for a way to achieve initialization of an array of objects through FB_Init, here's the syntax that worked for me:&lt;/p&gt;
&lt;p&gt;MyObjectArray:  ARRAY&lt;span&gt;[0..3]&lt;/span&gt; OF MyObject&lt;span&gt;[(1), (2), (3), (4)]&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;It is almost the same as Joan M tried in his exemple except that I have removed the " := " sign.&lt;/p&gt;
&lt;p&gt;Enjoy.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#538e" rel="alternate"/><published>2020-02-27T13:59:49.247000Z</published><updated>2020-02-27T13:59:49.247000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comefa6cf0acf57c0fa0a99fa54e8003f61244e6697</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; Catharine Coombs&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://explainjava.com/" rel="nofollow"&gt;https://explainjava.com/&lt;/a&gt; They are written simple here, so it went out clear to me as to guys with no experience. But  now I know for sure that CDS is not the very thing you need to try when you just have started practicing&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#771b" rel="alternate"/><published>2020-02-27T13:59:48.406000Z</published><updated>2020-02-27T13:59:48.406000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.coma61d270466fe0eaf6bff2b4f664ea2e4f93f389f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;I don't think your array initialization will ever work without a change from 3s.  If you play around a bit, one of the precompile errors will be .&lt;/p&gt;
&lt;p&gt;To clarify... when you try to initialize your array, you are defining what your objects should literally , not how they should initialize.  Take for example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyArray&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ARRAY&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You are telling the compiler you want your integers to  integers 1 and then 2.&lt;/p&gt;
&lt;p&gt;If you do:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyArray&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ARRAY&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;MyObject&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You are telling the compiler that you want your MyObjects to  integers 1 and then 2.&lt;/p&gt;
&lt;p&gt;This is not the same as having your object instantiate with a value of 1 and then 2.  I doubt CoDeSys can do what you are hoping for.&lt;/p&gt;
&lt;p&gt;In fact, this works (unfortunately, the precompiler really wants me to use MyObject(0) - otherwise it complains I am not following the Fb_INIT):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;Obj1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;MyObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;Obj2&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;MyObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;MyArray&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;ARRAY&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;MyObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Obj2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But this means your objects have to be created first and then put into the array (not what you wanted).&lt;/p&gt;
&lt;p&gt;If you are looking to simply have a unique ID with every instance, see this thread:  l &lt;a class="" href="http://forum.codesys.com/viewtopic.php?f=11&amp;amp;t=7348" rel="nofollow"&gt;viewtopic.php?f=11&amp;amp;t=7348&lt;/a&gt; l &lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: array_init.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=2435"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#a31f" rel="alternate"/><published>2020-02-27T13:59:48.127000Z</published><updated>2020-02-27T13:59:48.127000Z</updated><author><name>josepmariarams</name><uri>https://forge.codesys.com/u/josepmariarams/</uri></author><id>https://forge.codesys.com3cdbd90fb3f3c45c2fd8689ffec31246a1c94e5d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Dears.&lt;/p&gt;
&lt;p&gt;From your post I will test to pass parameters to FB_Init when the fB  is created via __new and it works doing:&lt;/p&gt;
&lt;p&gt;tst:=__new(test_class(temp:=450));&lt;/p&gt;
&lt;p&gt;(Being temp an input of FB_init),&lt;/p&gt;
&lt;p&gt;After that I have test to do the same in arrays, but I only can pass the same parameter to all FB_inits of the array:&lt;/p&gt;
&lt;p&gt;tst2:ARRAY&lt;span&gt;[0..2]&lt;/span&gt; of test_class(temp:=450);&lt;br/&gt;
All tst2 elements are initialized with temp:=50.&lt;/p&gt;
&lt;p&gt;But in array initialization you could initialize internal FB variables:&lt;/p&gt;
&lt;p&gt;tst2:ARRAY&lt;span&gt;[0..2]&lt;/span&gt; of test_class:=&lt;span&gt;[(tt:=1),(tt:=2),(tt:=3)]&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;Being tt internal variables of the FB not input variables of FB_init. That variables are setted after FB_init, but before a function with {'attribute call_after_init'}.&lt;/p&gt;
&lt;p&gt;You can use internal variables as constructor inputs and put the constructor code in a function with 'call_after_init' attribute.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#64c9" rel="alternate"/><published>2020-02-27T13:59:47.758000Z</published><updated>2020-02-27T13:59:47.758000Z</updated><author><name>rickj</name><uri>https://forge.codesys.com/u/rickj/</uri></author><id>https://forge.codesys.com26fadf9b1be237c4f2bfe30089ad546e9562572d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Joan if I understand correctly, perhaps you can do something like the following example.  I haven't tried it so don't know if this approach works.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="o"&gt;***&lt;/span&gt; &lt;span class="nv"&gt;FB&lt;/span&gt; &lt;span class="nv"&gt;Definition&lt;/span&gt;
&lt;span class="nv"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="nv"&gt;MyObject&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt;
   &lt;span class="nv"&gt;Id&lt;/span&gt;         : &lt;span class="nv"&gt;INT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="o"&gt;***&lt;/span&gt; &lt;span class="nv"&gt;Init&lt;/span&gt; &lt;span class="nv"&gt;Method&lt;/span&gt;
&lt;span class="nv"&gt;METHOD&lt;/span&gt; &lt;span class="nv"&gt;FB_init&lt;/span&gt; : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;VAR_INPUT&lt;/span&gt;
   &lt;span class="nv"&gt;bInitRetains&lt;/span&gt;   : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;bInCodyCode&lt;/span&gt;   : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;List&lt;/span&gt;         : &lt;span class="nv"&gt;POINTER&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;ARRAY&lt;/span&gt; [&lt;span class="mi"&gt;0&lt;/span&gt;..&lt;span class="mi"&gt;32767&lt;/span&gt;] &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;MyObject&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;First&lt;/span&gt;         : &lt;span class="nv"&gt;INT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;Last&lt;/span&gt;         : &lt;span class="nv"&gt;INT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt;
   &lt;span class="nv"&gt;i&lt;/span&gt;         : &lt;span class="nv"&gt;INT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;First&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;Last&lt;/span&gt; &lt;span class="nv"&gt;BY&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt;      &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nv"&gt;Search&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;list&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;self&lt;/span&gt;
   &lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;List&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;[&lt;span class="nv"&gt;i&lt;/span&gt;]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;THIS&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
      &lt;span class="nv"&gt;ID&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;Exit&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;span class="nv"&gt;END_FOR&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="o"&gt;***&lt;/span&gt; &lt;span class="nv"&gt;Usage&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt;
   &lt;span class="nv"&gt;ObjectArray&lt;/span&gt;   : &lt;span class="nv"&gt;ARRAY&lt;/span&gt; [&lt;span class="mi"&gt;1&lt;/span&gt;..&lt;span class="mi"&gt;4&lt;/span&gt;] &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;MyObject&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;List&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ADR&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ObjectArray&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;, &lt;span class="nv"&gt;First&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;, &lt;span class="nv"&gt;Last&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#7bdb" rel="alternate"/><published>2020-02-27T13:59:47.461000Z</published><updated>2020-02-27T13:59:47.461000Z</updated><author><name>Joan M</name><uri>https://forge.codesys.com/u/joan-m/</uri></author><id>https://forge.codesys.com53d29178492a8b5fddd85091802f858e44002f80</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi again camferti...&lt;/p&gt;
&lt;p&gt;This is possible using the new Object Oriented Programming paradigm Codesys V.3 offers.&lt;/p&gt;
&lt;p&gt;FB_Init is not a "normal" function.&lt;br/&gt;
It is the constructor function and it is used specifically to initialize internal things of the newly created function block.  (Somehow configure it).&lt;br/&gt;
this function is automatically called each time you instantiate the object that owns it (so each time you instantiate the fb that has it implemented).&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://infosys.beckhoff.com/content/1033/tc3_plc_intro/9007199390945931.html?id=8333023073559976250" rel="nofollow"&gt;https://infosys.beckhoff.com/content/1033/tc3_plc_intro/9007199390945931.html?id=8333023073559976250&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As a good example, it works when used alone (first line) in the program:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyObjectAlone&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;MyObject&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Here I'm not calling FB_Init at all, but it is automatically called and it receives 1 as the parameter ID.&lt;br/&gt;
But it is not working when used in an array as I can't parameterize the FB_Init function...&lt;/p&gt;
&lt;p&gt;The reason of this to fail must be:&lt;/p&gt;
&lt;p&gt;A) The syntax I'm using is wrong (which is what I believe).&lt;br/&gt;
B) The implementation of this feature is not done even the error message doesn't suggest this.&lt;/p&gt;
&lt;p&gt;In the newly attached picture you can see the errors the compiler show.&lt;/p&gt;
&lt;p&gt;Hope this clarifies a little bit more what happens here.&lt;/p&gt;
&lt;p&gt;Thank you very much.&lt;/p&gt;
&lt;p&gt;Again, happy new year.&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: MyObject_Errors.PNG" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=2423"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#24be" rel="alternate"/><published>2020-02-27T13:59:46.650000Z</published><updated>2020-02-27T13:59:46.650000Z</updated><author><name>camferti</name><uri>https://forge.codesys.com/u/camferti/</uri></author><id>https://forge.codesys.com5c1b1e35a92ea7c73200b36db2306bddf55c5c54</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Joan Murt hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Hello again,&lt;br/&gt;
Some extra explanations in the pictures comments.&lt;br/&gt;
You can see three different ways to instantiate the MyObject function block in MyProgram.&lt;br/&gt;
The first method of instantiation works well, but it forces me to create instances individually and I loose the possibility to put them inside an array. This is how I'm doing it right now.&lt;br/&gt;
The second method doesn't work for me as I do need the FB_Init call which is not called/parameterized.&lt;br/&gt;
The third one is what I'm interested in but doesn't work.&lt;br/&gt;
Thank you for your time.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Do you want to use a variable that you define within a function in the program?&lt;br/&gt;
it's not possible.&lt;br/&gt;
Why do you want to do that? I do not see the meaning. What are you trying to do?&lt;/p&gt;
&lt;p&gt;In the first line you make a call to the function "myObject (1)" so it does not give error&lt;br/&gt;
In the second and third where you make the call to the function? You do not start the instance&lt;/p&gt;
&lt;p&gt;happy New Year&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to initialize arrays of function blocks that need FB_Init to work</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/?limit=25#a0e9" rel="alternate"/><published>2020-02-27T13:59:46.354000Z</published><updated>2020-02-27T13:59:46.354000Z</updated><author><name>Joan M</name><uri>https://forge.codesys.com/u/joan-m/</uri></author><id>https://forge.codesys.com0c403a8cbb7b2af6f37b3987b901d36ed0cfa2f7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello again,&lt;/p&gt;
&lt;p&gt;Some extra explanations in the pictures comments.&lt;/p&gt;
&lt;p&gt;You can see three different ways to instantiate the MyObject function block in MyProgram.&lt;/p&gt;
&lt;p&gt;The first method of instantiation works well, but it forces me to create instances individually and I loose the possibility to put them inside an array. This is how I'm doing it right now.&lt;/p&gt;
&lt;p&gt;The second method doesn't work for me as I do need the FB_Init call which is not called/parameterized.&lt;/p&gt;
&lt;p&gt;The third one is what I'm interested in but doesn't work.&lt;/p&gt;
&lt;p&gt;Thank you for your time.&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: MyObject.PNG" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=2422"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: MyObject.FB_Init.PNG" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=2421"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: MyProgram.PNG" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=2420"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>