RESOURCE¶
A resource represents a processing unit within a configuration, typically corresponding to a CPU or processing module.
IEC 61131-3 |
Section 2.7.1 |
Support |
Supported |
Syntax¶
RESOURCE resource_name ON resource_type
global_variable_declarations
task_declarations
program_associations
END_RESOURCE
Example¶
RESOURCE DefaultResource ON PLC
TASK MainTask(INTERVAL := T#20ms, PRIORITY := 1);
TASK FastTask(INTERVAL := T#5ms, PRIORITY := 0);
PROGRAM main WITH MainTask : MainProgram;
PROGRAM fast WITH FastTask : FastProgram;
END_RESOURCE
A resource contains task declarations and associates programs with those tasks.
Note
IronPLC currently runs one PROGRAM per configuration. Declaring a
second PROGRAM, or instantiating a program more than once across the
RESOURCE blocks, is reported as P9999
at compile time. Support for more than one program is tracked in
issue #1613.
Resource Global Variables¶
A resource may declare its own VAR_GLOBAL block before its tasks.
These global variables belong to the resource: a program that the resource
instantiates accesses them through VAR_EXTERNAL, the same way as
configuration globals (see Variable Scope). Their
values persist from one scan to the next.
CONFIGURATION config
RESOURCE resource1 ON PLC
VAR_GLOBAL
ScanCount : DINT := 0;
END_VAR
TASK plc_task(INTERVAL := T#100ms, PRIORITY := 1);
PROGRAM plc_task_instance WITH plc_task : main;
END_RESOURCE
END_CONFIGURATION
PROGRAM main
VAR_EXTERNAL
ScanCount : DINT;
END_VAR
ScanCount := ScanCount + 1;
END_PROGRAM
IEC 61131-3 makes the global variables of a resource visible only to the programs of that resource, while configuration globals are visible to every resource.
See Also¶
CONFIGURATION — parent container
TASK — execution scheduling
PROGRAM — executable unit