Wait mode

Via the wait mode options of the JavaScript action, the TwinCAT HMI framework can be informed whether the stored logic works synchronously or asynchronously; it is used to determine when the TwinCAT HMI framework considers execution to be finished.

Wait mode 1:

Synchronous

The execution of the action is considered finished when the last line of JavaScript source code has been processed synchronously. If an exception occurs during execution, the error branch of the JavaScript action is executed. If the execution completed without errors, the success branch of the JavaScript action is executed.

The Wait for completion option has no effect for a synchronous logic. "Parallel" execution of synchronous logic, even in parts, is not possible.

Asynchronous

The execution of the action is considered completed if this has been signaled using the corresponding functions of a context object. If Inject context object is checked, an object with the name "ctx" is inserted into the context of the JavaScript block. This object contains functions for communicating the execution result.

If the success function is called, the success branch of the JavaScript action is executed. If the error function is called, the error branch of the JavaScript action is executed. The error branch of the JavaScript action is also executed if an exception occurs during execution.

With asynchronous logic, the Wait for completion option can be used to control whether the execution result is to be awaited when the subsequent actions are executed or whether they are to be executed in parallel with the JavaScript action.