Skip to content

ST Examples

Every channel in IO Mapping is exposed as a global variable through its DefaultMapping name: IN0–IN6, OUT0–OUT5, AN0–AN2 and LED are usable directly, with no declaration and no mapping.

LED is a DWORD in 0x00RRGGBB form, not a bit:

PROGRAM PLC_PRG
VAR
blinker : TON;
xOn : BOOL;
END_VAR
blinker(IN := NOT blinker.Q, PT := T#500ms);
IF blinker.Q THEN
xOn := NOT xOn;
IF xOn THEN
LED := 16#00FF0000; // red
ELSE
LED := 0; // off
END_IF
END_IF

Full brightness is harsh at close range; 16#00200000 is plenty for an indicator.

PROGRAM PLC_PRG
IF xFault THEN
LED := 16#00FF0000; // red
ELSIF xConnected THEN
LED := 16#0000FF00; // green
ELSE
LED := 16#00FFA000; // amber: running, not connected
END_IF
PROGRAM PLC_PRG
OUT0 := IN0;
OUT1 := IN1;
OUT2 := IN2;
OUT3 := IN3;
OUT4 := IN4;
OUT5 := IN5;
PROGRAM PLC_PRG
OUT0 := AN0 > 2048; // raw 12-bit count, 0...4095 over 0...3.3 V

There is no TEMPERATURE channel on this board — see IO Mapping.

The complete pattern, including the GVL with the located variables, is on the Modem page:

CASE nStep OF
0: GVL.sOut := 'AT+CFUN?';
GVL.wSend := 1;
nStep := 1;
1: GVL.wSend := 0;
nStep := 2;
2: IF GVL.wInLen > 0 THEN
sResp := GVL.sIn; // e.g. '+CFUN: 4' then 'OK'
nStep := 3;
END_IF
END_CASE