Tutorials¶
Follow the tutorial sequence from basic editing through runtime, HMI, and deployment workflows.
The tutorial path is ordered for confidence:
- basic ST editing
- control/runtime interaction
- tests and validation
- deployment, observability, HMI, and integration surfaces
Guided Tutorial Path¶
Beginner Structured Text Tutorials (VS Code Guided Path)¶
Docs category: docs/public/examples/tutorials.md
This is the primary onboarding path for learning truST in VS Code.
You will move from simple ST syntax to runtime interaction and unit testing, while intentionally using one VS Code feature per tutorial.
One-Time Setup¶
- Open repository root in VS Code:
code /path/to/trust-platform
- Install extension if needed:
code --install-extension trust-platform.trust-lsp
- Optional confidence check:
cargo test -p trust-runtime tutorial_examples_parse_typecheck_and_compile_to_bytecode
How To Work Through This Path¶
For each tutorial:
- Open the file.
- Read the "VS Code Feature Spotlight" first.
- Follow the guided interaction steps.
- Complete the challenge.
- Trigger one pitfall intentionally, then fix it.
01_hello_counter.st¶
VS Code Feature Spotlight¶
- Diagnostics + squiggles
- Hover tooltips
- Semantic syntax highlighting
Guided Steps¶
- Open
01_hello_counter.st. - Hover
count,step, andenableto inspect inferred types. - Intentionally remove one semicolon and confirm a red diagnostic.
- Restore the semicolon and confirm diagnostics clear.
Challenge¶
- Add
MAX_COUNT : INT := 100;and wrapcountto0whencount > MAX_COUNT.
Common Pitfalls¶
- Missing semicolon after assignment.
- Using
=instead of:=for assignment. - Forgetting
END_IF.
02_blinker.st¶
VS Code Feature Spotlight¶
- Completion for standard FBs (
TON) - Snippet insertion and parameter hints
Guided Steps¶
- Open
02_blinker.st. - Create a temporary line and type
TOthen trigger completion (Ctrl+Space). - Select
TONand inspect inserted call shape. - Hover timer fields (
IN,PT,Q) to inspect semantics.
Challenge¶
- Change period from
T#250mstoT#500msand document expected behavior change.
Common Pitfalls¶
- Writing
250msinstead of typed literalT#250ms. - Forgetting to keep timer call active each cycle.
03_traffic_light.st¶
VS Code Feature Spotlight¶
- Go to definition on enum types/members
- Document outline (
Ctrl+Shift+O)
Guided Steps¶
- Open
03_traffic_light.st. - Place cursor on enum state usage and press
F12(or Ctrl+Click). - Open outline (
Ctrl+Shift+O) and jump between type/program sections.
Challenge¶
- Add a maintenance state and transition into it from a new condition.
Common Pitfalls¶
- Missing enum member in
CASEhandling. - Inconsistent typed-literal style for enum values.
04_tank_level.st¶
VS Code Feature Spotlight¶
- Inlay hints
- Format Document (
Shift+Alt+F)
Guided Steps¶
- Open
04_tank_level.st. - Run Format Document and inspect spacing/alignment changes.
- Enable inlay hints if disabled and review call-site parameter names.
Challenge¶
- Tighten threshold band to reduce output oscillation.
Common Pitfalls¶
- Type mismatch between
INTsensor andREALthreshold math. - Missing
END_IFin nested conditions.
05_motor_starter.st¶
VS Code Feature Spotlight¶
- Find All References (
Shift+F12)
Guided Steps¶
- Open
05_motor_starter.st. - Run Find All References on
motor_run. - Verify all latching/unlatching writes are visible in one place.
Challenge¶
- Add
fault_resetbehavior requiring explicit reset after overload.
Common Pitfalls¶
- Accidental combinational loop in latch logic.
- Forgetting stop/overload precedence.
06_recipe_manager.st¶
VS Code Feature Spotlight¶
- Code folding for
CASEbranches
Guided Steps¶
- Open
06_recipe_manager.st. - Fold all
CASEbranches and expand one-by-one while tracing outputs. - Confirm each branch assigns all required outputs.
Challenge¶
- Add one new recipe ID with full parameter mapping.
Common Pitfalls¶
- Missing default/else behavior.
- Partially assigned outputs in one branch.
07_pid_loop.st¶
VS Code Feature Spotlight¶
- Rename Symbol (
F2)
Guided Steps¶
- Open
07_pid_loop.st. - Rename one control variable (for example
control_output->u_cmd) withF2. - Review rename preview before applying.
Challenge¶
- Add clamping limits to output and anti-windup condition.
Common Pitfalls¶
- Renaming to reserved keyword.
- Breaking semantic meaning by unclear variable names.
08_conveyor_system.st¶
VS Code Feature Spotlight¶
- Signature help during FB calls (
Ctrl+Shift+Space)
Guided Steps¶
- Open
08_conveyor_system.st. - Place cursor inside a call argument list and trigger signature help.
- Validate parameter ordering and intent.
Challenge¶
- Add a jam-reset input that clears jam latch under safe conditions.
Common Pitfalls¶
- Passing wrong parameter order in positional calls.
- Missing safety condition around restart.
09_simulation_coupling.st¶
VS Code Feature Spotlight¶
- Runtime Panel first-use walkthrough
Guided Steps¶
- Open
09_simulation_coupling.st. Ctrl+Shift+P->Structured Text: Open Runtime Panel.- Start runtime (Local mode).
- In I/O panel, write
%IW0below threshold (for exampleWord(300)) and observe alarm output. - Write
%IW0above threshold (for exampleWord(600)) and observe alarm change.
Challenge¶
- Add second alarm level (warning/critical) with two thresholds.
Common Pitfalls¶
- Writing wrong address type (
%Qinstead of%I). - Not starting runtime before writing values.
10_unit_testing_101/¶
VS Code Feature Spotlight¶
- Test Explorer + CodeLens run actions
Guided Steps¶
- Open
10_unit_testing_101/src/tests.st. - Use CodeLens
Run Testabove each test. - Open Testing sidebar (beaker icon) and run all discovered tests.
- Inspect pass/fail indicators and test output details.
Challenge¶
- Add one failing assertion intentionally, run tests, then fix it (red-green cycle).
Common Pitfalls¶
- Writing tests in
PROGRAMinstead ofTEST_PROGRAM/TEST_FUNCTION_BLOCK. - Forgetting deterministic setup per test case.
11_unit_testing_102/¶
VS Code Feature Spotlight¶
- Test Explorer triage + focused reruns
Guided Steps¶
- Open
11_unit_testing_102/src/tests.st. - Run all tests from Testing sidebar.
- Break one expected value intentionally.
- Re-run failed test only from sidebar.
- Restore fix and verify green state.
Challenge¶
- Extend mock I/O test matrix with one new operating-band scenario.
Common Pitfalls¶
- Testing hardware-mapped
PROGRAMdirectly instead of FB logic. - Carrying test state between scenarios.
12_hmi_pid_process_dashboard/¶
VS Code Feature Spotlight¶
- HMI descriptor workflow (
hmi/*.toml) - Process SVG page rendering (
kind = "process") - Live descriptor refresh for TOML + SVG edits
Guided Steps¶
- Open
12_hmi_pid_process_dashboard/README.md. - Build and run the tutorial project.
- Open
/hmiand verify operator pages: Operator OverviewP&ID ProcessP&ID BypassTrendsAlarms- Toggle
%IX0.0/%IX0.1/%IX0.2/%IX0.3to drive start/stop/spike/bypass scenarios. - Verify setpoint, deviation, and alarm widgets update in overview + process pages.
- Edit
hmi/plant.tomland swapplant.svg<->plant-minimal.svg; save and verify live refresh. - Capture one screenshot/GIF using the tutorial media commands.
Challenge¶
- Add one extra instrument ID in
hmi/plant-bypass.svgand bind it fromP1inhmi/plant-bypass.toml.
Common Pitfalls¶
- Selector IDs in
[[bind]]not matching SVG element IDs. - Using unsupported process selectors (must be
#idstyle). - Renaming PLC symbols without updating HMI bind paths.
Advanced Operations Tutorials (13-23)¶
After finishing Tutorials 01-12, continue with these production-oriented walkthroughs. Each guide is intentionally detailed and explains both what to do and why it matters.
13_project_bootstrap_zero_to_first_app/README.md- start from an empty folder and build a first runnable PLC project.
14_deploy_and_rollback/README.md- practice versioned deployment and controlled rollback.
15_multi_plc_discovery_mesh/README.md- run two runtimes, verify discovery/pairing, and enable mesh sharing.
16_secure_remote_access/README.md- configure TCP control with auth token, pairing, and minimal firewall exposure.
17_io_backends_and_multi_driver/README.md- configure
loopback,simulated,gpio,modbus-tcp,mqtt, and composedio.drivers. 18_simulation_toml_fault_injection/README.md- use deterministic
simulation.tomlcouplings/disturbances/fault events. 19_safety_commissioning/README.md- verify safe-state outputs, watchdog/fault policy, and restart recovery.
20_hmi_write_enablement/README.md- move HMI from read-only to constrained write mode with explicit allowlist.
21_ci_cd_project_pipeline/README.md- implement CI gates with machine-readable reports and stable exit codes.
22_neovim_zed_workflow/README.md- run a complete non-VS-Code workflow with Neovim/Zed plus terminal gates.
23_observability_historian_prometheus/README.md- enable historian + Prometheus telemetry and verify runtime observability contracts.
Suggested sequence for operations engineers:
13_project_bootstrap_zero_to_first_app/README.md17_io_backends_and_multi_driver/README.md18_simulation_toml_fault_injection/README.md19_safety_commissioning/README.md14_deploy_and_rollback/README.md16_secure_remote_access/README.md15_multi_plc_discovery_mesh/README.md20_hmi_write_enablement/README.md21_ci_cd_project_pipeline/README.md22_neovim_zed_workflow/README.md23_observability_historian_prometheus/README.md
Communication Protocol Examples (Grouped)¶
For protocol-first commissioning, use:
../communication/README.md- includes dedicated subfolders for:
modbus_tcpmqttopcuaethercatethercat_field_validated_esgpiomulti_driver
- each subfolder includes a runnable minimal project and step-by-step flow.
Transport gating reminders:
- EtherCAT hardware transport is gated by
ethercat-wireand unix-only for non-mockadapters. - OPC UA wire server is gated by
opcua-wire.
Validation Coverage¶
Current regression coverage verifies:
- parse/type-check/bytecode compile of tutorial sources,
- deterministic runtime behavior for selected scenarios,
- no unexpected LSP diagnostics on tutorial files.