Skip to content

Repeat / End Repeat ​

Purpose: run a block of steps a fixed number of times.

Repeat settings

Enter the count in Run body. Adding a Repeat also adds an EndRepeat; put the steps to repeat between them.

JSON ​

json
{ "repeat": { "count": 3 } },
{ "set": { "var": "i", "op": "+=", "value": 1 } },
{ "write": { "function": 6, "address": "0x0400 + ${i}", "value": "${i} * 10" } },
{ "endrepeat": true }
FieldMeaning
countNumber of times, 0–1000000. 0 means the block does not run (SKIP). Can also be written as {"repeat": 3}
End Repeat{"endrepeat": true}

Result ​

Repeat and EndRepeat themselves are PASS. Steps inside the loop are judged on every pass; if any pass FAILs, that step is FAIL. (runs 3) in the Actual column is the number of times it ran.

Example ​

Repeats 3 times. Each time, i goes up by 1 and 0x0400 + i = i × 10 is written. Finally, 0x0401..0x0403 are read back and should be 10, 20, 30.

Repeat example result

Notes ​

  • Set the variable's starting value outside the loop (Set i = 0 in the example), then add to it inside.
  • Repeat can be nested.

Download the sample script ​

Sample script

Before running it, start a Slave window on 127.0.0.1:502 and click Listen, then open the script with Open JSON in Script mode and click Run. See How to use the examples.

Roach Modbus Tool by Mr.Roach