Deep dive · expands Data Structures

Data types deep

A custom type earns its keep when it maps to a real job: STRUCT for recipes, ENUM for modes. The sharpest of them is the UNION, which lets you read the same bytes two ways. Flip some bits and watch every view update at once.

🔀 UNION overlayWORD ↔ bytes ↔ bits
01 · One memory, three views

Decode a fieldbus word

A drive packs a status word into 16 bits. Type the value or click individual bits. The WORD, the two bytes and the 16 BOOLs are the same memory, so they always agree.

0..65535
asWord (WORD)
-
asBytes[1] · high
-
asBytes[0] · low
-
hex
-

asBits: ARRAY[0..15] OF BOOL (click a bit to toggle it)

02 · The rest of the toolbox

ALIAS, subrange & arrays of structs

TYPE Temperature : REAL; END_TYPE  // ALIAS: clearer intent
TYPE Channel : UINT(1..8); END_TYPE // subrange: range-safe
stations : ARRAY[1..8] OF ST_Station; // a tabulated line

🏷️ ALIAS renames a type so Temperature reads better than a bare REAL. The storage is the same; only the code gets clearer. ALIAS and subrange are IEC 61131-3 derived types, but Sysmac Studio's own derived types are only structures, unions and enumerations.

📏 Subrange bakes limits into the type: a Channel can only be 1–8, so an out-of-range value is caught at the source. On an NJ/NX you set the same limit as a range specification on the variable itself.

03 · Check yourself

One quick question

Why reach for a UNION when decoding a fieldbus register?