<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Instantiation id for a Function Block.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/</id><updated>2020-02-27T14:08:42.659000Z</updated><subtitle>Recent posts to Instantiation id for a Function Block.</subtitle><entry><title>Instantiation id for a Function Block.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/?limit=25#d9db" rel="alternate"/><published>2020-02-27T14:08:42.659000Z</published><updated>2020-02-27T14:08:42.659000Z</updated><author><name>learnetk</name><uri>https://forge.codesys.com/u/learnetk/</uri></author><id>https://forge.codesys.com070f1b4f00a19750c1af1637b8a4633999ef68ed</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Oh..Thankyou so much Scott..&lt;br/&gt;
this works like a charm..!!&lt;/p&gt;
&lt;p&gt;Thanks again and warm regards&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Instantiation id for a Function Block.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/?limit=25#d86c" rel="alternate"/><published>2020-02-27T14:08:42.147000Z</published><updated>2020-02-27T14:08:42.147000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com5cda44ae22073a417ba89f7544382f305cfbdd8a</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;Use VAR_STAT to define an internal FB var that is static across FB instances.  Then add an Fb_INIT method (see the help) that will increment the counter and assign to a var output.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="nv"&gt;Motor&lt;/span&gt;
&lt;span class="nv"&gt;VAR_OUTPUT&lt;/span&gt;
   &lt;span class="nv"&gt;MotorId&lt;/span&gt; : &lt;span class="nv"&gt;UINT&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_STAT&lt;/span&gt;
   &lt;span class="nv"&gt;InstanceCount&lt;/span&gt; : &lt;span class="nv"&gt;UINT&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;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="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;; // if TRUE, the retain variables are initialized (warm start / cold start)&lt;/span&gt;
   &lt;span class="nv"&gt;bInCopyCode&lt;/span&gt; : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;;  // if TRUE, the instance afterwards gets moved into the copy code (online change)&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="nv"&gt;THIS&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;.&lt;span class="nv"&gt;InstanceCount&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="nv"&gt;InstanceCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;THIS&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;.&lt;span class="nv"&gt;MotorId&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="nv"&gt;InstanceCount&lt;/span&gt; &lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Instantiation id for a Function Block.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/?limit=25#d138" rel="alternate"/><published>2020-02-27T14:08:41.772000Z</published><updated>2020-02-27T14:08:41.772000Z</updated><author><name>learnetk</name><uri>https://forge.codesys.com/u/learnetk/</uri></author><id>https://forge.codesys.coma8f497d52e33fa43084bb38b96c329d7031e75a3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Scott &lt;/p&gt;
&lt;p&gt;Probably i couldnt explain my issue.&lt;br/&gt;
So i try it again, inside the function block i have a variable which is the Id of the function block, just as shown below&lt;/p&gt;
&lt;p&gt;Function_Block Motor&lt;br/&gt;
var&lt;br/&gt;
 Motor_id : uint;&lt;br/&gt;
end_var&lt;/p&gt;
&lt;p&gt;so if the User of the library has an two Instances of the function block like &lt;/p&gt;
&lt;p&gt;fbMotor1 : Motor;&lt;br/&gt;
fbMotor2 : Motor;&lt;/p&gt;
&lt;p&gt;then i would like the Motor_Id in fbMotor1 to have 1 and Motor_Id in fbMotor2 is 2, or any other number.&lt;/p&gt;
&lt;p&gt;Thanks and warm regards.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Instantiation id for a Function Block.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/?limit=25#bae7" rel="alternate"/><published>2020-02-27T14:08:41.340000Z</published><updated>2020-02-27T14:08:41.340000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comba11a34614a75451e6687091a54da0d1f7465680</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;What is wrong with letting the user define the name when the user uses your FB?&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PROGRAM&lt;/span&gt; &lt;span class="n"&gt;Example&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;Inst1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;YourLibrary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;YourFB&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;Inst2&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;YourLibrary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;YourFB&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;Inst3&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;YourLibrary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;YourFB&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;/div&gt;</summary></entry><entry><title>Instantiation id for a Function Block.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e32f04d73f/?limit=25#c403" rel="alternate"/><published>2020-02-27T14:08:40.400000Z</published><updated>2020-02-27T14:08:40.400000Z</updated><author><name>learnetk</name><uri>https://forge.codesys.com/u/learnetk/</uri></author><id>https://forge.codesys.comcb42e8ecc97b901e94c9155267d1ed87f03649de</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Everyone&lt;br/&gt;
I made a Function Block that would be part of a Library. The user of this library could use as many instances of the said function block which is not known at the time of implementation of the Function Block / Library.&lt;/p&gt;
&lt;p&gt;Is it possible to dynamically create an Id for each instance of the function block that the User creates. Does anyone have an idea how this could be done.&lt;/p&gt;
&lt;p&gt;Thanks and regards&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>