Loose variables become a mess fast. Group the ones that belong together into a named shape β a STRUCT β and your code starts to read like the machine it controls.
A bottling line has a recipe: fill volume, cap torque, label flag. Three loose variables, or one tidy ST_Recipe. Edit the fields β the Structured Text writes itself.
π‘ Now Line1.recipe is one variable you pass around, copy, or store as an array of recipes β instead of juggling three. Add a field to the type and every recipe gets it for free.
ENUM β readable states
Instead of "mode = 2", say what you mean. Click a mode:
UNION β one memory, two views
TYPE U_Word : UNION asWord : WORD; // all 16 bits asBytes : ARRAY[0..1] OF BYTE; END_UNION END_TYPE
Both members share the same bytes. Write asWord, read asBytes[0] β perfect for decoding a fieldbus register without bit-shifting by hand.
You write to myWord.asWord. What happens to myWord.asBytes?