Several programs
Section titled “Several programs”A model can carry several PLC programs, with one PLC Program component per node. Like blocks in a real PLC, these can represent individual machine units. All programs scan in the same tick, one after another, as set by their Order field. An output written by two programs is reported as a conflict.
The Laser Welding Assembly Station is controlled this way: eleven programs under the node PLC_Programs — operating modes, transport, the two lifts, the buffer, the entry and the five stations.
Cold start, warm start and start values
Section titled “Cold start, warm start and start values”| What you do | Start | Variables | Timers and counters | RV_FirstScan |
|---|---|---|---|---|
| Deploy | Cold | Back to their start values | New, with their start inputs | TRUE in the first scan |
| Reset, or resetting the simulation | Cold | Back to their start values | Back to their start inputs | TRUE in the first scan afterwards |
| Run after an error | Cold | Back to their start values | New | TRUE in the first scan |
| Stop, then Run | Warm | Keep their values | Keep their state | stays FALSE |
A variable without a start value begins with FALSE or 0; enums use their declared default, member valued 0, or first member as described above. RV_FirstScan is TRUE in exactly one scan after every cold start, so you can run set-up code once:
PROGRAM MainVAR_EXTERNAL RV_FirstScan : BOOL; PartPresent : BOOL; (* @signal: SensorInFeed *) Conveyor : BOOL; (* @signal: ConveyorStart *) BatchFull : BOOL; (* @signal: SignalTower_Yellow *)END_VARVAR CONSTANT BATCH : INT := 10; (* parts per batch *)END_VARVAR starts : INT := 0; (* counts cold starts *) parts : INT := 0; hold : TON := (PT := T#2s); (* start value for the input PT *) edge : R_TRIG;END_VAR IF RV_FirstScan THEN starts := starts + 1; END_IF; edge(CLK := PartPresent); IF edge.Q THEN parts := parts + 1; END_IF; hold(IN := parts >= BATCH); (* PT keeps its start value of 2 s *) BatchFull := hold.Q; Conveyor := NOT BatchFull;END_PROGRAMRV_FirstScan is not a signal. Declare it in VAR_EXTERNAL like RV_SimulationMode; writing to it stops the deploy with an error. The watch list shows the start inputs of timers and counters as well, for example hold.PT.
Resetting the simulation resets every program’s timers, counters and memory. It also restores ordinary outputs to their captured start values. GVL signals use their declaration values; later library initializer edits take effect on the next Reset.
If a scan runs too long (more than 200 ms, for example an endless loop), uses too much memory or hits an error such as a division by zero, the PLC stops with the status error. Fix the program and click Run again; the PLC restarts with fresh values.