<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts by rmarco</title><link href="https://forge.codesys.com/u/rmarco/" rel="alternate"></link><link href="https://forge.codesys.com/u/rmarco/profile/feed.atom" rel="self"></link><id>https://forge.codesys.com/u/rmarco/</id><updated>2026-06-29T12:12:04Z</updated><subtitle>Recent posts by rmarco</subtitle><entry><title>Generic Variables and FDB</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed55a288d0/?limit=25#56ba" rel="alternate"></link><published>2026-06-29T12:12:04Z</published><updated>2026-06-29T12:12:04Z</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>