<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Generic Variables and FDB</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/</id><updated>2026-07-22T19:51:10.827000Z</updated><subtitle>Recent posts to Generic Variables and FDB</subtitle><entry><title>Generic Variables and FDB</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/?limit=50#5e32" rel="alternate"/><published>2026-07-22T19:51:10.827000Z</published><updated>2026-07-22T19:51:10.827000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com64bf6d99ff96fc01c335995f64bd3e1cf9ddd792</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I also ran into this, try using Coil&amp;lt;1&amp;gt; as the type in the FBD box.  From what I understand, with VAR_GENERIC CONSTANT, the compiler creates separate data types for each different function block declaration.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Generic Variables and FDB</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/?limit=25#61ad" rel="alternate"/><published>2026-07-09T07:15:54.278000Z</published><updated>2026-07-09T07:15:54.278000Z</updated><author><name>salvatorethomas</name><uri>https://forge.codesys.com/u/salvatorethomas/</uri></author><id>https://forge.codesys.com0beea172dd9347551b24bf8b686d7fdbc74bb8c9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Marco,&lt;/p&gt;
&lt;p&gt;What you are seeing looks less like a coding mistake and more like a limitation or bug in the FBD editor parser when handling VAR_GENERIC CONSTANT specializations. The fact that the same FB works correctly in ST and only fails when instantiated on the FBD canvas strongly suggests that the graphical editor is not resolving the generic parameterized type correctly.&lt;/p&gt;
&lt;p&gt;One thing I would try is creating a non-generic wrapper FB around your specialized instance and exposing the required methods through that wrapper. In other words, keep the generic implementation in ST, but let FBD interact with a concrete FB type that has a fixed maxEvents value. Several IEC 61131-3 environments handle generic FBs correctly in ST but struggle with their graphical representation in FBD.&lt;/p&gt;
&lt;p&gt;Another possibility is that the editor expects the specialization to be defined through a type alias rather than directly in the instance declaration. If your environment supports it, something like:&lt;/p&gt;
&lt;p&gt;TYPE Coil5 : CDL.Coil(maxEvents := 1); END_TYPE&lt;/p&gt;
&lt;p&gt;VAR coil1 : Coil5; END_VAR&lt;/p&gt;
&lt;p&gt;may avoid the parser issue because FBD only sees a concrete type.&lt;/p&gt;
&lt;p&gt;Given that auto-completion and compilation work while the FBD instance name fails, I would definitely report this as an editor bug to the vendor. Your workaround through ST is valid, but the wrapper or type-alias approach may let you keep the logic fully compatible with FBD.&lt;/p&gt;
&lt;p&gt;Hope this helps, and please let us know if the type-alias approach works in your setup. &lt;a href="https://slope2-game.com" rel="nofollow"&gt;Slope 2&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Generic Variables and FDB</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/?limit=25#56ba" rel="alternate"/><published>2026-06-29T12:12:04.284000Z</published><updated>2026-06-29T12:12:04.284000Z</updated><author><name>rmarco</name><uri>https://forge.codesys.com/u/rmarco/</uri></author><id>https://forge.codesys.com93482aff7b7db9b8e2fa3dc8b1390dc624c6dc87</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello everyone,&lt;/p&gt;
&lt;p&gt;I am running into a highly frustrating issue in the FBD editor regarding a Function Block with generic constants (&lt;strong&gt;VAR_GENERIC CONSTANT&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;I created a FB using ST, with a generic var, useful for having a variable sized array, as follows:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;FUNCTION_BLOCK&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Coil&lt;/span&gt;
&lt;span class="nt"&gt;VAR_GENERIC&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;CONSTANT&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;maxEvents&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;USINT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&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="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;events&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&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;0&lt;/span&gt;&lt;span class="bp"&gt;..&lt;/span&gt;&lt;span class="nx nx-Member"&gt;maxEvents&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;OF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;IEvent&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;These FBs have also several methods. I declare them as follows in code:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;VAR&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;coil1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;CDL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Coil&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;(&lt;/span&gt;&lt;span class="nt"&gt;maxEvents&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&amp;gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and when using them in ST, I have no problems. However, when trying to use them in FDB, I do not know how to do that, as some strange misalignment happens.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Here's what happens:&lt;/strong&gt;&lt;br/&gt;
When I add the block to my FBD canvas and assign coil1 as the instance name, the compiler throws this error:&lt;br/&gt;
'coil1' is not an instance of 'CDL.Coil&amp;lt;(maxEvents:=1)&amp;gt;'.&lt;/p&gt;
&lt;p&gt;Same occurs when I try to instantiate blocks such as 'coil1.turnOn' or similar.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Here is what I have already tried, none of which worked:&lt;/strong&gt;&lt;br/&gt;
- Deleting the &amp;lt;(maxEvents:=1)&amp;gt; parameter from the text inside the FBD box.&lt;br/&gt;
- Deleting the block entirely, dropping an "Empty Box", and typing coil1 above it to let the IDE auto-complete and format the block.&lt;br/&gt;
- Running a full "Clean All" and rebuilding the code.&lt;/p&gt;
&lt;p&gt;I am aware that I could bypass the graphical editor by calling it in Structured Text. However, I need to keep this logic compatible to FBD.&lt;/p&gt;
&lt;p&gt;Has anyone encountered this specific FBD parsing bug with generic variables?&lt;/p&gt;
&lt;p&gt;Thanks in advance for any insights.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Best regards,&lt;/strong&gt;&lt;br/&gt;
Marco&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>