<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to For with Function BLOCK</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d6469fbfc2/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d6469fbfc2/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/d6469fbfc2/</id><updated>2022-02-25T17:32:43.524000Z</updated><subtitle>Recent posts to For with Function BLOCK</subtitle><entry><title>For with Function BLOCK</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d6469fbfc2/?limit=25#105c" rel="alternate"/><published>2022-02-25T17:32:43.524000Z</published><updated>2022-02-25T17:32:43.524000Z</updated><author><name>peterned</name><uri>https://forge.codesys.com/u/peterned/</uri></author><id>https://forge.codesys.comd8f1ca86f872bfce7a8f0e9b7fd9b2808c2a196d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;if the IF condition is not satisfied, it's simply skipped and the FOR loop continues with the next iteration. So you call cmd_LinuxSysCallAsync() in 5 successive scans.&lt;br/&gt;
Try to do in with steps with a CASE, e.g.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;CASE&lt;/span&gt; &lt;span class="nt"&gt;x&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt;
&lt;span class="nt"&gt;10&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; 
    &lt;span class="nt"&gt;count&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;20&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nt"&gt;20&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="nt"&gt;cmd_LinuxSysCallAsync&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;xExecute&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;TRUE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;sCommand&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'touch txt.txt'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="nt"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;30&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nt"&gt;30&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; 
    &lt;span class="nt"&gt;if&lt;/span&gt; &lt;span class="nt"&gt;cmd_LinuxSysCallAsync&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;xDone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nt"&gt;TRUE&lt;/span&gt; &lt;span class="nt"&gt;THEN&lt;/span&gt;
        &lt;span class="nt"&gt;do_something&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nt"&gt;count&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;count&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;if&lt;/span&gt; &lt;span class="nt"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nt"&gt;5&lt;/span&gt; &lt;span class="nt"&gt;then&lt;/span&gt; 
            &lt;span class="nt"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;40&lt;/span&gt;&lt;span class="o"&gt;;//&lt;/span&gt;&lt;span class="nt"&gt;exit&lt;/span&gt;
        &lt;span class="nt"&gt;else&lt;/span&gt;
            &lt;span class="nt"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;20&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nt"&gt;end_if&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;end_if&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nt"&gt;40&lt;/span&gt;&lt;span class="o"&gt;://&lt;/span&gt;&lt;span class="nt"&gt;end&lt;/span&gt;
    &lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nt"&gt;END_CASE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>For with Function BLOCK</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d6469fbfc2/?limit=25#47a3" rel="alternate"/><published>2022-02-23T14:43:41.975000Z</published><updated>2022-02-23T14:43:41.975000Z</updated><author><name>libi</name><uri>https://forge.codesys.com/u/libi/</uri></author><id>https://forge.codesys.com63e4715f401b031594e11ef012cc51ec3cd40d48</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;hello,&lt;/p&gt;
&lt;p&gt;I currently am doing something that i need a for loop with a 2 function block named LinuxSysCallAsync and WriteCSVData_Linear and when i do it the functions block don't have time to finish executing their code and i don't know how to do it here an example :&lt;/p&gt;
&lt;p&gt;FOR i := 1 TO 5 BY 1 DO&lt;br/&gt;
cmd_LinuxSysCallAsync(xExecute:=TRUE,sCommand('touch txt.txt')&lt;br/&gt;
if cmd_LinuxSysCallAsync.xDone = TRUE THEN&lt;br/&gt;
    do something&lt;br/&gt;
end_if&lt;br/&gt;
END_FOR&lt;br/&gt;
and it cannot by done &lt;/p&gt;
&lt;p&gt;Can someone help me&lt;br/&gt;
Cordially&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>