Appearance
Core Concepts
Before diving deeper into the language, it is important to understand the fundamental principles of Coldwave Script. These differ significantly from classic high-level languages. Once these concepts are internalized, programs become easier to read, write, and—most importantly—predict, which is essential for control software.
Programs, Blocks, Variables
Coldwave Script consists of three primary building elements:
- Programs contain execution flow and logic. Each script has exactly one
PROGRAM … END PROGRAMblock. - Function blocks such as
TON(timer) orCTU(counter). They have inputs, outputs, and internal state. - Variables & constants store data. Variables are declared with
DIM, constants withCONST.
Example:
vb
PROGRAM
DIM T AS TON
DIM counter AS INT = 0
T(IN = TRUE, PT = T#1000ms)
counter = counter + 1
PRINT counter, T.Q
END PROGRAMA key syntactic distinction:
- Assignments inside a program use
=. - Connecting signals to block inputs uses the connection operator
:=.
A detailed explanation with examples can be found in the chapter Functions & Blocks under
Parameter Passing (IN/OUT) and the Operators = / :=.
Memory Segments
Coldwave Script separates data into four logical areas:
| Segment | Purpose | Typical examples |
|---|---|---|
IN | Reading inputs | Sensor values, fieldbus registers, block inputs |
OUT | Writing outputs | Relays, LEDs, actuators, block outputs |
TMP | Temporary working values | Intermediate calculations, scratch space |
CONST | Fixed values | Parameters, thresholds, project configuration |
For practical use:
- Anything coming from the outside is read through
IN. - Anything acting on the outside is written through
OUT. - Pure computational values exist as normal variables; the VM places them internally in
TMP. CONSTvalues are fixed at compile/deployment time and do not change at runtime.
Details on internal addressing and banking are only relevant to integrators and documented in the internal architecture chapters.
Lifetime of Variables and Blocks
Coldwave Script executes cyclically. Each cycle:
- Input values (
IN) are acquired from hardware or fieldbus. - The program runs once from top to bottom.
- Output values (
OUT) are written to hardware or fieldbus.
Important to understand:
- Program-internal variables (
DIM) retain their values across cycles as long as the script runs. - Function blocks (e.g.
TON,CTU, or customBLOCKs) retain state across cycles. Time counters, edge detections, etc. do not reset every cycle. CONSTvalues are fixed configuration parameters.
On VM restart or device reboot, all non-persistent values are reset to their initial state.
Data Types
Coldwave Script supports the following data types:
| Type | Example | Notes |
|---|---|---|
| BOOL | TRUE / FALSE | logical values |
| INT | 42 | saturating (−32768 … +32767) |
| UINT | 65000 | lower bound 0, no negative result |
| DINT | 2147483647 | saturating, 32-bit |
| REAL | 3.14, 1.2E3 | IEEE-754 floating point |
| LREAL | 1.0E100 | double precision |
| TIME | T#500ms | time spans in milliseconds |
| DATE | DATE#2025-01-01 | calendar date |
| TOD | TOD#12:00:00 | time of day |
| DT | DT#2025-01-01-12:00:00 | date + time |
| STRING | "Hello" | UTF-8 string |
Specifics:
- Saturating arithmetic:
INT + INTexceeding 32767 → 32767. - Promotion: mixed types are promoted (INT + REAL → REAL).
- Time values: all TIME internally stored as milliseconds.
Example:
vb
PROGRAM
DIM a AS INT = 32000
DIM b AS INT = 1000
PRINT a + b ' Output: 32767 (saturated)
PRINT TO_REAL(a) / 2 ' Output: 16000.0
END PROGRAMExecution Model (Prefeed, Main Loop, Cycle)
Programs run in cycles. Each cycle contains three phases:
+-----------+ +------------------+ +---------+
| Prefeed | --> | Main Execution | --> | Commit |
+-----------+ +------------------+ +---------+- Prefeed: Inputs (
IN) are acquired and initial values prepared. - Main execution: Statements and blocks run in sequence; temporary (
TMP) values are used. - Commit:
OUTvalues are written to real outputs.
Example:
vb
DIM T AS TON
PROGRAM
T(IN = TRUE, PT = T#1000ms)
PRINT T.Q
END PROGRAMExecution sequence:
- Prefeed: timer input
INis sampled. - Main: timer increments
ETand computesQ. - Commit: output is applied if
Q = TRUE.
Summary
- Programs contain logic, blocks hold state, variables hold data.
- Segments separate IN, OUT, TMP, CONST for safety and clarity.
- Integer arithmetic is saturating; mixed types are promoted.
- Cycle model: Prefeed → Main → Commit ensures deterministic behavior.