DCode

Covers Engine 2.0.0

Sequences and Task Lifecycle

Run ordered steps and control task start, hold, stop, and persistent state.

Use a sequence for ordered work with a visible source-line position. Use periodic tasks for repeated sampling and state machines for named operating phases.

Run a sequence

Save and activate this script, then start docs_demo_steps in the task resource:

task_sequence docs_demo_steps:
    |docs_demo_step| = 1
    sleep 1.0
    |docs_demo_step| = 2
    sleep 1.0
    |docs_demo_step| = 3

The sequence reports its current DCode source line through docs_demo_steps_current_line. sleep expresses a delay in seconds, not a hardware timing guarantee. The scheduler and operating system determine when execution resumes.

Shared task controls

A task named docs_demo_steps creates the following channels:

SuffixPurpose
_runningWrite 1 to start or 0 to stop.
_holdWrite 1 to hold execution; write 0 to release the hold.
_target_frequencyRequested scheduler frequency in Hz; defaults to 10.
_actual_frequencyObserve-only measured frequency; zero while stopped.

These controls also apply to periodic and state-machine tasks. A hold pauses execution without being an output reset. Stopping releases the task’s automatic channel ownership, but the last stored output value is not itself a physical stop command. Put final actions in an end: section or driver shutdown path as appropriate to your application.

Keep state between calls

Store per-task values in state. Initialize them in start: when they should reset on every run:

task_periodic docs_demo_count:
    start:
        state.count = 0

    task elapsed_seconds:
        state.count = state.count + 1
        |docs_demo_count_value| = state.count

Use local for temporary values inside a body or function. Bare module assignments and imported helper state can be shared by callers; they are not a substitute for each task’s own state.

Lightweight loops

A named loop starts when its script is activated:

loop docs_demo_copy 2:
    |docs_demo_copy_value| = |docs_demo_count_value|

This requests two iterations per second. Use a full task when an operator needs the task resource’s lifecycle controls and status. Loops are still scheduled work, not inline dependency reactions; use a channel calculation for immediate derivation.

See Managing Tasks for operation and Engine Tasks for scheduler structures, missed releases, and native tasks.