For with Function BLOCK

libi
2022-02-23
2022-02-25
  • libi - 2022-02-23

    hello,

    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 :

    FOR i := 1 TO 5 BY 1 DO
    cmd_LinuxSysCallAsync(xExecute:=TRUE,sCommand('touch txt.txt')
    if cmd_LinuxSysCallAsync.xDone = TRUE THEN
    do something
    end_if
    END_FOR
    and it cannot by done

    Can someone help me
    Cordially

     
  • peterned - 2022-02-25

    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.
    Try to do in steps with a CASE, e.g.

    CASE x OF
    10: 
        count := 0;
        x := 20;
    
    20:
        cmd_LinuxSysCallAsync(xExecute:=TRUE,sCommand('touch txt.txt');
        x := 30;
    
    30: 
        if cmd_LinuxSysCallAsync.xDone = TRUE THEN
            do_something();
            count := count + 1;
            if count >= 5 then 
                x := 40;//exit
            else
                x := 20;
            end_if;
        end_if;
    
        40://end
        ;
    
    END_CASE;
    
     

    Last edit: peterned 2022-02-25

Log in to post a comment.