Skip to content

Pragmas

A pragma is a { … } annotation that attaches metadata to a declaration without changing its data type. logiccloud supports two kinds: the access pragma on variable declarations and the JSON pragma on struct elements.

The access pragma is written after a variable declaration and controls how that variable is exposed to connectors and the HMI, and how it behaves on reset.

VAR
speed : REAL { IN HMI };
state : INT { OUT RESET_TO 0 };
setpoint: REAL { IN_OUT INTERNAL };
END_VAR
KeywordMeaning
INExpose the variable as an input access variable.
OUTExpose the variable as an output access variable.
IN_OUTExpose as both input and output (two access variables generated).
HMIMake the access variable visible in the HMI.
INTERNALMark as internal use only (not used in connectors; typically HMI-only values).
RESET_TO <const>On program reset, reset the variable to a constant value.
NO_RESETDo not reset the variable on program reset.
RESET_DEFAULTReset the variable to its default value on program reset (the default policy).

A pragma names one direction (IN, OUT or IN_OUT), optionally INTERNAL and/or HMI, and — for OUT / IN_OUT — an optional reset policy. The reset keywords are mutually exclusive.

VAR
sensor : BOOL { IN HMI }; // HMI-visible input
alarm : BOOL { OUT HMI NO_RESET }; // retained across resets
gain : REAL { OUT RESET_TO 1.0 }; // reset to 1.0
scratch: INT { OUT INTERNAL }; // internal, not a connector
END_VAR

A struct element can carry a { JSON … } pragma that controls how that element is serialized to / deserialized from JSON.

TYPE
Reading : STRUCT
id : DINT;
value : REAL { JSON "measurement" }; // rename the JSON field
debugInfo : STRING { JSON IGNORE }; // omit from JSON entirely
note : STRING { JSON OMIT_EMPTY }; // drop when empty
label : STRING { JSON "tag" OMIT_EMPTY };// rename and omit when empty
END_STRUCT;
END_TYPE
FormEffect
{ JSON IGNORE }The element is excluded from JSON serialization.
{ JSON "name" }Use "name" as the JSON field name instead of the element name.
{ JSON OMIT_EMPTY }Omit the element from the JSON output when it holds an empty/zero value.
{ JSON "name" OMIT_EMPTY }Combine a custom field name with omit-when-empty.