<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Default function inputs</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/7fe64470de/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/7fe64470de/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/7fe64470de/</id><updated>2020-02-27T22:09:30.526000Z</updated><subtitle>Recent posts to Default function inputs</subtitle><entry><title>Default function inputs</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/7fe64470de/?limit=25#ebfc" rel="alternate"/><published>2020-02-27T22:09:30.526000Z</published><updated>2020-02-27T22:09:30.526000Z</updated><author><name>Svekke</name><uri>https://forge.codesys.com/u/svekke/</uri></author><id>https://forge.codesys.comf5a08c375057cae6ea0e17bfcb65310ef49130f2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm using CoDeSys v3.3&lt;/p&gt;
&lt;p&gt;It indeed works for Function Blocks ... Thanks ! However, I need to explicitely pass the input name in the FB call ...```&lt;/p&gt;
&lt;p&gt;mfb(nValue:=99);&lt;/p&gt;
&lt;p&gt;```&lt;/p&gt;
&lt;p&gt;Tried the same now with a method but then I get a compile error that tells me the method requires exactly 2 inputs  &lt;/p&gt;
&lt;p&gt;Any idea on that ?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Default function inputs</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/7fe64470de/?limit=25#0459" rel="alternate"/><published>2020-02-27T22:09:26.272000Z</published><updated>2020-02-27T22:09:26.272000Z</updated><author><name>bschuster</name><uri>https://forge.codesys.com/u/bschuster/</uri></author><id>https://forge.codesys.com1ccee5b738836e8f4762c4377248fd889851a2e4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I do not have the problem&lt;/p&gt;
&lt;p&gt;Please add a Function_Block to your project&lt;/p&gt;
&lt;p&gt;FUNCTION_BLOCK My_FB&lt;/p&gt;
&lt;p&gt;VAR_INPUT&lt;/p&gt;
&lt;p&gt;nValue : INT;&lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;VAR_INPUT CONSTANT&lt;/p&gt;
&lt;p&gt;nStep: INT := 1;&lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;VAR&lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;Code is only a ;&lt;/p&gt;
&lt;p&gt;Declare a instance in the PLC_PRG&lt;/p&gt;
&lt;p&gt;VAR&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;mfb&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;My_FB&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;And use it with mfb();&lt;/p&gt;
&lt;p&gt;Set a BP to mfb()&lt;/p&gt;
&lt;p&gt;And step into with F8&lt;/p&gt;
&lt;p&gt;There you’ll see nStep is 1&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Default function inputs</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/7fe64470de/?limit=25#0a49" rel="alternate"/><published>2020-02-27T22:09:24.696000Z</published><updated>2020-02-27T22:09:24.696000Z</updated><author><name>Svekke</name><uri>https://forge.codesys.com/u/svekke/</uri></author><id>https://forge.codesys.combca8b1a22d753496d8b1fc7ab872c32b5661aaa4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The default argument causes default method operation. All method calls that require default operation then need to pass the default argument. A lot simpler and safer if you can omit it as in C++, no ? Thx !&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Default function inputs</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/7fe64470de/?limit=25#685f" rel="alternate"/><published>2020-02-27T22:09:20.430000Z</published><updated>2020-02-27T22:09:20.430000Z</updated><author><name>spfeif</name><uri>https://forge.codesys.com/u/spfeif/</uri></author><id>https://forge.codesys.com2e31ed8655485b7a036e91fdb465b7d5b138acaf</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;it is possible with a FB by using an initial value to the input variable definition like Input :Byte := 4;, But not possible with a FUN that I am aware of, CoDeSys will not compile if the input to a function is not connected to a variable. Why do you need to do this?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Default function inputs</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/7fe64470de/?limit=25#53d7" rel="alternate"/><published>2020-02-27T22:09:18.863000Z</published><updated>2020-02-27T22:09:18.863000Z</updated><author><name>Svekke</name><uri>https://forge.codesys.com/u/svekke/</uri></author><id>https://forge.codesys.com2fcb795a5e58e4a7b64d7bf4be67aaea5a9ef316</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;As it's possible in e.g. C++ to  have default function arguments, I'm now wondering if this is also possible in CoDeSys ?&lt;/p&gt;
&lt;p&gt;C++ example&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;Increase&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;nValue&lt;/span&gt;, &lt;span class="nv"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;nStep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;{&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;nValue&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nv"&gt;nStep&lt;/span&gt;&lt;span class="c1"&gt;;};&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Following function calls are both valid ...&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="n"&gt;nTest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;Increase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nTest&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="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;nTest&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;incremented&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;Increase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nTest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&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="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;nTest&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;incremented&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In the CoDeSys help I found info about VAR_INPUT CONSTANT, but if I try this I get compile errors when calling the method with not all inputs filled in.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;METHOD&lt;/span&gt; &lt;span class="nt"&gt;mnIncrease&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt;
&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;nValue&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&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_INPUT&lt;/span&gt; &lt;span class="nt"&gt;CONSTANT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;nStep&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&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;;&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="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;----------------------------&lt;/span&gt;
&lt;span class="nt"&gt;mnIncrease&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;nValue&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nt"&gt;nStep&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;----------------------------&lt;/span&gt;
&lt;span class="nt"&gt;mnIncrease&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;nTest&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;nTest&lt;/span&gt; &lt;span class="nt"&gt;is&lt;/span&gt; &lt;span class="nt"&gt;incremented&lt;/span&gt; &lt;span class="nt"&gt;with&lt;/span&gt; &lt;span class="nt"&gt;5&lt;/span&gt;
&lt;span class="nt"&gt;mnIncrease&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;nTest&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;generates&lt;/span&gt; &lt;span class="nt"&gt;compile&lt;/span&gt; &lt;span class="nt"&gt;error&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Does anyone have an idea if my idea is possible ?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>