<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent posts to Generic Variables and FDB</title><link>https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/</link><description>Recent posts to Generic Variables and FDB</description><language>en</language><lastBuildDate>Mon, 29 Jun 2026 12:12:04 -0000</lastBuildDate><atom:link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/feed.rss" rel="self" type="application/rss+xml"></atom:link><item><title>Generic Variables and FDB</title><link>https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/?limit=25#56ba</link><description>&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;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">rmarco</dc:creator><pubDate>Mon, 29 Jun 2026 12:12:04 -0000</pubDate><guid isPermaLink="false">https://forge.codesys.com93482aff7b7db9b8e2fa3dc8b1390dc624c6dc87</guid></item></channel></rss>