Custom types earn their keep when they map to a real job. STRUCT for recipes, ENUM for modes, and the sharpest tool of all β the UNION, which lets you read the same bytes two ways. Flip some bits and watch every view update at once.
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.
asBits β ARRAY[0..15] OF BOOL (click to toggle)
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 β same storage, clearer code.
π Subrange bakes limits into the type: a Channel can only be 1β8, so an out-of-range value is caught at the source.
Why reach for a UNION when decoding a fieldbus register?