Drum, Shift & Search
For an introduction to the DSL vocabulary, see Core Concepts.
Shift register
- rung condition is the data bit inserted at position 1
- Clock — shift occurs on the rising edge of the clock condition
- Reset — level-sensitive: clears all bits in range while True
- With
.clock(...).reset(...),shiftis a box with pins and ends its rung.
Direction is determined by the range order:
- C.select(1, 8) → shifts low-to-high (data enters at C1, exits at C8)
- C.select(1, 8).reverse() → shifts high-to-low
Event drum
with rung(Running):
event_drum(
outputs=[DrumOut1, DrumOut2, DrumOut3],
events=[DrumEvt1, DrumEvt2, DrumEvt3, DrumEvt4],
pattern=[
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, 1, 0],
],
current_step=DrumStep,
completion_flag=DrumDone,
) \
.reset(ShiftReset) \
.jump((AutoMode, Found), step=DrumJumpStep) \
.jog(Clock, Found)
Time drum
with rung(Running):
time_drum(
outputs=[DrumOut1, DrumOut2, DrumOut3],
presets=[50, DS[1], 75, DS[2]],
unit="ms",
pattern=[
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, 1, 0],
],
current_step=DrumStep,
accumulator=DrumAcc,
completion_flag=DrumDone,
) \
.reset(ShiftReset) \
.jump(Found, step=2) \
.jog(Start)
A tag preset (DS[1]) needs CLICK v4 firmware. Earlier firmware accepts literal durations only, and Click validation leaves a hint.
Time & event drum
with rung(Running):
time_event_drum(
outputs=[Clamp, Drill, Eject],
presets=[500, None, 2000],
events=[None, PartPresent, DrillHome],
unit="ms",
pattern=[
[1, 0, 0],
[1, 1, 0],
[0, 0, 1],
],
current_step=DrumStep,
accumulator=DrumAcc,
completion_flag=DrumDone,
).reset(ShiftReset)
A step ends when its time is up and its event is on. None leaves out either half. Step 1 is time-only. Step 2 waits for PartPresent alone. Step 3 needs 2 s and DrillHome. Each step needs at least one of the two.
Events are levels, unlike event_drum's rising edges. An event already on when the time comes up ends the step on that scan. A step with no preset does not time.
event_drum(...), time_drum(...) and time_event_drum(...) end their rung. .reset(...) is required and finalizes the instruction. .jump(...) and .jog(...) are optional.
What a drum does each scan
All three drums run the same routine:
- Reset is a level, and it wins. While it is on, the drum sits on step 1, with its completion flag off and every output off.
- Jump and jog act on their rising edges, even while the rung is false. A jump beats a jog. A jog on the last step completes the drum.
- A step's own end needs the rung true and the completion flag off. A false rung pauses the drum and the outputs stay as they were.
- Outputs are written when the step moves or the rung comes back, not on every scan. A value that another rung writes to an output therefore stands until then.
- The completion flag is the drum's state. When the drum completes, it sets the flag and turns every output off. While the flag is on, the drum's own time and events do nothing. A reset clears the flag. Any other rung can clear it too.
- The step register: if its value is out of range, the drum goes to step 1 on the next true scan. Writing to the register does not move the drum. The outputs stay, and the next event or jog acts on the new step.
- A tag preset is read on every scan the step times. A preset of 0 or less ends the step on its first timing scan.
Variadic condition chaining
Builder condition arguments (.down(...), .clock(...), .reset(...), .jump(...), .jog(...)) all accept single conditions, multiple positional conditions, or tuple/list groups. All forms normalize to one AND expression:
event_drum(...).reset(ResetA, ResetB).jog(JogA, JogB)
event_drum(...).jump((AutoMode, Found), step=2)
Search
Find the first element in a range matching a condition:
The first argument is a comparison expression built from a .select() range. It uses the same operator syntax as tags elsewhere in the DSL.
- On success:
result = matched_address(1-based),found = True - On miss:
result = -1,found = False resultmust be INT or DINT, andfoundmust be BOOL- The range holds INT, DINT, REAL, WORD or CHAR tags. The value is one tag, a pointer, a constant or an expression
- For CLICK,
resultmust be aDSandfoundaCbit. The range must hold two or more addresses inDS,DD,DH,DF,TD,CTDorTXT - For CLICK, the value must suit the range. A
TXTrange takes text or aTXTtag. ADHrange takes a number or aDH,XDorYDtag. The other ranges take a number or a tag inDS,DD,DF,TD,CTDorSD - The export rejects a search that CLICK refuses
Continuous search (resume from last position)
result == 0→ restart at first addressresult == -1→ already exhausted, so return miss without rescanning- otherwise → resume at first address after current result
Text search
Only == and != are valid for CHAR ranges. The search matches substrings as long as the value string. The value is text, a TXT tag, a pointer, or a number or number tag. A number or a Bool is searched for as text, so == 5 finds "5". pyrung refuses any other operator, an expression and empty text when it builds the program. "\x00" finds a blank character.