Is it possible to iterate through all tasks without any information of the tasks?

I am trying to create a function where I check if all tasks are running or not, but I cant find a way to iterate through all tasks.

I am thinking something like this
<div>&nbsp; &nbsp; &nbsp; &nbsp; FOR taskNo FROM 1 TO 20 DO</div><div>            IF NOT TaskIsExecuting(taskNo) RETURN FALSE;<br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; ENDFOR</div>
but the TaskIsExecuting-function does not take a number as input.

I'd rather not use the ReadCfgData to analyze the systemparameters if not absolutely neccecary.
//Markus Näslund


  • lemster68
    lemster68 United States ✭✭✭
    TaskIsExecuting("T_Rob" + NumToStr(TaskNo,0))
    Lee Justice
  • SomeTekk
    SomeTekk USA
    edited March 2020
    It is suggested to try an array with the task names.

    CONST string stTaskNames {5}:= ["T_ROB1", ... T_TaskX"];

    FOR index FROM 1 to dim(stTaskNames,1) DO

    IF NOT TaskIsExecuting(stTaskNames {index}) RETURN FALSE

  • Thank for your suggestions, but unfortunately I don't know anything about the present tasks at "compile-time" so I cannot use the array-solution.
    Also, I cannot take for granted that the tasks are named in a certain way so to build the tasknames is not an option.

    //Markus Näslund
  • lemster68
    lemster68 United States ✭✭✭
    It sounds then like you are going to have to go with ReadCfgData.
    Lee Justice
  • Micky
    Micky Germany ✭✭✭

    I agree with lemester68 to use the ReaedCfgData, but it is not possible to search directly for the names of the tasks, because you could only search for the value of a string parameter in the configuration data.

    The following code searches only for all normal tasks in the system:
    LOCAL PROC GetTaskName()
        VAR num nListIndex;
        VAR string stTaskName;
        !read all normal task names from sys.cfg
        WHILE nListIndex<>END_OF_LIST DO
          ReadCfgData "/SYS/CAB_TASKS/Type/NORMAL","Name",stTaskName\ListNo:=nListIndex;
          TPWrite "Task name: "+stTaskName;
    If you want to search for all task types you have to add a search for the static and semi-static tasks.

  • Thanks for your suggestion. I have already considered this but I was looking for an "easier" way. Something like GetTaskName 1; would give me the name of task 1. 
    //Markus Näslund