Sysmac Studio Β· NJ/NX Β· custom types

Data Structures

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.

🧱 STRUCT🏷️ ENUMπŸ”€ UNION
01 Β· STRUCT

Bundle a recipe

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.

ml
Nm

        

πŸ’‘ 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.

02 Β· ENUM & UNION

Name your states, overlay your bytes

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.

03 Β· Check yourself

One quick question

You write to myWord.asWord. What happens to myWord.asBytes?