<< Click to Display Table of Contents >> Navigation: »No topics above this level« Statements |
mapp Services V5.16
The statements used for the coroutines are explained in this section.
A coroutine can be created from a function definition using statement "Create".
Syntax:
handle := COROUTINE_CREATE(function_def [,‘coroutine_name’,(arg1, arg2 …)]);
Arguments:
•function_def: Specifies the function definition used to create a coroutine.
•coroutine_name: The argument can optionally be specified. This argument can be used to assign a name to the coroutine. This can help the user to distinguish one coroutine from another.
•(arg1, arg2, ...): If command line parameters were defined in the function definition, these can be specified at the end. If no command line parameters are used when creating the coroutine, the values defined in the function definition are used.
Return value:
•handle: If the coroutine was created, a handle is returned. This identifies the created coroutine. The handle can be used to start, resume, stop and delete the coroutine.
A coroutine is started via statement "Resume" or resumed if paused via statement "Yield". The statement can also be called within a coroutine to start another coroutine. In this case, the original routine is in the waiting state.
Syntax:
return_value := COROUTINE_RESUME(handle [, (arg1, arg2 …)] );
Arguments:
•handle: The handle of the desired routine that should be started or resumed must be specified.
•(arg1, arg2 ...): These optional arguments can be used to again specify the parameters of the coroutine that were previously defined by statement "Create", for example. If no arguments are defined, then the last parameter set is used.
Return value:
•return_value: Statement "Resume" can be used to obtain a return value. The return value is only displayed after the coroutine has been paused by statement "Yield" or completed execution. A return value can only be received if the coroutine has a return value. If the function from which the coroutine was created is defined with "NONE", no return value can be received:
FUNCTION myCoroutineDef : NONE
...
...
END_FUNCTION
The execution of a coroutine can be interrupted by calling statement "Yield". The coroutine can be executed again via statement "Resume".
The statement is used within a coroutine to jump back to the main program.
Syntax:
COROUTINE_YIELD([arg]);
Arguments:
•arg: With this optional argument, a return value can be transferred to statement "Resume". If no argument is defined, the currently assigned return value of the coroutine is used.
If a coroutine has completed execution, it must be deleted afterwards. This can be indicated by statement "State". A routine that has completed execution has state 4. The coroutine can no longer be enabled or started in is state and is therefore unusable and must be deleted.
A coroutine can also be deleted in state 1. In this case, the coroutine has been created but not yet enabled. If a condition in the program was not fulfilled, for example, the created routine is not necessary and can therefore be deleted.
Syntax:
COROUTINE_DELETE(handle);
Arguments:
•Handle: The handle of the desired coroutine created by statement "Create" must be specified.
"State" statements can be used to determine the current state of the coroutine.
Syntax:
state := COROUTINE_STATE(handle);
Arguments:
•Handle: The handle of the desired coroutine created by statement "Create" must be specified.
Return value:
The return value of the statement is of data type UDINT and specifies the state of the coroutine. The following return values are possible.
•0: The requested coroutine does not exist (Undefined).
•1: Coroutine was created but is not currently active (Suspended).
•2: Coroutine is currently being executed (running).
•3: Another coroutine was called within the coroutine. The original coroutine is in the waiting state (Wait).
•4: Coroutine was terminated. To restart the same routine again, it must first be deleted with statement "Delete" (Dead).