Program Control
For an introduction to the DSL vocabulary, see Core Concepts.
Programs
Two equivalent ways to define a program:
# Context manager
with Program() as logic:
with Rung(Start):
latch(Running)
# Decorator
@program
def logic():
with Rung(Start):
latch(Running)
Both produce a Program you pass to PLC. See Core Concepts — Programs for details.
Subroutines
Context-manager style
with Program() as logic:
with subroutine("startup"):
with Rung(Step == 0):
out(InitLight)
with Rung(AutoMode):
call("startup")
Decorator style
@subroutine("init")
def init_sequence():
with Rung():
out(InitLight)
with Program() as logic:
with Rung(Button):
call(init_sequence) # auto-registers and calls
For loops
forloop repeats a block of instructions N times within a single scan:
The count can be a literal or a tag (resolved each scan):
Use loop.idx for indirect addressing inside the loop body:
End and return instructions aren't needed — Python indentation handles scope.